Skip to content

Commit

Permalink
fix: startup exception due to no selection
Browse files Browse the repository at this point in the history
Traceback (most recent call last):
  File "C:\Program Files\Sublime Text\Lib\python33\sublime_plugin.py", line 944, in on_activated_async
    run_view_callbacks('on_activated_async', view_id)
  File "C:\Program Files\Sublime Text\Lib\python33\sublime_plugin.py", line 708, in run_view_callbacks
    callback(v, *args)
  File "C:\Program Files\Sublime Text\Lib\python33\sublime_plugin.py", line 190, in exception_handler
    return event_handler(*args)
  File "C:\Users\User\AppData\Roaming\Sublime Text\Installed Packages\HyperClick.sublime-package\hyper_click_annotator.py", line 105, in on_activated_async
    self.on_selection_modified_async(view)
  File "C:\Program Files\Sublime Text\Lib\python33\sublime_plugin.py", line 190, in exception_handler
    return event_handler(*args)
  File "C:\Users\User\AppData\Roaming\Sublime Text\Installed Packages\HyperClick.sublime-package\hyper_click_annotator.py", line 102, in on_selection_modified_async
    self.annotate(point, view)
  File "C:\Users\User\AppData\Roaming\Sublime Text\Installed Packages\HyperClick.sublime-package\hyper_click_annotator.py", line 49, in annotate
    matched = self.is_valid_line(line_content, view)
  File "C:\Users\User\AppData\Roaming\Sublime Text\Installed Packages\HyperClick.sublime-package\hyper_click_annotator.py", line 17, in is_valid_line
    if view.match_selector(view.sel()[0].b, selector):
  File "C:\Program Files\Sublime Text\Lib\python33\sublime.py", line 1044, in __getitem__
    raise IndexError()
IndexError

Signed-off-by: Jack Cherng <[email protected]>
  • Loading branch information
jfcherng authored and cristianl committed Jun 8, 2022
1 parent 64fdf60 commit b3153f4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions hyper_click_annotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def __init__(self):
self.current_line = (-1, -1)

def is_valid_line(self, line_content, view):
if not self.has_valid_selection(view):
return False
settings = sublime.load_settings('HyperClick.sublime-settings')
scopes = settings.get('scopes', {})
for selector in scopes:
Expand Down Expand Up @@ -109,6 +111,8 @@ def on_deactivated_async(self, view):

def on_query_context(self, view, key, operator, operand, match_all):
if key == 'hyper_click_jump_line':
if not self.has_valid_selection(view):
return False
cursor = view.sel()[0].b
line_range = view.line(cursor)
line_content = view.substr(line_range).strip()
Expand All @@ -118,6 +122,10 @@ def on_query_context(self, view, key, operator, operand, match_all):
def on_hover(self, view, point, hover_zone):
self.annotate(point, view)

@staticmethod
def has_valid_selection(view):
return len(view.sel()) > 0


def plugin_loaded():
window = sublime.active_window()
Expand Down

0 comments on commit b3153f4

Please sign in to comment.