Sublime Forum

Opening new tabs on the right

#1

Hi. I tried to make a plugin that will open new tabs on the right. (Instead of next to the currently active tab.)

My plugin sort-of works, but it seems like the actual tabs aren’t redrawn; the GUI does not change. I can’t figure out how to fix this :frowning:
Maybe someone on this forum can help me?


import sublime, sublime_plugin

class TabrightEvent(sublime_plugin.EventListener):

	def __init__(self, *args, **kwargs):
		super(TabrightEvent, self).__init__(*args, **kwargs)
		self.new_buffers = ]

	def on_new(self,view):
		self.new_buffers.append(view.buffer_id())

	def on_activated(self, view):
		# print 'on_activated', self.last_syntax, view.buffer_id()
		if view.buffer_id() in self.new_buffers:
			self.new_buffers.remove(view.buffer_id())

			window = view.window()
			group = window.active_group()
			viewcount = len(window.views()) - 1
			window.set_view_index(view, group, viewcount)
			window.focus_view(view)
0 Likes

Open new tab at the right
#2

After reading some forum posts, I’ve come up with this solution. I haven’t tested it much though.
I’d be grateful for any insights or comments.

Also, I’ve noticed that running window commands (window.run_command) from on_activated doesn’t work?

import sublime, sublime_plugin

class TabrightEvent(sublime_plugin.EventListener):

	def on_new(self,view):
		window = sublime.active_window()
		rightIndex = len(window.views()) - 1
		window.set_view_index(view, window.active_group(), rightIndex)
		window.run_command("select_by_index", {"index": rightIndex})
0 Likes

#3

For those interested: I moved this to GitHub for convenience.

https://github.com/stylishmedia/SublimeText-Tabright

0 Likes