diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-01-23 17:14:19 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-01-23 17:14:19 -0400 |
commit | 5894d2d244cc52bb9756d3e0215bf09ab25f8139 (patch) | |
tree | 38a73db97d82b7f45c044238c255db845697b55a | |
parent | 0b1581b73bff34d2b7b1360003d9dbc4ae41565b (diff) |
st4: hsmusic: direction normalizing nonsense
-rw-r--r-- | apps/Sublime Text 4/Packages/User/HSMusic Editing.py | 18 |
1 files 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: |