Skip to content

Commit 92ba406

Browse files
committed
Add mouse support.
1 parent 43b2118 commit 92ba406

5 files changed

+70
-1
lines changed

Default (Linux).sublime-mousemap

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"button": "button2", "count": 1, "modifiers": ["ctrl", "alt"],
4+
"press_command": "column_select",
5+
"press_args": {"by": "mouse"}
6+
}
7+
]

Default (OSX).sublime-mousemap

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"button": "button2", "count": 1, "modifiers": ["ctrl", "shift"],
4+
"press_command": "column_select",
5+
"press_args": {"by": "mouse"}
6+
}
7+
]

Default (Windows).sublime-mousemap

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"button": "button2", "count": 1, "modifiers": ["ctrl", "alt"],
4+
"press_command": "column_select",
5+
"press_args": {"by": "mouse"}
6+
}
7+
]

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,27 @@ Windows:
2020
- Ctrl-Alt-Home: Up until the beginning of the document.
2121
- Ctrl-Alt-End: Down until the end of the document.
2222

23+
- Ctrl-Alt-Right-click: Select current column in all lines from the cursor to the row where you clicked.
24+
2325
Linux:
2426

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

32+
- Ctrl-Alt-Right-click: Select current column in all lines from the cursor to the row where you clicked.
33+
3034
OS X:
3135

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

41+
- Ctrl-Shift-Right-click: Select current column in all lines from the cursor to the row where you clicked.
42+
43+
3744
If you want to use a different keystroke, go to "Preferences" then "Key Bindings - User", and add an entry like this:
3845

3946
{ "keys": ["ctrl+alt+up"], "command": "column_select", "args": {"by": "lines", "forward": false}},

column_select.py

+42-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import sys
22
import sublime, sublime_plugin
33

4+
# Notes:
5+
# - Would prefer that after going down, pressing up would undo the last down,
6+
# not extend the selection from the top. However, there's no simple way
7+
# that I can think of to determine which direction the last move was.
8+
49
class ColumnSelect(sublime_plugin.TextCommand):
510

611
def all_selections_at_end(self, sel):
@@ -14,7 +19,19 @@ def all_selections_at_end(self, sel):
1419
break
1520
return at_end
1621

17-
def run(self, edit, by, forward):
22+
def run_(self, args):
23+
if 'event' in args:
24+
event = args['event']
25+
del args['event']
26+
else:
27+
event = None
28+
edit = self.view.begin_edit(self.name(), args)
29+
try:
30+
self.run(edit=edit, event=event, **args)
31+
finally:
32+
self.view.end_edit(edit)
33+
34+
def run(self, edit=None, by='lines', forward=True, event=None):
1835
all_sel = self.view.sel()
1936

2037
# Whether or not to ignore lines that are too short in the line count.
@@ -30,6 +47,30 @@ def run(self, edit, by, forward):
3047
ignore_too_short = False
3148
elif by == 'all':
3249
num_lines = sys.maxint
50+
elif by == 'mouse':
51+
orig_sel = [s for s in all_sel]
52+
self.view.run_command('drag_select', {'event': event})
53+
all_sel = self.view.sel()
54+
click_point = all_sel[0].a
55+
all_sel.clear()
56+
map(all_sel.add, orig_sel)
57+
58+
if click_point < all_sel[0].begin():
59+
forward = False
60+
relative = all_sel[0].begin()
61+
else:
62+
forward = True
63+
relative = all_sel[-1].end()
64+
crow, ccol = self.view.rowcol(click_point)
65+
rrow, rcol = self.view.rowcol(relative)
66+
67+
if forward:
68+
if crow <= rrow: return
69+
num_lines = crow - rrow
70+
else:
71+
if crow >= rrow: return
72+
num_lines = rrow - crow
73+
ignore_too_short = False
3374
else:
3475
sublime.error_message('Invalid "by" argument.')
3576
return

0 commit comments

Comments
 (0)