Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.Surface.js |
— | — | @@ -84,7 +84,9 @@ |
85 | 85 | /* Methods */ |
86 | 86 | |
87 | 87 | ve.ce.Surface.prototype.annotate = function( method, annotation ) { |
88 | | - var range = this.getSelection(); |
| 88 | + var range = this.getSelection(), |
| 89 | + _this = this; |
| 90 | + |
89 | 91 | if ( method === 'toggle' ) { |
90 | 92 | var annotations = this.getAnnotations(); |
91 | 93 | if ( ve.dm.DocumentNode.getIndexOfAnnotation( annotations.full, annotation ) !== -1 ) { |
— | — | @@ -97,12 +99,16 @@ |
98 | 100 | var tx = this.model.getDocument().prepareContentAnnotation( |
99 | 101 | range, method, annotation |
100 | 102 | ); |
101 | | - |
| 103 | + |
| 104 | + // transact with autoRender |
102 | 105 | this.autoRender = true; |
103 | 106 | this.model.transact( tx ); |
104 | 107 | this.autoRender = false; |
105 | | - //TODO: Redraw selection |
106 | | - |
| 108 | + |
| 109 | + this.clearPollData(); |
| 110 | + |
| 111 | + // show cursor |
| 112 | + _this.showCursorAt(range.to); |
107 | 113 | } else { |
108 | 114 | if ( method === 'set' ) { |
109 | 115 | this.addInsertionAnnotation( annotation ); |
— | — | @@ -175,11 +181,7 @@ |
176 | 182 | // re-render |
177 | 183 | _this.getLeafNode( node ).data( 'view' ).renderContent(); |
178 | 184 | |
179 | | - // clear the prev information from poll object (probably a better way to do this) |
180 | | - _this.poll.prevText = |
181 | | - _this.poll.prevHash = |
182 | | - _this.poll.prevOffset = |
183 | | - _this.poll.node = null; |
| 185 | + _this.clearPollData(); |
184 | 186 | |
185 | 187 | // place cursor |
186 | 188 | _this.showCursorAt( selection.start ); |
— | — | @@ -196,7 +198,7 @@ |
197 | 199 | .html('') |
198 | 200 | .show() |
199 | 201 | .css( 'top', $(window).scrollTop() ) |
200 | | - .css(' left', $(window).scrollLeft() ) |
| 202 | + .css( 'left', $(window).scrollLeft() ) |
201 | 203 | .focus(); |
202 | 204 | |
203 | 205 | setTimeout( function() { |
— | — | @@ -211,11 +213,7 @@ |
212 | 214 | _this.model.transact( tx ); |
213 | 215 | _this.autoRender = false; |
214 | 216 | |
215 | | - // clear the prev information from poll object (probably a better way to do this) |
216 | | - _this.poll.prevText = |
217 | | - _this.poll.prevHash = |
218 | | - _this.poll.prevOffset = |
219 | | - _this.poll.node = null; |
| 217 | + _this.clearPollData(); |
220 | 218 | |
221 | 219 | // place cursor |
222 | 220 | _this.showCursorAt( insertionPoint + _this.clipboard[key].length ); |
— | — | @@ -272,6 +270,15 @@ |
273 | 271 | } |
274 | 272 | }; |
275 | 273 | |
| 274 | +ve.ce.Surface.prototype.clearPollData = function() { |
| 275 | + this.stopPolling(); |
| 276 | + this.poll.prevText = |
| 277 | + this.poll.prevHash = |
| 278 | + this.poll.prevOffset = |
| 279 | + this.poll.node = null; |
| 280 | + this.startPolling(); |
| 281 | +}; |
| 282 | + |
276 | 283 | ve.ce.Surface.prototype.pollContent = function() { |
277 | 284 | var localOffset, text, hash; |
278 | 285 | |