Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js |
— | — | @@ -27,6 +27,7 @@ |
28 | 28 | .appendTo( 'body' ); |
29 | 29 | this.$cursor = $( '<div class="es-surfaceView-cursor"></div>' ) |
30 | 30 | .appendTo( 'body' ); |
| 31 | + this.insertionAnnotations = []; |
31 | 32 | this.updateSelectionTimeout = undefined; |
32 | 33 | this.emitUpdateTimeout = undefined; |
33 | 34 | |
— | — | @@ -135,38 +136,55 @@ |
136 | 137 | |
137 | 138 | /* Methods */ |
138 | 139 | |
| 140 | +es.SurfaceView.prototype.getInsertionAnnotations = function() { |
| 141 | + return this.insertionAnnotations; |
| 142 | +}; |
| 143 | + |
| 144 | +es.SurfaceView.prototype.addInsertionAnnotation = function( annotation ) { |
| 145 | + this.insertionAnnotations.push( annotation ); |
| 146 | +}; |
| 147 | + |
| 148 | +es.SurfaceView.prototype.removeInsertionAnnotation = function( annotation ) { |
| 149 | + var index = es.DocumentView.getIndexOfAnnotation( this.insertionAnnotations, annotation ); |
| 150 | + if ( index !== -1 ) { |
| 151 | + this.insertionAnnotations.splice( index, 1 ); |
| 152 | + } |
| 153 | +}; |
| 154 | + |
| 155 | +es.SurfaceView.prototype.clearInsertionAnnotations = function() { |
| 156 | + this.insertionAnnotations = []; |
| 157 | +}; |
| 158 | + |
139 | 159 | es.SurfaceView.prototype.getModel = function() { |
140 | 160 | return this.model; |
141 | 161 | }; |
142 | 162 | |
143 | 163 | es.SurfaceView.prototype.updateSelection = function( delay ) { |
| 164 | + var _this = this; |
| 165 | + function update() { |
| 166 | + if ( _this.currentSelection.from !== _this.currentSelection.to ) { |
| 167 | + _this.hideCursor(); |
| 168 | + _this.documentView.drawSelection( _this.currentSelection ); |
| 169 | + // Update the context icon position |
| 170 | + _this.contextView.update(); |
| 171 | + // Clear insertion annotations |
| 172 | + _this.insertionAnnotations = []; |
| 173 | + } else { |
| 174 | + _this.showCursor(); |
| 175 | + _this.documentView.clearSelection( _this.currentSelection ); |
| 176 | + // Load new insertion annotations |
| 177 | + _this.insertionAnnotations = |
| 178 | + _this.model.getDocument().getAnnotationsFromOffset( _this.currentSelection.to ); |
| 179 | + } |
| 180 | + _this.updateSelectionTimeout = undefined; |
| 181 | + } |
144 | 182 | if ( delay ) { |
145 | 183 | if ( this.updateSelectionTimeout !== undefined ) { |
146 | 184 | return; |
147 | 185 | } |
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 ); |
153 | | - // Update the context icon position |
154 | | - _this.contextView.update(); |
155 | | - } else { |
156 | | - _this.showCursor(); |
157 | | - _this.documentView.clearSelection( _this.currentSelection ); |
158 | | - } |
159 | | - _this.updateSelectionTimeout = undefined; |
160 | | - }, delay ); |
| 186 | + this.updateSelectionTimeout = setTimeout( update, delay ); |
161 | 187 | } else { |
162 | | - if ( this.currentSelection.from !== this.currentSelection.to ) { |
163 | | - this.hideCursor(); |
164 | | - this.documentView.drawSelection( this.currentSelection ); |
165 | | - // Update the context icon position |
166 | | - this.contextView.update(); |
167 | | - } else { |
168 | | - this.showCursor(); |
169 | | - this.documentView.clearSelection( this.currentSelection ); |
170 | | - } |
| 188 | + update(); |
171 | 189 | } |
172 | 190 | }; |
173 | 191 | |