Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.Surface.js |
— | — | @@ -84,7 +84,7 @@ |
85 | 85 | /* Methods */ |
86 | 86 | |
87 | 87 | ve.ce.Surface.prototype.annotate = function( method, annotation ) { |
88 | | - var range = this.getSelection(), |
| 88 | + var range = this.getSelectionRange(), |
89 | 89 | _this = this; |
90 | 90 | |
91 | 91 | if ( method === 'toggle' ) { |
— | — | @@ -164,14 +164,14 @@ |
165 | 165 | sel = rangy.getSelection(), |
166 | 166 | key = sel.getRangeAt(0).toString().replace( /\s/gm, '' ); |
167 | 167 | |
168 | | - _this.clipboard[key] = ve.copyArray( _this.documentView.model.getData( _this.getSelection() ) ); |
| 168 | + _this.clipboard[key] = ve.copyArray( _this.documentView.model.getData( _this.getSelectionRange() ) ); |
169 | 169 | |
170 | 170 | if ( event.type == 'cut' ) { |
171 | 171 | setTimeout( function() { |
172 | 172 | // we don't like how browsers cut, so let's undo it and do it ourselves. |
173 | 173 | document.execCommand('undo', false, false); |
174 | 174 | |
175 | | - var selection = _this.getSelection(), |
| 175 | + var selection = _this.getSelectionRange(), |
176 | 176 | node = rangy.getSelection().anchorNode; |
177 | 177 | |
178 | 178 | // transact |
— | — | @@ -191,7 +191,7 @@ |
192 | 192 | |
193 | 193 | ve.ce.Surface.prototype.onPaste = function( e ) { |
194 | 194 | var _this = this, |
195 | | - insertionPoint = _this.getSelection().start, |
| 195 | + insertionPoint = _this.getSelectionRange().start, |
196 | 196 | node = rangy.getSelection().anchorNode; |
197 | 197 | |
198 | 198 | $('#paste') |
— | — | @@ -448,7 +448,7 @@ |
449 | 449 | } |
450 | 450 | break; |
451 | 451 | } |
452 | | - var range = this.getSelection(); |
| 452 | + var range = this.getSelectionRange(); |
453 | 453 | if ( range.getLength() !== 0 ) { |
454 | 454 | e.preventDefault(); |
455 | 455 | } |
— | — | @@ -546,21 +546,23 @@ |
547 | 547 | sel.addRange( range ); |
548 | 548 | }; |
549 | 549 | |
550 | | -ve.ce.Surface.prototype.getSelection = function() { |
551 | | - var sel = rangy.getSelection(), |
552 | | - range; |
553 | 550 | |
554 | | - if ( sel.anchorNode === sel.focusNode && sel.anchorOffset === sel.focusOffset ) { |
555 | | - var offset = this.getOffset( sel.anchorNode, sel.anchorOffset, true ); |
556 | | - range = new ve.Range( offset, offset ); |
| 551 | +/** |
| 552 | + * @method |
| 553 | + * @returns {ve.Range} Current selection range |
| 554 | + */ |
| 555 | +ve.ce.Surface.prototype.getSelectionRange = function() { |
| 556 | + var rangySel = rangy.getSelection(); |
| 557 | + |
| 558 | + if ( rangySel.isCollapsed ) { |
| 559 | + var offset = this.getOffset( rangySel.anchorNode, rangySel.anchorOffset, true ); |
| 560 | + return new ve.Range( offset, offset ); |
557 | 561 | } else { |
558 | | - range = new ve.Range( |
559 | | - this.getOffset( sel.anchorNode, sel.anchorOffset, true ), |
560 | | - this.getOffset( sel.focusNode, sel.focusOffset, true ) |
| 562 | + return new ve.Range( |
| 563 | + this.getOffset( rangySel.anchorNode, rangySel.anchorOffset, true ), |
| 564 | + this.getOffset( rangySel.focusNode, rangySel.focusOffset, true ) |
561 | 565 | ); |
562 | 566 | } |
563 | | - range.normalize(); |
564 | | - return range; |
565 | 567 | }; |
566 | 568 | |
567 | 569 | ve.ce.Surface.prototype.getLeafNode = function( elem ) { |
— | — | @@ -621,7 +623,7 @@ |
622 | 624 | |
623 | 625 | ve.ce.Surface.prototype.handleDelete = function( backspace, isPartial ) { |
624 | 626 | this.stopPolling(); |
625 | | - var selection = this.getSelection().clone(), |
| 627 | + var selection = this.getSelectionRange().clone(), |
626 | 628 | sourceOffset, |
627 | 629 | targetOffset, |
628 | 630 | sourceSplitableNode, |
— | — | @@ -700,7 +702,7 @@ |
701 | 703 | |
702 | 704 | ve.ce.Surface.prototype.handleEnter = function() { |
703 | 705 | this.stopPolling(); |
704 | | - var selection = this.getSelection().clone(), |
| 706 | + var selection = this.getSelectionRange().clone(), |
705 | 707 | tx; |
706 | 708 | if ( selection.from !== selection.to ) { |
707 | 709 | this.handleDelete( false, true ); |