Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 9ff17db

Browse files
committed
Fix bug with Select Line around end of inline editor range, and add unit
tests for it.
1 parent 298a01a commit 9ff17db

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/editor/EditorCommandHandlers.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ define(function (require, exports, module) {
301301
var sel = editor.getSelection();
302302
var from = {line: sel.start.line, ch: 0};
303303
var to = {line: sel.end.line + 1, ch: 0};
304+
305+
if (to.line === editor.getLastVisibleLine() + 1) {
306+
// Last line: select to end of line instead of start of (hidden/nonexistent) following line,
307+
// which due to how CM clips coords would only work some of the time
308+
to.line -= 1;
309+
to.ch = editor.document.getLine(to.line).length;
310+
}
311+
304312
editor.setSelection(from, to);
305313
}
306314
}

test/spec/EditorCommandHandlers-test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,13 +1006,29 @@ define(function (require, exports, module) {
10061006

10071007
describe("Select Line - editor with visible range", function () {
10081008

1009-
it("shouldn't select past end of visible range", function () {
1009+
it("shouldn't select past end of visible range, IP in middle of last visible line", function () {
10101010
makeEditorWithRange({startLine: 1, endLine: 5});
10111011
myEditor.setSelection({line: 5, ch: 4}, {line: 5, ch: 4});
10121012
CommandManager.execute(Commands.EDIT_SELECT_LINE, myEditor);
10131013

10141014
expectSelection({start: {line: 5, ch: 0}, end: {line: 5, ch: 5}});
10151015
});
1016+
1017+
it("shouldn't select past end of visible range, IP at start of last visible line", function () {
1018+
makeEditorWithRange({startLine: 1, endLine: 5});
1019+
myEditor.setSelection({line: 5, ch: 0}, {line: 5, ch: 0});
1020+
CommandManager.execute(Commands.EDIT_SELECT_LINE, myEditor);
1021+
1022+
expectSelection({start: {line: 5, ch: 0}, end: {line: 5, ch: 5}});
1023+
});
1024+
1025+
it("should extend selection to include last line of visible range", function () {
1026+
makeEditorWithRange({startLine: 1, endLine: 5});
1027+
myEditor.setSelection({line: 4, ch: 4}, {line: 4, ch: 4});
1028+
CommandManager.execute(Commands.EDIT_SELECT_LINE, myEditor);
1029+
1030+
expectSelection({start: {line: 4, ch: 0}, end: {line: 5, ch: 0}});
1031+
});
10161032
});
10171033

10181034
});

0 commit comments

Comments
 (0)