Skip to content

Instantly share code, notes, and snippets.

@cef62
Forked from danieleds/gist:326903084a196055a7c3
Created February 10, 2016 23:14
Show Gist options
  • Save cef62/5ca90fe87f38f2f5f801 to your computer and use it in GitHub Desktop.
Save cef62/5ca90fe87f38f2f5f801 to your computer and use it in GitHub Desktop.
CodeMirror: indent with tab or spaces
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