From b3153f4295b6546d008462809f65d6d5729ac9dc Mon Sep 17 00:00:00 2001 From: Jack Cherng Date: Sat, 5 Feb 2022 13:35:36 +0800 Subject: [PATCH] fix: startup exception due to no selection 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 --- hyper_click_annotator.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hyper_click_annotator.py b/hyper_click_annotator.py index ec027f5..67641bf 100644 --- a/hyper_click_annotator.py +++ b/hyper_click_annotator.py @@ -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: @@ -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() @@ -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()