add duplicateSelection command
This commit is contained in:
parent
b56f41e9a4
commit
a82c1c52d8
2 changed files with 23 additions and 0 deletions
|
|
@ -319,6 +319,11 @@ exports.commands = [{
|
||||||
bindKey: bindKey("Ctrl-D", "Command-D"),
|
bindKey: bindKey("Ctrl-D", "Command-D"),
|
||||||
exec: function(editor) { editor.removeLines(); },
|
exec: function(editor) { editor.removeLines(); },
|
||||||
multiSelectAction: "forEach"
|
multiSelectAction: "forEach"
|
||||||
|
}, {
|
||||||
|
name: "duplicateSelection",
|
||||||
|
bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
|
||||||
|
exec: function(editor) { editor.duplicateSelection(); },
|
||||||
|
multiSelectAction: "forEach"
|
||||||
}, {
|
}, {
|
||||||
name: "togglecomment",
|
name: "togglecomment",
|
||||||
bindKey: bindKey("Ctrl-/", "Command-/"),
|
bindKey: bindKey("Ctrl-/", "Command-/"),
|
||||||
|
|
|
||||||
|
|
@ -1348,6 +1348,24 @@ var Editor = function(renderer, session) {
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.duplicateSelection = function() {
|
||||||
|
var sel = this.selection;
|
||||||
|
var doc = this.session;
|
||||||
|
var range = sel.getRange();
|
||||||
|
if (range.isEmpty()) {
|
||||||
|
var row = range.start.row;
|
||||||
|
doc.duplicateLines(row, row);
|
||||||
|
} else {
|
||||||
|
var reverse = sel.isBackwards()
|
||||||
|
var point = sel.isBackwards() ? range.start : range.end;
|
||||||
|
var endPoint = doc.insert(point, doc.getTextRange(range), false);
|
||||||
|
range.start = point;
|
||||||
|
range.end = endPoint;
|
||||||
|
|
||||||
|
sel.setSelectionRange(range, reverse)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/** related to: EditSession.moveLinesDown
|
/** related to: EditSession.moveLinesDown
|
||||||
* Editor.moveLinesDown() -> Number
|
* Editor.moveLinesDown() -> Number
|
||||||
* + (Number): On success, it returns -1.
|
* + (Number): On success, it returns -1.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue