summaryrefslogtreecommitdiff
path: root/js/codeq
diff options
context:
space:
mode:
Diffstat (limited to 'js/codeq')
-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);