Skip to content

Commit 1bf22d0

Browse files
committed
[sublime keymap] Fix coding style in 8eb523db08b80b0ff70728d9b71475cadb2bcf93
Also, wrap the command in an operation and use the head rather than the anchor of the selections.
1 parent c7f2e70 commit 1bf22d0

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

keymap/sublime.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -394,17 +394,24 @@
394394
};
395395

396396
cmds[map["Shift-Alt-Up"] = "selectLinesUpward"] = function(cm) {
397-
var curs = cm.listSelections();
398-
for (var i = 0; i < curs.length; i++) {
399-
if(curs[i].anchor.line>0)
400-
cm.addSelection({line:curs[i].anchor.line-1,ch:curs[i].anchor.ch});
401-
};
397+
cm.operation(function() {
398+
var ranges = cm.listSelections();
399+
for (var i = 0; i < ranges.length; i++) {
400+
var range = ranges[i];
401+
if (range.head.line > cm.firstLine())
402+
cm.addSelection(Pos(range.head.line - 1, range.head.ch));
403+
}
404+
});
402405
};
403406
cmds[map["Shift-Alt-Down"] = "selectLinesDownward"] = function(cm) {
404-
var curs = cm.listSelections();
405-
for (var i = 0; i < curs.length; i++) {
406-
cm.addSelection({line:curs[i].anchor.line+1,ch:curs[i].anchor.ch});
407-
};
407+
cm.operation(function() {
408+
var ranges = cm.listSelections();
409+
for (var i = 0; i < ranges.length; i++) {
410+
var range = ranges[i];
411+
if (range.head.line < cm.lastLine())
412+
cm.addSelection(Pos(range.head.line + 1, range.head.ch));
413+
}
414+
});
408415
};
409416

410417
map["Shift-" + ctrl + "["] = "fold";

test/sublime_test.js

+25
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,31 @@
184184
val("abc\nabc\ndef\ndef\nghi\nghi"), hasSel(1, 1, 1, 1,
185185
3, 1, 3, 1,
186186
5, 1, 5, 1));
187+
stTest("selectLinesUpward", "123\n345\n789\n012",
188+
setSel(0, 1, 0, 1,
189+
1, 1, 1, 3,
190+
2, 0, 2, 0,
191+
3, 0, 3, 0),
192+
"selectLinesUpward",
193+
hasSel(0, 1, 0, 1,
194+
0, 3, 0, 3,
195+
1, 0, 1, 0,
196+
1, 1, 1, 3,
197+
2, 0, 2, 0,
198+
3, 0, 3, 0));
199+
200+
stTest("selectLinesDownward", "123\n345\n789\n012",
201+
setSel(0, 1, 0, 1,
202+
1, 1, 1, 3,
203+
2, 0, 2, 0,
204+
3, 0, 3, 0),
205+
"selectLinesDownward",
206+
hasSel(0, 1, 0, 1,
207+
1, 1, 1, 3,
208+
2, 0, 2, 0,
209+
2, 3, 2, 3,
210+
3, 0, 3, 0));
211+
187212
stTest("sortLines", "c\nb\na\nC\nB\nA",
188213
"sortLines", val("A\nB\nC\na\nb\nc"),
189214
"undo",

0 commit comments

Comments
 (0)