From fd69181cceb8b4df09cebb3eee02c3dbbeb4bce0 Mon Sep 17 00:00:00 2001 From: Van Date: Mon, 10 Nov 2014 17:19:30 +0800 Subject: [PATCH] Shift-Ctrl-Up & Shift-Ctrl-Down --- static/js/editors.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/static/js/editors.js b/static/js/editors.js index e963ac2..f276057 100644 --- a/static/js/editors.js +++ b/static/js/editors.js @@ -639,10 +639,17 @@ var editors = { } for (var i = from.line, max = to.line; i <= max; i++) { - content += '\n' + cm.getLine(i); + if (to.ch !== 0 || i !== max) { // 下一行选中为0时,不应添加内容 + content += '\n' + cm.getLine(i); + } } - cm.replaceRange(content, CodeMirror.Pos(to.line)); + // 下一行选中为0时,应添加到上一行末 + var replaceToLine = to.line; + if (to.ch === 0) { + replaceToLine = to.line - 1; + } + cm.replaceRange(content, CodeMirror.Pos(replaceToLine)); cm.setSelection(CodeMirror.Pos(to.line, to.ch), CodeMirror.Pos(from.line, from.ch)); @@ -659,14 +666,20 @@ var editors = { } for (var i = from.line, max = to.line; i <= max; i++) { - content += '\n' + cm.getLine(i); + if (to.ch !== 0 || i !== max) { // 下一行选中为0时,不应添加内容 + content += '\n' + cm.getLine(i); + } } + // 下一行选中为0时,应添加到上一行末 + var replaceToLine = to.line; + if (to.ch === 0) { + replaceToLine = to.line - 1; + } + cm.replaceRange(content, CodeMirror.Pos(replaceToLine)); - cm.replaceRange(content, CodeMirror.Pos(to.line)); - var offset = to.line - from.line + 1; - - cm.setSelection(CodeMirror.Pos(to.line + offset, to.ch), - CodeMirror.Pos(from.line + offset, from.ch)); + var offset = replaceToLine - from.line + 1; + cm.setSelection(CodeMirror.Pos(from.line + offset, from.ch), + CodeMirror.Pos(to.line + offset, to.ch)); }, "Shift-Alt-Up": function (cm) { var selectoion = cm.listSelections()[0];