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 | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/apps/Sublime Text 4/Packages/User/HSMusic Editing.py b/apps/Sublime Text 4/Packages/User/HSMusic Editing.py index 6daa032..41c6408 100644 --- a/apps/Sublime Text 4/Packages/User/HSMusic Editing.py +++ b/apps/Sublime Text 4/Packages/User/HSMusic Editing.py @@ -174,10 +174,20 @@ def _match_tag_in_progress(view, region): if match: return match.group(1) -def _match_rest_of_tag_in_progress(view, region): +def _match_regex_ahead_same_line(view, region, regex): region = _normalize_region(region) to_end = sublime.Region(region.a, view.line(region).b) - match = re.search('^((?:(?!\[\[).)*]])', view.substr(to_end)) + return re.search(regex, view.substr(to_end)) + +def _match_rest_of_tag_in_progress(view, region): + regex = '^((?:(?!\[\[).)*]])' + match = _match_regex_ahead_same_line(view, region, regex) + if match: + return match.group(1) + +def _match_through_closing_html_tag(view, region, tag): + regex = f'^(.*?</{tag}>)' + match = _match_regex_ahead_same_line(view, region, regex) if match: return match.group(1) @@ -241,13 +251,6 @@ class EnterExitWikiTagCommand(_CursorAdaptiveCommand): else: return ('wrap', '[[', ']]', 'left') -class WrapTextBoldCommand(_CursorAdaptiveCommand): - def handle_region(self, region): - if region.a == region.b: - return ('insert', 'right', '<b></b>', 4) - else: - return ('wrap', '<b>', '</b>', 'right') - class ExitWikiTagCommand(_CursorAdaptiveCommand): def handle_region(self, region): rest_of_tag = _match_rest_of_tag_in_progress(self.view, region) @@ -298,3 +301,22 @@ class SpaceInWikiTagCommand(_CursorAdaptiveCommand): def no_action_fallback(self, edit): self.view.run_command('insert', {'characters': ' '}) + +class BoldWikiTextCommand(_CursorAdaptiveCommand): + def handle_region(self, region): + rest_of_tag = _match_through_closing_html_tag(self.view, region, 'b') + if rest_of_tag: + return ('move', len(rest_of_tag)) + elif region.a == region.b: + return ('insert', 'right', '<b></b>', 4) + else: + return ('wrap', '<b>', '</b>', 'left') + +class InsertLineBreakInWikiTextCommand(_CursorAdaptiveCommand): + def handle_region(self, region): + region = _normalize_region(region) + to_end = sublime.Region(region.a, self.view.line(region).b) + if region.a == to_end.b: + return ('insert', 'right', '<br>', 0) + else: + return ('move', len(self.view.substr(to_end))) |