allow behaviours to handle removeRight as well

This commit is contained in:
nightwing 2011-10-04 21:55:51 +05:00
commit a2cd7be899
2 changed files with 12 additions and 18 deletions

View file

@ -303,7 +303,7 @@ canon.addCommand({
canon.addCommand({ canon.addCommand({
name: "del", name: "del",
bindKey: bindKey("Delete", "Delete|Ctrl-D"), bindKey: bindKey("Delete", "Delete|Ctrl-D"),
exec: function(env, args, request) { env.editor.removeRight(); } exec: function(env, args, request) { env.editor.remove("right"); }
}); });
canon.addCommand({ canon.addCommand({
name: "backspace", name: "backspace",
@ -311,7 +311,7 @@ canon.addCommand({
"Ctrl-Backspace|Command-Backspace|Option-Backspace|Shift-Backspace|Backspace", "Ctrl-Backspace|Command-Backspace|Option-Backspace|Shift-Backspace|Backspace",
"Ctrl-Backspace|Command-Backspace|Shift-Backspace|Backspace|Ctrl-H" "Ctrl-Backspace|Command-Backspace|Shift-Backspace|Backspace|Ctrl-H"
), ),
exec: function(env, args, request) { env.editor.removeLeft(); } exec: function(env, args, request) { env.editor.remove("left"); }
}); });
canon.addCommand({ canon.addCommand({
name: "removetolinestart", name: "removetolinestart",

View file

@ -656,32 +656,26 @@ var Editor =function(renderer, session) {
return this.$modeBehaviours; return this.$modeBehaviours;
}; };
this.removeRight = function() { this.remove = function(dir) {
if (this.$readOnly) if (this.$readOnly)
return; return;
if (this.selection.isEmpty()) { if (this.selection.isEmpty()){
this.selection.selectRight(); if(dir == "left")
} this.selection.selectLeft();
this.session.remove(this.getSelectionRange()); else
this.clearSelection(); this.selection.selectRight();
}; }
this.removeLeft = function() {
if (this.$readOnly)
return;
if (this.selection.isEmpty())
this.selection.selectLeft();
var range = this.getSelectionRange(); var range = this.getSelectionRange();
if (this.getBehavioursEnabled()) { if (this.getBehavioursEnabled()) {
var session = this.session; var session = this.session;
var state = session.getState(range.start.row); var state = session.getState(range.start.row);
var new_range = session.getMode().transformAction(state, 'deletion', this, session, range); var new_range = session.getMode().transformAction(state, 'deletion', this, session, range);
if (new_range !== false) { if (new_range === false)
return;
if (new_range)
range = new_range; range = new_range;
}
} }
this.session.remove(range); this.session.remove(range);