Skip to content

Instantly share code, notes, and snippets.

@danieleds
Created September 4, 2014 08:48
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danieleds/326903084a196055a7c3 to your computer and use it in GitHub Desktop.
Save danieleds/326903084a196055a7c3 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