Sublime Forum

Fun plugin idea: Auto hide/show sidebar (hover events)

#1

Not sure if something like this is even worth releasing as an official package, but I was playing around with this idea and thought I’d share.

The idea:

  • Hide sidebar when mouse is in text view (hover event).
  • Show sidebar when mouse hovers over gutter.
"""AutoSideBar."""
import sublime
import sublime_plugin


class AutoSideBarListener(sublime_plugin.EventListener):
    """Listener that auto hides/shows the sidebar."""

    def on_hover(self, view, point, hover_zone):
        """
        Hide/Show sidebar on hover event.

        If hovering over the main view, keep the sidebar hidden.
        If hovering over the gutter, show the sidebar.
        Events like "reveal file" in sidebar will usually show the sidebar on their own.
        """
        win = view.window()
        if win is not None:
            sidebar_visible = win.is_sidebar_visible()
            if sidebar_visible is False and hover_zone == sublime.HOVER_GUTTER:
                win.run_command('toggle_side_bar')
            elif sidebar_visible is True and hover_zone != sublime.HOVER_GUTTER:
                win.run_command('toggle_side_bar')

I just threw this together. Feel free to use it if you like it :slightly_smiling:.

EDIT: I should note this is for Sublime Text 3116+.

5 Likes

SidebarHoverToggle - Toggles the sidebar, based on where you mouse is hovering
#2

Final form of plugin lives here in my random plugin sandbox (this is where I put plugins I am either experimenting with or plugins I haven’t formally released (for various reasons) and do not want to actively field issues or offer support for). Feel free to dig out the latest version (it will be found in autosidebar.py – that should be all you need).

  • Added a command to toggle the feature and optionally set the sidebar to either shown or hidden on disable
1 Like