Index: trunk/parsers/wikidom/lib/es/es.Surface.js |
— | — | @@ -24,6 +24,7 @@ |
25 | 25 | this.rendered = false; |
26 | 26 | this.location = null; |
27 | 27 | this.selection = null; |
| 28 | + this.keydownInterval = null; |
28 | 29 | this.render(); |
29 | 30 | |
30 | 31 | this.state = { |
— | — | @@ -64,6 +65,7 @@ |
65 | 66 | } |
66 | 67 | |
67 | 68 | Surface.prototype.onKeyDown = function( e ) { |
| 69 | + |
68 | 70 | switch ( e.keyCode ) { |
69 | 71 | case 37: // Left arrow |
70 | 72 | this.moveCursorLeft(); |
— | — | @@ -77,11 +79,48 @@ |
78 | 80 | case 40: // Down arrow |
79 | 81 | this.moveCursorDown(); |
80 | 82 | break; |
| 83 | + case 8: // Backspace |
| 84 | + this.handleBackspace(); |
| 85 | + break; |
| 86 | + case 46: // Delete |
| 87 | + this.handleDelete(); |
| 88 | + break; |
| 89 | + default: |
| 90 | + this.cursor.hide(); |
| 91 | + if ( this.keydownInterval ) { |
| 92 | + clearTimeout( this.keydownInterval ); |
| 93 | + } |
| 94 | + this.keydownInterval = setTimeout( function ( surface ) { |
| 95 | + var val = surface.$input.val(); |
| 96 | + surface.$input.val( '' ); |
| 97 | + if ( val.length > 0 ) { |
| 98 | + var location = surface.getLocation(); |
| 99 | + location.block.insertContent( location.offset, val); |
| 100 | + location.offset++; |
| 101 | + } |
| 102 | + }, 0, this ); |
| 103 | + break; |
| 104 | + } |
| 105 | + return true; |
| 106 | +} |
81 | 107 | |
| 108 | +Surface.prototype.handleBackspace = function() { |
| 109 | + var location = this.getLocation(); |
| 110 | + if ( location.offset > 0 ) { |
| 111 | + location.block.deleteContent( location.offset - 1, location.offset ); |
| 112 | + location.offset--; |
| 113 | + this.cursor.show( location.block.flow.getPosition( location.offset ), location.block.$.offset() ); |
82 | 114 | } |
83 | | - return true; |
84 | 115 | } |
85 | 116 | |
| 117 | +Surface.prototype.handleDelete = function() { |
| 118 | + var location = this.getLocation(); |
| 119 | + if ( location.offset < location.block.getLength() - 1 ) { |
| 120 | + location.block.deleteContent( location.offset, location.offset + 1); |
| 121 | + this.cursor.show( location.block.flow.getPosition( location.offset ), location.block.$.offset() ); |
| 122 | + } |
| 123 | +} |
| 124 | + |
86 | 125 | Surface.prototype.onMouseDown = function( e ) { |
87 | 126 | var $target = $( e.target ); |
88 | 127 | $block = $target.is( '.editSurface-block' ) |