Last active
October 27, 2018 16:23
-
-
Save mattst/4747f216e9e8882d5fd88995b39fa34e to your computer and use it in GitHub Desktop.
An ST plugin to move the active buffer's tab left and right on the tab bar.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Name: MoveTabInGroup | |
# Requirements: Plugin for Sublime Text v2 and v3 | |
# Written by: mattst - https://github.com/mattst | |
# ST Command: move_tab_in_group | |
# Arg Required: direction: "left" or "right" | |
# Description: An ST plugin to move the active buffer's | |
# tab left and right on the tab bar. | |
# | |
import sublime | |
import sublime_plugin | |
class MoveTabInGroupCommand(sublime_plugin.WindowCommand): | |
""" | |
An ST plugin to move the active buffer's tab left and right on the tab bar. | |
""" | |
def run(self, direction): | |
active_sheet = self.window.active_sheet() | |
if not active_sheet: | |
return | |
group, tab_pos = self.window.get_sheet_index(active_sheet) | |
num_tabs_in_group = len(self.window.sheets_in_group(group)) | |
if tab_pos < 0 or num_tabs_in_group < 2: | |
return | |
elif direction == "left": | |
new_tab_pos = tab_pos - 1 | |
if new_tab_pos < 0: | |
new_tab_pos = num_tabs_in_group - 1 | |
elif direction == "right": | |
new_tab_pos = tab_pos + 1 | |
if new_tab_pos >= num_tabs_in_group: | |
new_tab_pos = 0 | |
else: | |
return | |
self.window.set_sheet_index(active_sheet, group, new_tab_pos) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment