tednaleid / sublime-EasyMotion

Sublime Text 2 plugin to quickly jump to any character in the visible area of the active view.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Change coloration to accentuate jump targets

tednaleid opened this issue · comments

The original AceJump and EasyMotion plugins dim the non-jump target text and turn jump targets a bright red.

We're currently putting a box around targets and decorating matching lines with a dot symbol in the gutter, but it might be nice to accentuate them even more by doing something similar.

This is partially done now by using a stronger highlight (rather than an outline) and is also something the user can override the styling of. The default is in SublimeJump.sublime-settings:

{
    // defines syntax highlighting scope that will be used to highlight matched jump targets
    // other examples include: keyword, string, number
    "jump_target_scope" : "entity.name.class"
}

Tried coloring in the inverse with something like "comment" scope, but it didn't look good at all in most color schemes. ST2 doesn't color in the full line with the region, only the text so ragged lines looked off, also seemed to be adding some additional highlighting that didn't look good. Here's the patch if we decide to go back and try again:

diff --git a/SublimeJump.sublime-settings b/SublimeJump.sublime-settings
index 7682316..fa48996 100644
--- a/SublimeJump.sublime-settings
+++ b/SublimeJump.sublime-settings
@@ -1,5 +1,8 @@
 {
     // defines syntax highlighting scope that will be used to highlight matched jump targets
     // other examples include: keyword, string, number
-    "jump_target_scope" : "entity.name.class"
+    "jump_target_scope" : "entity.name.class",
+
+    // set to "none" to turn off changing the inverse of matches to all the same class
+    "inverted_jump_target_scope" : "comment"
 }
\ No newline at end of file
diff --git a/sublime_jump.py b/sublime_jump.py
index 239ed47..9058202 100644
--- a/sublime_jump.py
+++ b/sublime_jump.py
@@ -57,6 +57,9 @@ class JumpGroupIterator:
     def visible_region_begin(self):
         return self.view.visible_region().begin()

+    def visible_region_end(self):
+        return self.view.visible_region().end()
+
     def visible_text(self):
         # TODO enhance to be aware of collapsed text blocks
         visible_region = self.view.visible_region()
@@ -78,13 +81,14 @@ class SublimeJumpCommand(sublime_plugin.WindowCommand):
     active_view = None
     edit = None
     jump_target_scope = None
+    inverted_jump_target_scope = None
     jump_group_iterator = None
     current_jump_group = None

     def run(self, character=None):
         sublime.status_message("SublimeJump to " + character)

-        self.jump_target_scope = sublime.load_settings("SublimeJump.sublime-settings").get('jump_target_scope', 'string')
+        self.init_scopes()
         self.active_view = self.window.active_view()

         self.jump_group_iterator = JumpGroupIterator(self.active_view, character)
@@ -94,6 +98,11 @@ class SublimeJumpCommand(sublime_plugin.WindowCommand):
         else:
             sublime.status_message("Sublime Jump: unable to find any instances of " + character + " in visible region")

+    def init_scopes(self):
+        settings = sublime.load_settings("SublimeJump.sublime-settings")
+        self.jump_target_scope = settings.get('jump_target_scope', 'string')
+        self.inverted_jump_target_scope = settings.get('inverted_jump_target_scope', 'comment')
+
     def prompt_for_next_jump_group(self):
         if not self.jump_group_iterator.has_next():
             self.jump_group_iterator.reset()
@@ -135,8 +144,21 @@ class SublimeJumpCommand(sublime_plugin.WindowCommand):
         for placeholder_char in self.current_jump_group.keys():
             self.active_view.replace(self.edit, self.current_jump_group[placeholder_char], placeholder_char)

+        print(self.inverted_jump_target_scope)
+
+        if self.inverted_jump_target_scope != "none":
+            self.active_view.add_regions("inverted_jump_match_regions", self.inverted_jump_match_regions(), self.inverted_jump_target_scope)
+
         self.active_view.add_regions("jump_match_regions", self.current_jump_group.values(), self.jump_target_scope, "dot")

+    def inverted_jump_match_regions(self):
+        ''' No need to actually calculate gaps, can just return whole region and then overlay with jump matches
+        '''
+        visible_region_begin = self.jump_group_iterator.visible_region_begin()
+        visible_region_end = self.jump_group_iterator.visible_region_end()
+        full_area = sublime.Region(visible_region_begin, visible_region_end)
+        return self.active_view.lines(full_area)