Search code examples
sublimetext3sublime-text-plugin

SublimeText3: How to do the the opposite of `focus_side_bar`, i.e. focus the main view?


I have a command in a sublime plugin

v.window().run_command("reveal_in_side_bar")
v.window().run_command("focus_side_bar")

that focuses the sidebar. And in another command I hide the side bar (by toggle_side_bar) but the focus still remains on the (now hidden) sidebar.

How to switch the focus back to the main view (the file contents)?


Solution

  • sublime.Window has several methods that could be useful, including focus_view(view), active_view(), focus_group(group), and active_group(). You can save the current view with active_view(), run your reveal_in_side_bar and focus_side_bar commands, then switch back to the formerly active view with focus_view(). Or, if you only have one group in your window, focus_group(0) will switch back to it. If there are multiple groups, use active_group() to get its index.