summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2015-11-18 18:36:58 +0100
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2015-11-18 18:36:58 +0100
commit4ff70466bf0fea1fa91c130e3864868459bfbe9e (patch)
tree205f54fb33dfdb5e36bb5e018cfaddbe166e02da /js
parent7243a8f388f8a47e74d5563968b5354a0969a927 (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')
-rw-r--r--js/codeq/editor.js20
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);