From 5894d2d244cc52bb9756d3e0215bf09ab25f8139 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 23 Jan 2024 17:14:19 -0400 Subject: st4: hsmusic: direction normalizing nonsense --- apps/Sublime Text 4/Packages/User/HSMusic Editing.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/Sublime Text 4/Packages/User/HSMusic Editing.py b/apps/Sublime Text 4/Packages/User/HSMusic Editing.py index 89fa031..74880a2 100644 --- a/apps/Sublime Text 4/Packages/User/HSMusic Editing.py +++ b/apps/Sublime Text 4/Packages/User/HSMusic Editing.py @@ -110,14 +110,14 @@ class _CursorAdaptiveCommand(sublime_plugin.TextCommand): self.__inserted_offsets.append((insert_point, insert_offset)) return (region, direction, 0, backoff) - def perform_replace(self, edit, region, direction, erase, replace, backoff): - replace_point = region.b + def perform_replace_left(self, edit, region, erase, replace, backoff, move_side): + replace_point = _normalize_region(region).a replace_point -= erase aligned_replace_point = self.__align_point_after_insertions(replace_point, 'right') aligned_replace_region = sublime.Region(aligned_replace_point, aligned_replace_point + erase) self.view.replace(edit, aligned_replace_region, replace) self.__inserted_offsets.append((replace_point, len(replace) - erase)) - return (region, direction, 0, backoff) + return (region, move_side, 0, backoff) def perform_wrap(self, edit, region, insert_left, insert_right, move_side = None): if region.a < region.b: @@ -140,13 +140,21 @@ class _CursorAdaptiveCommand(sublime_plugin.TextCommand): else: return (region, 'collapse-right', 0, 0) +def _normalize_region(region): + if region.a < region.b: + return region + else: + return sublime.Region(region.b, region.a) + def _match_tag_in_progress(view, region): - to_start = sublime.Region(view.line(region).a, region.b) + region = _normalize_region(region) + to_start = sublime.Region(view.line(region).a, region.a) match = re.search('(\[\[(?:(?!]]|\|).)*)$', view.substr(to_start)) if match: return match.group(1) def _match_rest_of_tag_in_progress(view, region): + region = _normalize_region(region) to_end = sublime.Region(region.a, view.line(region).b) match = re.search('^((?:(?!\[\[).)*]])', view.substr(to_end)) if match: @@ -179,7 +187,7 @@ def _consider_reference_cycle(view, region, cycle): next_ref = cycle[0] if current_ref: - return ('replace', 'right', len(current_ref) + 1, next_ref + ':', 0) + return ('replace_left', len(current_ref) + 1, next_ref + ':', 0, 'right') elif insert_pipe: return ('insert', 'right', next_ref + ':|', 1) else: -- cgit 1.3.0-6-gf8a5