Skip to content

Commit 8d1d94f

Browse files
committed
Option to focus on file window after reveal
1 parent 187af86 commit 8d1d94f

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

SyncedSideBar.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ def revealLater():
124124

125125
class SideBarListener(sublime_plugin.EventListener):
126126
def on_activated(self, view):
127+
128+
self.packageSettings = sublime.load_settings('SyncedSideBar.sublime-settings')
129+
127130
# don't even consider updating state if we don't have a window.
128131
# reveal in side bar is a window command only.
129132
# 'goto anything' activates views but doesn't set a window until the file is selected.
@@ -142,11 +145,22 @@ def on_activated(self, view):
142145

143146
# Sublime text v3 window command listener, safe to include unconditionally as it's simply ignored by v2.
144147
# Eventually, v3 support below 3098 will be dropped and this can be deleted.
145-
def on_window_command(self, window, command_name, args):
146-
if command_name == 'toggle_side_bar':
148+
def on_window_command(self, window, command, args):
149+
if command == 'toggle_side_bar':
147150
global sidebarVisible
148151
sidebarVisible = not sidebarVisible
149152

153+
# This is needed for the `on_post_window_command` to work
154+
if command == 'reveal_in_side_bar':
155+
self.last_view = window.active_view()
156+
157+
158+
# Back to the file window after `reveal_in_side_bar` command
159+
def on_post_window_command(self, window, command, args):
160+
if command == 'reveal_in_side_bar':
161+
if self.packageSettings.get('focus-on-view'):
162+
window.focus_view(self.last_view)
163+
150164

151165
class SideBarUpdateSync(sublime_plugin.ApplicationCommand):
152166
# Update user preferences with the new value

SyncedSideBar.sublime-settings

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
*/
1313
"reveal-on-activate": true,
1414

15+
/*
16+
* After reveal on sidebar, focus on file window view.
17+
*
18+
* Defaults to true.
19+
*/
20+
"focus-on-view": true,
21+
1522
/*
1623
* Controls window switch behaviour.
1724
*

0 commit comments

Comments
 (0)