Simplify: don't use kwargs; only implement is_visible
Keyboard shortcuts don't check `is_visible` only `is_enabled` which is
`True` by default.
So shortcuts now get through always.
Context clicks get checked in `is_visible` if any errors
Command Palette is checkes for the selection length
@@ -8,49 +8,44 @@ from .lint import util
MYPY = False
if MYPY:
- from typing import Callable, List
+ from typing import Callable, List, TypedDict
LintError = persist.LintError
+ Event = TypedDict("Event", {"x": float, "y": float})
class sublime_linter_quick_actions(sublime_plugin.TextCommand):
- def is_visible(self, prefer_panel=False, **kwargs):
- if 'event' in kwargs:
+ def is_visible(self, event=None, prefer_panel=False):
+ # type: (Event, bool) -> bool
+ if event:
filename = util.get_filename(self.view)
return len(persist.file_errors[filename]) > 0
else:
- return True
-
- def is_enabled(self, prefer_panel=False, **kwargs):
- # type: (bool, object) -> bool
- if 'event' in kwargs:
- return True
- if prefer_panel:
return len(self.view.sel()) == 1
- else:
- return True
def want_event(self):
return True
- def run(self, edit, prefer_panel=False, **kwargs):
- # type: (sublime.Edit, bool, object) -> None
+ def run(self, edit, event=None, prefer_panel=False):
+ # type: (sublime.Edit, Event, bool) -> None
view = self.view
window = view.window()
assert window
- sel = view.sel()[0]
- if 'event' in kwargs:
- vector = (kwargs['event']['x'], kwargs['event']['y'])
+ if event:
+ vector = (event['x'], event['y'])
point = view.window_to_text(vector)
- sel = sublime.Region(point, point)
for selection in view.sel():
if selection.contains(point):
sel = selection
break
- elif len(self.view.sel()) != 1:
+ else:
+ sel = sublime.Region(point)
+ else:
+ if len(self.view.sel()) != 1:
window.status_message("Quick actions don't support multiple selections")
return
+ sel = view.sel()[0]
filename = util.get_filename(view)
if sel.empty():
