diff options
Diffstat (limited to 'apps/Sublime Text 4/Packages/User/HSMusic Editing.py')
-rw-r--r-- | apps/Sublime Text 4/Packages/User/HSMusic Editing.py | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/apps/Sublime Text 4/Packages/User/HSMusic Editing.py b/apps/Sublime Text 4/Packages/User/HSMusic Editing.py index fcf4592..22e7db7 100644 --- a/apps/Sublime Text 4/Packages/User/HSMusic Editing.py +++ b/apps/Sublime Text 4/Packages/User/HSMusic Editing.py @@ -71,6 +71,23 @@ class _CursorAdaptiveCommand(sublime_plugin.TextCommand): else: aligned_point -= delta real_regions.append(aligned_point) + elif direction in ['extend-left', 'extend-right']: + start = region.a + end = region.b + align_direction = ('left' if direction == 'extend-left' else 'right') + aligned_start = self.__align_point_after_insertions(start, None) + aligned_end = self.__align_point_after_insertions(end, align_direction) + if region.a == region.b and delta: + if direction == 'extend-right': + aligned_start += delta + else: + aligned_start -= delta + if backoff: + if direction == 'extend-right': + aligned_end -= backoff + else: + aligned_end += backoff + real_regions.append(sublime.Region(aligned_start, aligned_end)) elif direction in ['left', 'right']: start = region.a end = region.b + delta @@ -105,12 +122,14 @@ class _CursorAdaptiveCommand(sublime_plugin.TextCommand): def perform_collapse_move(self, edit, region, delta): return (region, 'collapse-right', delta, 0) - def perform_insert(self, edit, region, direction, insert, backoff): + def perform_insert(self, edit, region, direction, insert, backoff, extend_delta=None): insert_point = region.b - aligned_insert_point = self.__align_point_after_insertions(insert_point, direction) + insert_direction = ('left' if direction in ['left', 'extend-left'] else 'right') + aligned_insert_point = self.__align_point_after_insertions(insert_point, insert_direction) insert_offset = self.view.insert(edit, aligned_insert_point, insert) self.__inserted_offsets.append((insert_point, insert_offset)) - return (region, direction, 0, backoff) + delta = (extend_delta if direction in ['extend-left', 'extend-right'] else 0) + return (region, direction, delta, backoff) def perform_replace_left(self, edit, region, erase, replace, backoff, move_side): replace_point = _normalize_region(region).a @@ -191,10 +210,21 @@ def _consider_reference_cycle(view, region, cycle): if current_ref: return ('replace_left', len(current_ref) + 1, next_ref + ':', 0, 'right') elif insert_pipe: - return ('insert', 'right', next_ref + ':|', 1) + directory = _guess_directory(rest_of_tag[:-2]) + return ('insert', 'extend-right', next_ref + ':' + directory + '|', 1, len(next_ref) + 1) else: return ('insert', 'right', next_ref + ':', 0) +def _guess_directory(name): + directory = name + directory = "-".join(directory.split(" ")) + directory = directory.replace("&", "and") + directory = re.sub(r"[^a-zA-Z0-9-]", "", directory) + directory = re.sub(r"-{2,}", "-", directory) + directory = re.sub(r"^-+|-+$", "", directory) + directory = directory.lower() + return directory + class EnterExitWikiTagCommand(_CursorAdaptiveCommand): ref_cycle = ['artist', 'group', 'flash', 'tag'] |