Keep selection.
This commit is contained in:
Liang Ding 2014-11-09 19:26:47 +08:00
parent 0dfa779ebb
commit 231f1490b8
1 changed files with 21 additions and 18 deletions

View File

@ -629,41 +629,44 @@ var editors = {
}, },
"Shift-Ctrl-Up": function (cm) { "Shift-Ctrl-Up": function (cm) {
var content = '', var content = '',
selectoion = cm.listSelections()[0], selectoion = cm.listSelections()[0];
cursor = cm.getCursor();
var from = selectoion.anchor.line, var from = selectoion.anchor,
to = selectoion.head.line; to = selectoion.head;
if (from > to) { if (from > to) {
from = selectoion.head.line; from = selectoion.head;
to = selectoion.anchor.line; to = selectoion.anchor;
} }
for (var i = from, max = to; i <= max; i++) { for (var i = from.line, max = to.line; i <= max; i++) {
content += '\n' + cm.getLine(i); content += '\n' + cm.getLine(i);
} }
cm.replaceRange(content, CodeMirror.Pos(to)); cm.replaceRange(content, CodeMirror.Pos(to.line));
cm.setCursor(cursor);
cm.setSelection(CodeMirror.Pos(to.line, to.ch),
CodeMirror.Pos(from.line, from.ch));
}, },
"Shift-Ctrl-Down": function (cm) { "Shift-Ctrl-Down": function (cm) {
var content = '', var content = '',
selectoion = cm.listSelections()[0], selectoion = cm.listSelections()[0];
cursor = cm.getCursor();
var from = selectoion.anchor.line, var from = selectoion.anchor,
to = selectoion.head.line; to = selectoion.head;
if (from > to) { if (from > to) {
from = selectoion.head.line; from = selectoion.head;
to = selectoion.anchor.line; to = selectoion.anchor;
} }
for (var i = from, max = to; i <= max; i++) { for (var i = from.line, max = to.line; i <= max; i++) {
content += '\n' + cm.getLine(i); content += '\n' + cm.getLine(i);
} }
cm.replaceRange(content, CodeMirror.Pos(to)); cm.replaceRange(content, CodeMirror.Pos(to.line));
cm.setCursor(CodeMirror.Pos(to + (to - from) + 1, cursor.ch)); var offset = to.line - from.line + 1;
cm.setSelection(CodeMirror.Pos(to.line + offset, to.ch),
CodeMirror.Pos(from.line + offset, from.ch));
} }
} }
}); });