Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Minor tweaks

  • Loading branch information...
commit 0c35e038af07596f98e209b6f049bcd02cc14fb9 1 parent c824577
Tito titoBouzout authored
Showing with 22 additions and 16 deletions.
  1. +6 −0 Word Highlight.sublime-commands
  2. +16 −16 word_highlight.py
6 Word Highlight.sublime-commands
View
@@ -0,0 +1,6 @@
+[
+ {
+ "caption": "WordHighlight: Toggle Enabled",
+ "command": "set_word_highlight_enabled"
+ }
+]
32 word_highlight.py
View
@@ -16,11 +16,10 @@ def load(self):
Pref.word_separators = settings_base.get('word_separators')
Pref.file_size_limit = int(settings.get('file_size_limit', 4194304))
Pref.timing = time.time()
+ Pref.enabled = True
Pref().load()
-g_enabled = True
-
settings.add_on_change('color_scope_name', lambda:Pref().load())
settings.add_on_change('selection_delay', lambda:Pref().load())
settings.add_on_change('draw_outlined', lambda:Pref().load())
@@ -31,14 +30,15 @@ def load(self):
class set_word_highlight_enabled(sublime_plugin.ApplicationCommand):
- def run(self, enabled=None):
- global g_enabled
- if enabled is None:
- enabled = not g_enabled
- g_enabled = enabled
-
+ def run(self):
+ Pref.enabled = not Pref.enabled
+ if not Pref.enabled:
+ sublime.active_window().active_view().erase_regions("WordHighlight")
+ else:
+ WordHighlightListener().highlight_occurences(sublime.active_window().active_view())
+
def description(self):
- return 'Disable' if g_enabled else 'Enable'
+ return 'Disable' if Pref.enabled else 'Enable'
class SelectHighlightedWordsCommand(sublime_plugin.TextCommand):
@@ -54,33 +54,33 @@ class WordHighlightListener(sublime_plugin.EventListener):
def on_activated(self, view):
if not view.is_loading():
Pref.word_separators = view.settings().get('word_separators') or settings_base.get('word_separators')
+ if not Pref.enabled:
+ view.erase_regions("WordHighlight")
def on_selection_modified(self, view):
- if g_enabled and not view.settings().get('is_widget') and view.size() <= Pref.file_size_limit:
+ if Pref.enabled and view.size() <= Pref.file_size_limit and not view.settings().get('is_widget'):
now = time.time()
if now - Pref.timing > Pref.selection_delay:
- self.highlight_occurences(view)
Pref.timing = now
+ self.highlight_occurences(view)
else:
Pref.timing = now
- elif not g_enabled:
- view.erase_regions("WordHighlight")
def highlight_occurences(self, view):
regions = []
occurrencesMessage = []
occurrencesCount = 0
for sel in view.sel():
- if sel.empty() and Pref.highlight_when_selection_is_empty:
+ if Pref.highlight_when_selection_is_empty and sel.empty():
string = view.substr(view.word(sel)).strip()
if string and all([not c in Pref.word_separators for c in string]):
regions += view.find_all('(?<![\\w])'+re.escape(string)+'\\b')
if not Pref.highlight_word_under_cursor_when_selection_is_empty:
for s in view.sel():
regions = [r for r in regions if not r.contains(s)]
- else:
+ elif not sel.empty():
word = view.word(sel)
- if word.end() == sel.end() and word.begin() == sel.begin() :
+ if word.end() == sel.end() and word.begin() == sel.begin():
string = view.substr(word).strip()
if string:
regions += view.find_all('(?<![\\w])'+re.escape(string)+'\\b')
Please sign in to comment.
Something went wrong with that request. Please try again.