Skip to content

Commit

Permalink
Commands for moving the group focus up, down, left, right
Browse files Browse the repository at this point in the history
related to sublimehq#44
  • Loading branch information
misfo committed Mar 21, 2012
1 parent d6a8ab6 commit 77bfd4a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,26 @@
"context": [{"key": "setting.vintage_ctrl_keys"}, {"key": "setting.command_mode"}]
},

{ "keys": ["ctrl+w", "k"], "command": "move_group_focus",
"args": {"direction": "up"},
"context": [{"key": "setting.vintage_ctrl_keys"}, {"key": "setting.command_mode"}]
},

{ "keys": ["ctrl+w", "j"], "command": "move_group_focus",
"args": {"direction": "down"},
"context": [{"key": "setting.vintage_ctrl_keys"}, {"key": "setting.command_mode"}]
},

{ "keys": ["ctrl+w", "l"], "command": "move_group_focus",
"args": {"direction": "right"},
"context": [{"key": "setting.vintage_ctrl_keys"}, {"key": "setting.command_mode"}]
},

{ "keys": ["ctrl+w", "h"], "command": "move_group_focus",
"args": {"direction": "left"},
"context": [{"key": "setting.vintage_ctrl_keys"}, {"key": "setting.command_mode"}]
},

//
// Actions
//
Expand Down
26 changes: 26 additions & 0 deletions vintage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,3 +1016,29 @@ def run(self, edit):
self.view.sel().clear()
for s in new_sels:
self.view.sel().add(s)

class MoveGroupFocus(sublime_plugin.WindowCommand):
def run(self, direction):
cells = self.window.get_layout()['cells']
active_group = self.window.active_group()
x1, y1, x2, y2 = cells[active_group]

idxs = range(len(cells))
del idxs[active_group]

# Matches are any group that shares a border with the active group in the
# specified direction.
if direction == "up":
matches = (i for i in idxs if cells[i][3] == y1 and cells[i][0] < x2 and cells[i][2] > x1)
elif direction == "down":
matches = (i for i in idxs if cells[i][1] == y2 and cells[i][0] < x2 and cells[i][2] > x1)
elif direction == "right":
matches = (i for i in idxs if cells[i][0] == x2 and cells[i][1] < y2 and cells[i][3] > y1)
elif direction == "left":
matches = (i for i in idxs if cells[i][2] == x1 and cells[i][1] < y2 and cells[i][3] > y1)

# Focus the first group found in the specified direction, if there is one.
try:
self.window.focus_group(matches.next())
except StopIteration:
return

0 comments on commit 77bfd4a

Please sign in to comment.