Sublime Forum

[Mac] Double click (or something similar) to close a tab?

#1

I use Sublime Text on a Mac and I have

"show_tab_close_buttons": false

but I still need a quick way to close individual tab without using the keyboard. Is it possible to bind the double click for this somehow?

0 Likes

#2

https://docs.sublimetext.io/reference/mouse_bindings.html

1 Like

#3

I tried this:

[
  {
      "button": "button1", "count": 2,
      "press_command": "close"
  }
]

This closes the tab if I double-click in the main area. But how to make it close the tab when I double-click the tab control instead?

47%E2%80%AFAM

0 Likes

#4

ChatGPT created the following plugin, but it doesn’t work:

import sublime
import sublime_plugin

class CloseTabOnDoubleClick(sublime_plugin.EventListener):
    def on_text_command(self, view, command_name, args):
        if command_name == "drag_select" and args and args.get("event"):
            event = args["event"]
            if event.get("count", 1) == 2:  # Detect double-click
                window = view.window()
                if window:
                    window.run_command("close")
                return None  # Prevent the default action
        return None

Any ideas why?

0 Likes

#5

I don’t think there is a way for a plugin to detect when a tab is clicked on, I think your choices are to:

  • middle click on the tab to close it
  • or right click and use the context menu
  • or use the File menu
  • or add an entry to the command palette.
0 Likes

#6
  • middle click on the tab to close it

The problem is that I don’t understand how it can be simulated on MacBook’s touchpad. It seems it is not possible.

0 Likes