Skip to content

Commit

Permalink
refresh project folder and focus when sidebar is open (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Surya Kotamraju authored and miguelgraz committed Jun 24, 2018
1 parent d2b5666 commit 9e1b34c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions FocusFileOnSidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,21 @@ def get_project_json(self):
def set_project_json(self, data):
return self.window.set_project_data(data)

def reveal_and_focus_in_sidebar(self):
self.window.run_command("reveal_in_side_bar")
self.window.run_command("focus_side_bar")

class FocusFileOnSidebar(sublime_plugin.WindowCommand):
def run(self):
if not self.window.is_sidebar_visible():
refresh_folders(self)
self.window.set_sidebar_visible(True)
self.window.run_command("reveal_in_side_bar")
# Without the timeout the command on the palette doesn't work
sublime.set_timeout(
lambda: self.window.run_command('focus_side_bar'), 50)
# set_project_data is asynchronous so we need settimeout for subsequent commands
sublime.set_timeout_async(lambda: reveal_and_focus_in_sidebar(self), 250)
else:
if close_sidebar_if_opened:
self.window.set_sidebar_visible(False)
sublime.set_timeout(lambda: refresh_folders(self), 50)
refresh_folders(self)
else:
self.window.run_command("reveal_in_side_bar")
self.window.run_command('focus_side_bar')
refresh_folders(self)
sublime.set_timeout_async(lambda: reveal_and_focus_in_sidebar(self), 250)

0 comments on commit 9e1b34c

Please sign in to comment.