-
-
Save Boorj/eb020e14487329431bdabc9141ee7ca1 to your computer and use it in GitHub Desktop.
Codemirror custom Keyboard Shortcuts / JetBrains keymap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CodeMirror API - https://codemirror.net | |
/** Duplicate a current line in CodeMirror doc */ | |
function cmDuplicateLine(cm) { | |
// get a position of a current cursor in a current cell | |
var currentCursor = cm.doc.getCursor(); | |
// read a content from a line where is the current cursor | |
var lineContent = cm.doc.getLine(currentCursor.line); | |
// go to the end the current line | |
CodeMirror.commands.goLineEnd(cm); | |
// make a break for a new line | |
CodeMirror.commands.newlineAndIndent(cm); | |
// move caret to the left position | |
CodeMirror.commands.goLineStart(cm); | |
// filled a content of the new line content from line above it | |
cm.doc.replaceSelection(lineContent); | |
// restore position cursor on the new line | |
cm.doc.setCursor(currentCursor.line + 1, currentCursor.ch); | |
} | |
CodeMirror.keyMap.pcDefault["Ctrl-D"] = cmDuplicateLine; | |
CodeMirror.keyMap.pcDefault["Ctrl-Y"] = CodeMirror.commands.deleteLine; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment