Skip to content

Commit

Permalink
Ctrl-D and Cmd-D is now duplicate line
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxLap committed Jan 23, 2020
1 parent 4b877f2 commit 9cab39f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion dist/dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -10854,6 +10854,16 @@ document.addEventListener("DOMContentLoaded", function (event) {
}

function loadEditor() {
function duplicateLine(cm) {
var current_cursor = cm.doc.getCursor();
var line_content = cm.doc.getLine(current_cursor.line);
CodeMirror.commands.goLineEnd(cm);
CodeMirror.commands.newlineAndIndent(cm);
CodeMirror.commands.goLineLeft(cm);
cm.doc.replaceSelection(line_content);
cm.doc.setCursor(current_cursor.line + 1, current_cursor.ch);
}

editor = CodeMirror.fromTextArea(document.getElementById("code"), {
mode: "indent_text",
lineWrapping: true,
Expand Down Expand Up @@ -10898,7 +10908,9 @@ document.addEventListener("DOMContentLoaded", function (event) {
cm.scrollIntoView();
},
"Home": "goLineLeftSmart",
"End": "goLineRight"
"End": "goLineRight",
"Ctrl-D": duplicateLine,
"Cmd-D": duplicateLine
}
});
editor.setSize("100%", "100%");
Expand Down
14 changes: 13 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ document.addEventListener("DOMContentLoaded", function(event) {
}

function loadEditor() {
function duplicateLine(cm) {
var current_cursor = cm.doc.getCursor();
var line_content = cm.doc.getLine(current_cursor.line);
CodeMirror.commands.goLineEnd(cm);
CodeMirror.commands.newlineAndIndent(cm);
CodeMirror.commands.goLineLeft(cm);
cm.doc.replaceSelection(line_content);
cm.doc.setCursor(current_cursor.line + 1, current_cursor.ch);
}

editor = CodeMirror.fromTextArea(document.getElementById("code"), {
mode: "indent_text",
lineWrapping: true,
Expand Down Expand Up @@ -149,7 +159,9 @@ document.addEventListener("DOMContentLoaded", function(event) {
cm.scrollIntoView();
},
"Home": "goLineLeftSmart",
"End": "goLineRight"
"End": "goLineRight",
"Ctrl-D": duplicateLine,
"Cmd-D": duplicateLine,
}
});
editor.setSize("100%", "100%");
Expand Down

0 comments on commit 9cab39f

Please sign in to comment.