From de55027c8286cfecc6725ab5350b560aa54912aa Mon Sep 17 00:00:00 2001 From: juleslagarde <23563133+juleslagarde@users.noreply.github.com> Date: Tue, 28 May 2024 10:49:37 +0200 Subject: [PATCH 1/2] Fix ranges extraction the previous code would output [[1,2],[3,3]] instead of [[1,2],[3,4]] because i variable increase one by one instead of the expexted two by two --- gui-programming/rich-text-editor/rich_text_editor.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gui-programming/rich-text-editor/rich_text_editor.py b/gui-programming/rich-text-editor/rich_text_editor.py index 10c14263..027c089f 100644 --- a/gui-programming/rich-text-editor/rich_text_editor.py +++ b/gui-programming/rich-text-editor/rich_text_editor.py @@ -113,8 +113,10 @@ def fileManager(event=None, action=None): ranges = textArea.tag_ranges(tagName) - for i, tagRange in enumerate(ranges[::2]): - document['tags'][tagName].append([str(tagRange), str(ranges[i+1])]) + assert (len(ranges)%2) == 0, "ranges should have a length multiple of 2" + for i in range(0, len(ranges), 2): + document['tags'][tagName].append([str(ranges[i]), str(ranges[i + 1])]) + if not filePath: # ask the user for a filename with the native file explorer. From b0d1d82cb53c506e341a7c1bdcab29e8d553a7dc Mon Sep 17 00:00:00 2001 From: juleslagarde <23563133+juleslagarde@users.noreply.github.com> Date: Tue, 28 May 2024 10:53:56 +0200 Subject: [PATCH 2/2] fix indent --- gui-programming/rich-text-editor/rich_text_editor.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/gui-programming/rich-text-editor/rich_text_editor.py b/gui-programming/rich-text-editor/rich_text_editor.py index 027c089f..05259905 100644 --- a/gui-programming/rich-text-editor/rich_text_editor.py +++ b/gui-programming/rich-text-editor/rich_text_editor.py @@ -112,11 +112,9 @@ def fileManager(event=None, action=None): document['tags'][tagName] = [] ranges = textArea.tag_ranges(tagName) - - assert (len(ranges)%2) == 0, "ranges should have a length multiple of 2" - for i in range(0, len(ranges), 2): - document['tags'][tagName].append([str(ranges[i]), str(ranges[i + 1])]) - + + for i in range(0, len(ranges), 2): + document['tags'][tagName].append([str(ranges[i]), str(ranges[i + 1])]) if not filePath: # ask the user for a filename with the native file explorer.