diff options
author | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2015-11-18 18:36:58 +0100 |
---|---|---|
committer | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2015-11-18 18:36:58 +0100 |
commit | 4ff70466bf0fea1fa91c130e3864868459bfbe9e (patch) | |
tree | 205f54fb33dfdb5e36bb5e018cfaddbe166e02da /js/codeq | |
parent | 7243a8f388f8a47e74d5563968b5354a0969a927 (diff) |
Editor: decrease indent with shift-tab / backspace
Backspace is "smart" - behaves normally except on the first
non-whitespace character in the current line.
Diffstat (limited to 'js/codeq')
-rw-r--r-- | js/codeq/editor.js | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/js/codeq/editor.js b/js/codeq/editor.js index d0b365e..27296d5 100644 --- a/js/codeq/editor.js +++ b/js/codeq/editor.js @@ -9,10 +9,26 @@ codeq.makeEditor = function (elt, options) { matchBrackets: true, extraKeys: { // replace tabs with spaces - Tab: function (cm) { + 'Tab': function (cm) { var spaces = Array(cm.getOption("indentUnit") + 1).join(" "); cm.replaceSelection(spaces); - } + }, + // decrease indent if on first non-whitespace character in line + 'Backspace': function (cm) { + var doc = cm.getDoc(), + cursor = doc.getCursor(), + line = doc.getLine(cursor.line), + col = cursor.ch; + if (col > 0 && !/\S/.test(line.substring(0, col)) && + (col === line.length || /\S/.test(line[col]))) { + // cursor on the first non-whitespace character in line + cm.execCommand('indentLess'); + } + else { + cm.execCommand('delCharBefore'); + } + }, + 'Shift-Tab': 'indentLess', } }, options), editor = CodeMirror(elt, allOptions); |