Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js |
— | — | @@ -70,7 +70,7 @@ |
71 | 71 | // Keep a copy of the current selection on hand |
72 | 72 | _this.currentSelection = selection.clone(); |
73 | 73 | // Respond to selection changes |
74 | | - _this.updateSelection( 0 ); |
| 74 | + _this.updateSelection(); |
75 | 75 | } ); |
76 | 76 | this.model.getDocument().on( 'update', function() { |
77 | 77 | _this.emitUpdate( 25 ); |
— | — | @@ -141,31 +141,45 @@ |
142 | 142 | /* Methods */ |
143 | 143 | |
144 | 144 | es.SurfaceView.prototype.updateSelection = function( delay ) { |
145 | | - if ( this.updateSelectionTimeout !== undefined ) { |
146 | | - return; |
147 | | - } |
148 | | - var _this = this; |
149 | | - this.updateSelectionTimeout = setTimeout( function() { |
150 | | - if ( _this.currentSelection.from !== _this.currentSelection.to ) { |
151 | | - _this.hideCursor(); |
152 | | - _this.documentView.drawSelection( _this.currentSelection ); |
| 145 | + if ( delay ) { |
| 146 | + if ( this.updateSelectionTimeout !== undefined ) { |
| 147 | + return; |
| 148 | + } |
| 149 | + var _this = this; |
| 150 | + this.updateSelectionTimeout = setTimeout( function() { |
| 151 | + if ( _this.currentSelection.from !== _this.currentSelection.to ) { |
| 152 | + _this.hideCursor(); |
| 153 | + _this.documentView.drawSelection( _this.currentSelection ); |
| 154 | + } else { |
| 155 | + _this.showCursor(); |
| 156 | + _this.documentView.clearSelection( _this.currentSelection ); |
| 157 | + } |
| 158 | + _this.updateSelectionTimeout = undefined; |
| 159 | + }, delay || 0 ); |
| 160 | + } else { |
| 161 | + if ( this.currentSelection.from !== this.currentSelection.to ) { |
| 162 | + this.hideCursor(); |
| 163 | + this.documentView.drawSelection( this.currentSelection ); |
153 | 164 | } else { |
154 | | - _this.showCursor(); |
155 | | - _this.documentView.clearSelection( _this.currentSelection ); |
| 165 | + this.showCursor(); |
| 166 | + this.documentView.clearSelection( this.currentSelection ); |
156 | 167 | } |
157 | | - _this.updateSelectionTimeout = undefined; |
158 | | - }, delay || 0 ); |
| 168 | + } |
159 | 169 | }; |
160 | 170 | |
161 | 171 | es.SurfaceView.prototype.emitUpdate = function( delay ) { |
162 | | - if ( this.emitUpdateTimeout !== undefined ) { |
163 | | - return; |
| 172 | + if ( delay ) { |
| 173 | + if ( this.emitUpdateTimeout !== undefined ) { |
| 174 | + return; |
| 175 | + } |
| 176 | + var _this = this; |
| 177 | + this.emitUpdateTimeout = setTimeout( function() { |
| 178 | + _this.emit( 'update' ); |
| 179 | + _this.emitUpdateTimeout = undefined; |
| 180 | + }, delay || 0 ); |
| 181 | + } else { |
| 182 | + this.emit( 'update' ); |
164 | 183 | } |
165 | | - var _this = this; |
166 | | - this.emitUpdateTimeout = setTimeout( function() { |
167 | | - _this.emit( 'update' ); |
168 | | - _this.emitUpdateTimeout = undefined; |
169 | | - }, delay || 0 ); |
170 | 184 | }; |
171 | 185 | |
172 | 186 | es.SurfaceView.prototype.onMouseDown = function( e ) { |