Index: trunk/extensions/VisualEditor/modules/es/es.TransactionProcessor.js |
— | — | @@ -171,7 +171,7 @@ |
172 | 172 | return node; |
173 | 173 | }; |
174 | 174 | |
175 | | -es.TransactionProcessor.prototype.applyAnnotations = function( to ) { |
| 175 | +es.TransactionProcessor.prototype.applyAnnotations = function( to, update ) { |
176 | 176 | var i, |
177 | 177 | j, |
178 | 178 | length, |
— | — | @@ -213,10 +213,16 @@ |
214 | 214 | } |
215 | 215 | } |
216 | 216 | } |
| 217 | + if ( update ) { |
| 218 | + var updates = this.model.selectNodes( new es.Range( this.cursor, to ) ); |
| 219 | + for ( i = 0; i < updates.length; i++ ) { |
| 220 | + updates[i].node.emit( 'update' ); |
| 221 | + } |
| 222 | + } |
217 | 223 | }; |
218 | 224 | |
219 | 225 | es.TransactionProcessor.prototype.retain = function( op ) { |
220 | | - this.applyAnnotations( this.cursor + op.length ); |
| 226 | + this.applyAnnotations( this.cursor + op.length, true ); |
221 | 227 | this.cursor += op.length; |
222 | 228 | }; |
223 | 229 | |
Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js |
— | — | @@ -26,6 +26,7 @@ |
27 | 27 | .prependTo( this.$ ); |
28 | 28 | this.$cursor = $( '<div class="es-surfaceView-cursor"></div>' ) |
29 | 29 | .appendTo( this.$ ); |
| 30 | + this.updateSelectionTimeout = undefined; |
30 | 31 | |
31 | 32 | // Interaction states |
32 | 33 | |
— | — | @@ -68,16 +69,12 @@ |
69 | 70 | // Keep a copy of the current selection on hand |
70 | 71 | _this.currentSelection = selection.clone(); |
71 | 72 | // Respond to selection changes |
72 | | - if ( selection.from !== selection.to ) { |
73 | | - _this.hideCursor(); |
74 | | - _this.documentView.drawSelection( selection ); |
75 | | - } else { |
76 | | - _this.showCursor(); |
77 | | - _this.documentView.clearSelection( selection ); |
78 | | - } |
| 73 | + _this.updateSelection( 0 ); |
79 | 74 | } ); |
80 | 75 | this.model.getDocument().on( 'update', function() { |
81 | 76 | _this.emit( 'update' ); |
| 77 | + // Respond to layout changes |
| 78 | + _this.updateSelection( 50 ); |
82 | 79 | } ); |
83 | 80 | this.$.mousedown( function(e) { |
84 | 81 | return _this.onMouseDown( e ); |
— | — | @@ -142,12 +139,28 @@ |
143 | 140 | |
144 | 141 | /* Methods */ |
145 | 142 | |
| 143 | +es.SurfaceView.prototype.updateSelection = function( delay ) { |
| 144 | + if ( this.updateSelectionTimeout !== undefined ) { |
| 145 | + return; |
| 146 | + } |
| 147 | + var _this = this; |
| 148 | + this.updateSelectionTimeout = setTimeout( function() { |
| 149 | + if ( _this.currentSelection.from !== _this.currentSelection.to ) { |
| 150 | + _this.hideCursor(); |
| 151 | + _this.documentView.drawSelection( _this.currentSelection ); |
| 152 | + } else { |
| 153 | + _this.showCursor(); |
| 154 | + _this.documentView.clearSelection( _this.currentSelection ); |
| 155 | + } |
| 156 | + _this.updateSelectionTimeout = undefined; |
| 157 | + }, delay ); |
| 158 | +}; |
| 159 | + |
146 | 160 | es.SurfaceView.prototype.onMouseDown = function( e ) { |
147 | 161 | // Only for left mouse button |
148 | 162 | if ( e.button === 0 ) { |
149 | 163 | var selection = this.currentSelection.clone(), |
150 | 164 | offset = this.documentView.getOffsetFromEvent( e ); |
151 | | - |
152 | 165 | // Single click |
153 | 166 | if ( e.originalEvent.detail === 1 ) { |
154 | 167 | // @see {es.SurfaceView.prototype.onMouseMove} |
— | — | @@ -163,7 +176,6 @@ |
164 | 177 | nodeView = this.documentView.getNodeFromOffset( offset, false ); |
165 | 178 | this.cursor.initialBias = position.left > nodeView.contentView.$.offset().left; |
166 | 179 | } |
167 | | - |
168 | 180 | } |
169 | 181 | // Double click |
170 | 182 | else if ( e.originalEvent.detail === 2 ) { |
— | — | @@ -175,7 +187,6 @@ |
176 | 188 | selection = wordRange; |
177 | 189 | this.mouse.selectedRange = selection.clone(); |
178 | 190 | } |
179 | | - |
180 | 191 | } |
181 | 192 | // Triple click |
182 | 193 | else if ( e.originalEvent.detail >= 3 ) { |
— | — | @@ -191,7 +202,6 @@ |
192 | 203 | ); |
193 | 204 | this.mouse.selectedRange = selection.clone(); |
194 | 205 | } |
195 | | - |
196 | 206 | // Reset the initial left position |
197 | 207 | this.cursor.initialLeft = null; |
198 | 208 | // Apply new selection |