Support for deleting text with backspace and delete

This commit is contained in:
Inez Korczynski 2011-11-05 00:59:20 +00:00
parent b4b043e06e
commit cc6fc80bee

View file

@ -195,8 +195,14 @@ es.SurfaceView.prototype.onKeyDown = function( e ) {
this.moveCursor( 'down' );
break;
case 8: // Backspace
var transaction = this.documentView.model.prepareRemoval( new es.Range( this.selection.to, this.selection.to - 1 ) );
this.documentView.model.commit ( transaction );
this.selection.from = this.selection.to -= 1;
this.showCursor();
break;
case 46: // Delete
var transaction = this.documentView.model.prepareRemoval( new es.Range( this.selection.to, this.selection.to + 1 ) );
this.documentView.model.commit ( transaction );
break;
default: // Insert content (maybe)
if ( this.keyboard.keydownTimeout ) {
@ -217,7 +223,7 @@ es.SurfaceView.prototype.insertFromInput = function() {
if ( val.length > 0 ) {
var transaction = this.documentView.model.prepareInsertion( this.selection.to, val.split('') );
this.documentView.model.commit ( transaction );
this.selection.to += val.length;
this.selection.from = this.selection.to += val.length;
this.showCursor();
}
};