Skip to content

Commit

Permalink
Force focus interface view
Browse files Browse the repository at this point in the history
If the user opens e.g. the status dashboard using keybindings she can be
actually in a panel (like Terminus et.al.) at that time. In that case a simple
`window.focus_view` is not enough to bring the cursor to the view, we must
focus the group first.
  • Loading branch information
kaste committed Jul 9, 2019
1 parent 7fd517b commit 6e869a3
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions common/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
EDIT_DEFAULT_HELP_TEXT = "## To finalize your edit, press {super_key}+Enter. To cancel, close the view.\n"


def focus_view(view):
window = view.window()
if not window:
return

group, _ = window.get_view_index(view)
window.focus_group(group)
window.focus_view(view)


class Interface():

interface_type = ""
Expand All @@ -35,9 +45,11 @@ def __new__(cls, repo_path=None, **kwargs):
window = sublime.active_window()
for view in window.views():
vset = view.settings()
if vset.get("git_savvy.interface") == cls.interface_type and \
vset.get("git_savvy.repo_path") == repo_path:
window.focus_view(view)
if (
vset.get("git_savvy.interface") == cls.interface_type
and vset.get("git_savvy.repo_path") == repo_path
):
focus_view(view)
try:
return interfaces[view.id()]
except KeyError:
Expand Down Expand Up @@ -97,7 +109,7 @@ def create_view(self, repo_path):
self.view.set_name(self.title())

self.render()
window.focus_view(self.view)
focus_view(self.view)

return self.view

Expand Down

0 comments on commit 6e869a3

Please sign in to comment.