Skip to content

Commit e92ae96

Browse files
authored
title editor: Fix name-duplication regex (#3637)
The previous version was treating the parentheses as non-optional, and could come out with no match at all for a name that lacked them.
1 parent 4608d43 commit e92ae96

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/windows/title_editor.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,19 @@ def load_svg_template(self):
249249
if self.duplicate and self.edit_file_path:
250250
# Re-use current name
251251
name = os.path.basename(self.edit_file_path)
252-
# Splits the filename into "[base-part][optional space]([number]).svg
253-
match = re.match(r"^(.*?)(\s*)\(([0-9]*)\)\.svg$", name)
252+
# Splits the filename into:
253+
# [base-part][optional space][([number])].svg
254+
# Match groups are:
255+
# 1: Base name ("title", "Title-2", "Title number 3000")
256+
# 2: Space(s) preceding groups 3+4, IFF 3/4 are a match
257+
# 3: The entire parenthesized number ("(1)", "(20)", "(1000)")
258+
# 4: Just the number inside the parens ("1", "20", "1000")
259+
match = re.match(r"^(.+?)(\s*)(\(([0-9]*)\))?\.svg$", name)
254260
# Make sure the new title has " (%d)" appended by default
255261
name = match.group(1) + " (%d)"
256-
if match.group(3):
262+
if match.group(4):
257263
# Filename already contained a number -> start counting from there
258-
offset = int(match.group(3))
264+
offset = int(match.group(4))
259265
# -> only include space(s) if there before
260266
name = match.group(1) + match.group(2) + "(%d)"
261267
# Find an unused file name

0 commit comments

Comments
 (0)