« get me outta code hell

st4: hsmusic: exit wiki tags when enter pressed - dotfiles - Miscellaneous configuration files of my personal use
about summary refs log tree commit diff
path: root/apps/Sublime Text 4/Packages
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-01-23 17:38:02 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-01-23 17:39:23 -0400
commit9075481c9300ab8b2caffb501865007e0a9f4a40 (patch)
tree7e5022e66ac17ee2053fa288cbc17e28f3a93f45 /apps/Sublime Text 4/Packages
parent85f47515a3a6ea256cf5a0ec8f99ae71059849e7 (diff)
st4: hsmusic: exit wiki tags when enter pressed
Diffstat (limited to 'apps/Sublime Text 4/Packages')
-rw-r--r--apps/Sublime Text 4/Packages/User/Default (OSX).sublime-keymap8
-rw-r--r--apps/Sublime Text 4/Packages/User/HSMusic Editing.py18
2 files changed, 26 insertions, 0 deletions
diff --git a/apps/Sublime Text 4/Packages/User/Default (OSX).sublime-keymap b/apps/Sublime Text 4/Packages/User/Default (OSX).sublime-keymap
index 551ebaf..82f169c 100644
--- a/apps/Sublime Text 4/Packages/User/Default (OSX).sublime-keymap
+++ b/apps/Sublime Text 4/Packages/User/Default (OSX).sublime-keymap
@@ -41,4 +41,12 @@
 			{ "key": "project_name", "operator": "regex_contains", "operand": "HSMusic" },
 		],
 	},
+
+	{ "keys": ["enter"],
+		"command": "exit_wiki_tag",
+		"context": [
+			{ "key": "project_name", "operator": "regex_contains", "operand": "HSMusic" },
+			{ "key": "panel_has_focus", "operator": "not_equal" },
+		],
+	},
 ]
diff --git a/apps/Sublime Text 4/Packages/User/HSMusic Editing.py b/apps/Sublime Text 4/Packages/User/HSMusic Editing.py
index 4fa3663..fcf4592 100644
--- a/apps/Sublime Text 4/Packages/User/HSMusic Editing.py
+++ b/apps/Sublime Text 4/Packages/User/HSMusic Editing.py
@@ -61,9 +61,15 @@ class _CursorAdaptiveCommand(sublime_plugin.TextCommand):
     real_regions = list()
     for (region, direction, delta, backoff) in new_regions:
       if direction in ['collapse-left', 'collapse-right']:
+        # Adding a `delta` hasn't been particularly tested with multiple cursors at once.
         point = _normalize_region(region).a
         align_direction = ('right' if direction == 'collapse-left' else 'left')
         aligned_point = self.__align_point_after_insertions(point, align_direction)
+        if delta:
+          if direction == 'collapse-right':
+            aligned_point += delta
+          else:
+            aligned_point -= delta
         real_regions.append(aligned_point)
       elif direction in ['left', 'right']:
         start = region.a
@@ -96,6 +102,9 @@ class _CursorAdaptiveCommand(sublime_plugin.TextCommand):
   def perform_move(self, edit, region, delta):
     return (region, 'right', delta, 0)
 
+  def perform_collapse_move(self, edit, region, delta):
+    return (region, 'collapse-right', delta, 0)
+
   def perform_insert(self, edit, region, direction, insert, backoff):
     insert_point = region.b
     aligned_insert_point = self.__align_point_after_insertions(insert_point, direction)
@@ -202,6 +211,15 @@ class EnterExitWikiTagCommand(_CursorAdaptiveCommand):
     else:
       return ('wrap', '[[', ']]', 'left')
 
+class ExitWikiTagCommand(_CursorAdaptiveCommand):
+  def handle_region(self, region):
+    rest_of_tag = _match_rest_of_tag_in_progress(self.view, region)
+    if rest_of_tag:
+      return ('collapse_move', len(rest_of_tag))
+
+  def no_action_fallback(self, edit):
+    self.view.run_command('insert', {'characters': '\n'})
+
 class HyphenInWikiTagCommand(_CursorAdaptiveCommand):
   ref_cycle = ['artist', 'group', 'flash', 'tag']