Sublime Forum

How to get visibility and focus of sidebar?


As title say.

Background: the following code does not hide the sidebar because self.view.window().run_command(“focus_side_bar”) is nullified by the fact that sidebar is already visible and focused:

[code]import sublime, sublime_plugin

class toggle_sidebar(sublime_plugin.TextCommand):
def run(self, edit):
So, I need to check sidebar visibility & focus status to decide whether to run focus_side_bar command

1 Like


Build 3098 added Window.is_sidebar_visible() and Window.set_sidebar_visible() but as far as I know there is still no way to determine if it has the focus

also related:

1 Like


So could it now be possible to use sidebar_visible in key binding contexts in some way? Obviously I intended to have a key binding to toggle the sidebar if it is visible (to hide it) and one (the same key) to focus the sidebar if it is not visible.

I suppose this is something that would just be much easier to do in a plugin?

And 5 minutes later:

import sublime
import sublime_plugin

class SideBarHopperCommand(sublime_plugin.WindowCommand):
    def run(self):
        if self.window.is_sidebar_visible():
        "command": "side_bar_hopper",
        "keys": [

There seems to be something odd though, it will sometimes focus the file in the folder tree instead of the open-files list at the top. Will probably debug this if it happens often enough to annoy me.


Could use a little help with command chaining for key bindings

Consider adding


above the line:


…otherwise the sidebar can retain input focus while it’s invisible.



After update 4143, the command self.window.set_sidebar_visible() no longer toggles the side bar smoothly as View -> Toggle Side Bar does. Is this a bug?



Yes that’s a bug. We’ve got a fix for it in the works.

1 Like