Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

title editor: Fix name-duplication regex #3637

Merged
merged 2 commits into from
Aug 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/windows/title_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,19 @@ def load_svg_template(self):
if self.duplicate and self.edit_file_path:
# Re-use current name
name = os.path.basename(self.edit_file_path)
# Splits the filename into "[base-part][optional space]([number]).svg
match = re.match(r"^(.*?)(\s*)\(([0-9]*)\)\.svg$", name)
# Splits the filename into:
# [base-part][optional space][([number])].svg
# Match groups are:
# 1: Base name ("title", "Title-2", "Title number 3000")
# 2: Space(s) preceding groups 3+4, IFF 3/4 are a match
# 3: The entire parenthesized number ("(1)", "(20)", "(1000)")
# 4: Just the number inside the parens ("1", "20", "1000")
match = re.match(r"^(.+?)(\s*)(\(([0-9]*)\))?\.svg$", name)
# Make sure the new title has " (%d)" appended by default
name = match.group(1) + " (%d)"
if match.group(3):
if match.group(4):
# Filename already contained a number -> start counting from there
offset = int(match.group(3))
offset = int(match.group(4))
# -> only include space(s) if there before
name = match.group(1) + match.group(2) + "(%d)"
# Find an unused file name
Expand Down