Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js |
— | — | @@ -123,11 +123,13 @@ |
124 | 124 | |
125 | 125 | ve.es.Surface.prototype.pollContent = function() { |
126 | 126 | if ( this.poll.compositionStart !== null && this.poll.compositionEnd !== null ) { |
| 127 | + |
127 | 128 | var text = ve.es.Surface.getDOMText2( this.poll.node ), |
128 | 129 | hash = ve.es.Surface.getDOMHash( this.poll.node ), |
129 | 130 | localOffset = this.poll.compositionEnd; |
130 | 131 | this.poll.compositionStart = null; |
131 | 132 | this.poll.compositionEnd = null; |
| 133 | + |
132 | 134 | } else { |
133 | 135 | var rangySel = rangy.getSelection(); |
134 | 136 | |
— | — | @@ -183,7 +185,7 @@ |
184 | 186 | nodeOffset + 1 + this.poll.prevText.length - sameFromRight |
185 | 187 | ) ) ); |
186 | 188 | var newData = text.substring( sameFromLeft, text.length - sameFromRight ).split( '' ); |
187 | | - var annotations = this.model.getDocument().getAnnotationsFromOffset( nodeOffset + 1 + sameFromLeft - 1 ); |
| 189 | + var annotations = this.model.getDocument().getAnnotationsFromOffset( nodeOffset + 1 + sameFromLeft ); |
188 | 190 | ve.dm.DocumentNode.addAnnotationsToData( newData, annotations ); |
189 | 191 | this.model.transact( this.documentView.model.prepareInsertion( |
190 | 192 | nodeOffset + 1 + sameFromLeft, |
— | — | @@ -295,6 +297,20 @@ |
296 | 298 | sel.addRange(range); |
297 | 299 | }; |
298 | 300 | |
| 301 | +ve.es.Surface.prototype.getSelection = function() { |
| 302 | + var selection = rangy.getSelection(); |
| 303 | + |
| 304 | + if ( selection.anchorNode === selection.focusNode && selection.anchorOffset === selection.focusOffset ) { |
| 305 | + var offset = this.getOffset( selection.anchorNode, selection.anchorOffset ); |
| 306 | + return new ve.Range( offset, offset ); |
| 307 | + } else { |
| 308 | + return new ve.Range( |
| 309 | + this.getOffset( selection.anchorNode, selection.anchorOffset ), |
| 310 | + this.getOffset( selection.focusNode, selection.focusOffset ) |
| 311 | + ); |
| 312 | + } |
| 313 | +}; |
| 314 | + |
299 | 315 | ve.es.Surface.prototype.getLeafNode = function( elem ) { |
300 | 316 | var $node = $( elem ); |
301 | 317 | while( !$node.hasClass( 'ce-leafNode' ) ) { |