Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
added basic autoindenting support
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed Jun 19, 2012
1 parent f5dda69 commit 18246a9
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions webapp/content/js/completer.js
Expand Up @@ -45,23 +45,30 @@ MetricCompleter = Ext.extend(Ext.form.TextArea, {
},

onSpecialKey: function (field, e) {
if (e.getKey() == e.TAB) { // This was a pain in the ass to actually get it working right
// field.getEl().blur();
// field.getEl().focus(50);
// field.doQuery( field.getValue() );

var key = e.getKey();
if(key == e.TAB){
/* allow the user to insert tabs */
var el = field.el.dom;
var startPos = el.selectionStart;
var endPos = el.selectionEnd;
var value = field.getValue();
field.setValue(
value.substring(0, el.selectionStart)
+ '\t'
+ ' '
+ value.substring(el.selectionEnd, value.length)
);
e.stopEvent();
return false;
}else if(key == e.ENTER){
var value = field.getValue();
braces = value.match(/\(/g).length - value.match(/\)/g).length;
field.setValue(
value
+ '\n'
+ Array(braces + 1).join(' ')
);
e.stopEvent();
return false;
}
}
});
Expand Down

0 comments on commit 18246a9

Please sign in to comment.