Skip to content

Commit

Permalink
Add function to quickly switch between most recently active windows
Browse files Browse the repository at this point in the history
  • Loading branch information
deathaxe committed Aug 7, 2023
1 parent ec26e50 commit 649c8df
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Default (Linux).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
"keys": ["ctrl+k", "ctrl+tab"],
"command": "show_overlay",
"args": {"overlay": "command_palette", "command": "switch_window"}
},
{
"keys": ["ctrl+k", "ctrl+\\"],
"command": "switch_window",
"args": {"previous_window": true}
}
]
5 changes: 5 additions & 0 deletions Default (OSX).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
"keys": ["ctrl+k", "ctrl+tab"],
"command": "show_overlay",
"args": {"overlay": "command_palette", "command": "switch_window"}
},
{
"keys": ["ctrl+k", "ctrl+\\"],
"command": "switch_window",
"args": {"previous_window": true}
}
]
5 changes: 5 additions & 0 deletions Default (Windows).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
"keys": ["ctrl+k", "ctrl+tab"],
"command": "show_overlay",
"args": {"overlay": "command_palette", "command": "switch_window"}
},
{
"keys": ["ctrl+k", "ctrl+\\"],
"command": "switch_window",
"args": {"previous_window": true}
}
]
5 changes: 5 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"caption": "Switch: Window",
"command": "switch_window"
},
{
"caption": "Switch: To Previous Window",
"command": "switch_window",
"args": { "previous_window": true },
},
{
"caption": "Preferences: Switch Window Key Bindings",
"command": "edit_settings",
Expand Down
17 changes: 15 additions & 2 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,24 @@ def input_description(self):
return "Switch Window"

def input(self, args):
if args.get("window_id") is None:
if 'previous_window' not in args and args.get("window_id") is None:
return WindowInputHandler()
return None

def run(self, window_id=None):
def run(self, previous_window=False, window_id=None):
"""
Execute `switch_window` command
:param previous_window:
If ``true`` directly switch to previous window.
:param window_id:
The window identifier of the window to switch to.
"""
if previous_window:
if len(_history) >= 2:
_history[1].bring_to_front()
return

for window in sublime.windows():
if window.id() == window_id:
window.bring_to_front()
Expand Down

0 comments on commit 649c8df

Please sign in to comment.