merge julians's key handler changes

This commit is contained in:
Fabian Jakobs 2011-07-15 08:50:13 +00:00
commit aef91c2d31
4 changed files with 52 additions and 18 deletions

View file

@ -426,14 +426,14 @@ var Editor =function(renderer, session) {
var mode = session.getMode();
var cursor = this.getCursorPosition();
if (this.getBehavioursEnabled()) {
// Get a transform if the current mode wants one.
var transform = mode.transformAction(session.getState(cursor.row), 'insertion', this, session, text);
if (transform)
text = transform.text;
}
text = text.replace("\t", this.session.getTabString());
// remove selected text
@ -455,7 +455,7 @@ var Editor =function(renderer, session) {
var line = session.getLine(cursor.row);
var lineIndent = mode.getNextLineIndent(lineState, line.slice(0, cursor.column), session.getTabString());
var end = session.insert(cursor, text);
if (transform && transform.selection) {
if (transform.selection.length == 2) { // Transform relative to the current column
this.selection.setSelectionRange(
@ -469,7 +469,7 @@ var Editor =function(renderer, session) {
transform.selection[3]));
}
}
var lineState = session.getState(cursor.row);
// TODO disabled multiline auto indent
@ -515,8 +515,27 @@ var Editor =function(renderer, session) {
}
};
this.onTextInput = function(text) {
this.keyBinding.onTextInput(text);
this.onTextInput = function(text, notPasted) {
// In case the text was not pasted and we got only one character, then
// handel it as a command key stroke.
if (notPasted && text.length == 1) {
// Note: The `null` as `keyCode` is important here, as there are
// some checks in the code for `keyCode == 0` meaning the text comes
// from the keyBinding.onTextInput code path.
var handled = this.keyBinding.onCommandKey({}, 0, null, text);
// Check if the text was handled. If not, then handled it as "normal"
// text and insert it to the editor directly. This shouldn't be done
// using the this.keyBinding.onTextInput(text) function, as it would
// make the `text` get sent to the keyboardHandler twice, which might
// turn out to be a bad thing in case there is a custome keyboard
// handler like the StateHandler.
if (!handled) {
this.insert(text);
}
} else {
this.keyBinding.onTextInput(text);
}
};
this.onCommandKey = function(e, hashId, keyCode) {
@ -619,12 +638,12 @@ var Editor =function(renderer, session) {
this.getReadOnly = function() {
return this.$readOnly;
};
this.$modeBehaviours = false;
this.setBehavioursEnabled = function (enabled) {
this.$modeBehaviours = enabled;
}
this.getBehavioursEnabled = function () {
return this.$modeBehaviours;
}
@ -646,7 +665,7 @@ var Editor =function(renderer, session) {
if (this.selection.isEmpty())
this.selection.selectLeft();
var range = this.getSelectionRange();
if (this.getBehavioursEnabled()) {
var session = this.session;