Sublime Forum

Command to re-order tabs?

#1

Is there a command that will allow me to re-order tabs? Currently this is the only thing that I have to go to the mouse for. Basically I just want super+ctrl+left/right to make the tab swap places with its neighbor. Is this possible?

0 Likes

#2

[pre=#0C1021]import sublime_plugin

class MoveTab(sublime_plugin.TextCommand):
def run(self, edit, mod):
view = self.view
window = view.window()
group_index, tab_index = window.get_view_index(view)
view.window().set_view_index(view, group_index,
(tab_index + int(mod)) % len (
view.window().views_in_group(group_index)) )
[/pre]

0 Likes

#3

Should probably have made that a window command operating on the window.active_view()

0 Likes

#4

Keybindings for castles_made_of_sand’s plugin:

	{ "keys": "ctrl+super+left"], "command": "move_tab", "args": {"mod": -1} },
	{ "keys": "ctrl+super+right"], "command": "move_tab", "args": {"mod": 1} },

Not sure what you mean here. I noticed that when moving the current tab with this plugin, it stops being highlighted in the sidebar (or whatever it’s called). Is this related?

0 Likes

#5

[quote=“quodlibet”]

Not sure what you mean here. I noticed that when moving the current tab with this plugin, it stops being highlighted in the sidebar (or whatever it’s called). Is this related?[/quote]

No, what castles_made_of_sand means is that it’s better to use a sublime_plugin.WindowCommand because you only interact with the window, not with the content of the view.

To resolve the issue with highlighted item in the sidebar, simply use window.focus_view().
Something like that (untested):

class MoveTabCommand(sublime_plugin.WindowCommand): def run(self, mod): view = self.window.active_view() group_index, tab_index = self.window.get_view_index(view) self.window.set_view_index(view, group_index, (tab_index + int(mod)) % len ( self.window.views_in_group(group_index)) ) self.window.focus_view(view)

0 Likes

#6

Probably the result of a lazy newplug snippet and hefty dose of braindead… FFFFFFFFFFFFFF :smile:

No, what he means is that is better to use a sublime_plugin.WindowCommand because you only interact with the window, not with the content of the view.

Yep yep, well said, and if you are inside an input panel for example (which TextCommands operate on) it will still work…

In general, with window commands operating on views, you got to watch for when it’s None, which is the case when the focused group is void of cells…

EDIT: FFFFFFFFFFF

I mean, window commands operating on the active_view. Sub void of cells with void of views

One clapped out FFFFFFFF at the moment.

0 Likes

#7

I just tested bizoo’s code and it works perfectly. The plugin keeps the current tab focused on the sidebar and it also works when the console is open (which is what I think castles_made_of_sand was referring to when he was talking about being inside an input panel).

You guys rock!

0 Likes