Skip to content

Commit

Permalink
Add mouse support.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Jul 26, 2012
1 parent 43b2118 commit 92ba406
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Default (Linux).sublime-mousemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"button": "button2", "count": 1, "modifiers": ["ctrl", "alt"],
"press_command": "column_select",
"press_args": {"by": "mouse"}
}
]
7 changes: 7 additions & 0 deletions Default (OSX).sublime-mousemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"button": "button2", "count": 1, "modifiers": ["ctrl", "shift"],
"press_command": "column_select",
"press_args": {"by": "mouse"}
}
]
7 changes: 7 additions & 0 deletions Default (Windows).sublime-mousemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"button": "button2", "count": 1, "modifiers": ["ctrl", "alt"],
"press_command": "column_select",
"press_args": {"by": "mouse"}
}
]
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,27 @@ Windows:
- Ctrl-Alt-Home: Up until the beginning of the document.
- Ctrl-Alt-End: Down until the end of the document.

- Ctrl-Alt-Right-click: Select current column in all lines from the cursor to the row where you clicked.

Linux:

- Alt-Shift-Up / Ctrl-Alt-Down: Up/down one line.
- Alt-Shift-PageUp / Ctrl-Alt-PageDown: Up/down one page.
- Alt-Shift-Home: Up until the beginning of the document.
- Alt-Shift-End: Down until the end of the document.

- Ctrl-Alt-Right-click: Select current column in all lines from the cursor to the row where you clicked.

OS X:

- Ctrl-Shift-Up / Ctrl-Alt-Down: Up/down one line.
- Ctrl-Shift-PageUp / Ctrl-Alt-PageDown: Up/down one page.
- Ctrl-Shift-Home: Up until the beginning of the document.
- Ctrl-Shift-End: Down until the end of the document.

- Ctrl-Shift-Right-click: Select current column in all lines from the cursor to the row where you clicked.


If you want to use a different keystroke, go to "Preferences" then "Key Bindings - User", and add an entry like this:

{ "keys": ["ctrl+alt+up"], "command": "column_select", "args": {"by": "lines", "forward": false}},
Expand Down
43 changes: 42 additions & 1 deletion column_select.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import sys
import sublime, sublime_plugin

# Notes:
# - Would prefer that after going down, pressing up would undo the last down,
# not extend the selection from the top. However, there's no simple way
# that I can think of to determine which direction the last move was.

class ColumnSelect(sublime_plugin.TextCommand):

def all_selections_at_end(self, sel):
Expand All @@ -14,7 +19,19 @@ def all_selections_at_end(self, sel):
break
return at_end

def run(self, edit, by, forward):
def run_(self, args):
if 'event' in args:
event = args['event']
del args['event']
else:
event = None
edit = self.view.begin_edit(self.name(), args)
try:
self.run(edit=edit, event=event, **args)
finally:
self.view.end_edit(edit)

def run(self, edit=None, by='lines', forward=True, event=None):
all_sel = self.view.sel()

# Whether or not to ignore lines that are too short in the line count.
Expand All @@ -30,6 +47,30 @@ def run(self, edit, by, forward):
ignore_too_short = False
elif by == 'all':
num_lines = sys.maxint
elif by == 'mouse':
orig_sel = [s for s in all_sel]
self.view.run_command('drag_select', {'event': event})
all_sel = self.view.sel()
click_point = all_sel[0].a
all_sel.clear()
map(all_sel.add, orig_sel)

if click_point < all_sel[0].begin():
forward = False
relative = all_sel[0].begin()
else:
forward = True
relative = all_sel[-1].end()
crow, ccol = self.view.rowcol(click_point)
rrow, rcol = self.view.rowcol(relative)

if forward:
if crow <= rrow: return
num_lines = crow - rrow
else:
if crow >= rrow: return
num_lines = rrow - crow
ignore_too_short = False
else:
sublime.error_message('Invalid "by" argument.')
return
Expand Down

0 comments on commit 92ba406

Please sign in to comment.