I’m working in distraction-free mode with several “windows” open. Each window looks like a tab, in that case. I posted a screenshot here: https://pasteboard.co/HSgoX8E.png
(Nb: To get this to work one has to do “open new window” when already in fullscreen or distraction-free mode. If one does “open new window” outside fullscreen/distraction-free mode, it opens an actual new window, as opposed to opening a new “window-level tab” in the current window.)
I’ll call the topmost tabs in the previous screenshot “window-level tabs”. (So there are three window-level tabs in the screenshot: one named “app.js - dev_ops”, one named “py_test.py - py”, etc.)
I’ve been able to create keyboard shortcuts for cycling through these window-level tabs using sublime.windows()
which returns a list of these windows. I’ll put the code below. (Disclaimer: This code was mostly inspired by/copied from the Goto Window
ST package, and I only checked that my modified version works on OSX.)
Unfortunately my keyboard shortcuts are somewhat deficient because sublime.windows()
doesn’t return the list of window-level-tabs in their visual order, but rather in their last-used-order. (I think.) To correctly navigate the window-level-tabs via keyboard, I’d need to know the visual index of each window-level-tab, or at least know which one is to the right/left of the current active_window
.
Is their a way to know which window is first, second, etc, as a tab?
Thanks!
def window_focus(window_to_move_to):
active_view = window_to_move_to.active_view()
active_group = window_to_move_to.active_group()
# Goto Window author mentioned that the redundant
# focus_view call is necessary on Windows
if active_view is not None:
window_to_move_to.focus_view(active_view)
window_to_move_to.run_command('focus_neighboring_group')
window_to_move_to.focus_view(active_view)
return
if active_group is not None:
window_to_move_to.focus_group(active_group)
window_to_move_to.run_command('focus_neighboring_group')
window_to_move_to.focus_group(active_group)
class WindowLeftCommand(sublime_plugin.TextCommand):
def run(self, edit):
windows = sublime.windows()
active_window = sublime.active_window()
for i, window in enumerate(windows):
if window == active_window:
break
window_to_move_to_index = (i - 1 + len(windows)) % len(windows)
window_to_move_to = windows[window_to_move_to_index]
j = (i + 1) % len(windows)
while j != window_to_move_to_index:
window_focus(windows[j])
j = (j + 1) % len(windows)
window_focus(window_to_move_to)
class WindowRightCommand(sublime_plugin.TextCommand):
def run(self, edit):
windows = sublime.windows()
active_window = sublime.active_window()
for i, window in enumerate(windows):
if window == active_window:
break
window_to_move_to = windows[(i + 1) % len(windows)]
window_focus(window_to_move_to)