-
-
Save cef62/5ca90fe87f38f2f5f801 to your computer and use it in GitHub Desktop.
CodeMirror: indent with tab or spaces
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
editor.addKeyMap({ | |
"Tab": function (cm) { | |
if (cm.somethingSelected()) { | |
var sel = editor.getSelection("\n"); | |
// Indent only if there are multiple lines selected, or if the selection spans a full line | |
if (sel.length > 0 && (sel.indexOf("\n") > -1 || sel.length === cm.getLine(cm.getCursor().line).length)) { | |
cm.indentSelection("add"); | |
return; | |
} | |
} | |
if (cm.options.indentWithTabs) | |
cm.execCommand("insertTab"); | |
else | |
cm.execCommand("insertSoftTab"); | |
}, | |
"Shift-Tab": function (cm) { | |
cm.indentSelection("subtract"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment