r113304 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113303‎ | r113304 | r113305 >
Date:21:37, 7 March 2012
Author:inez
Status:deferred
Tags:
Comment:
Small refactoring. Changed method name, from Surface.getSelection to Surface.getSelectionRange.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.Surface.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.Surface.js
@@ -84,7 +84,7 @@
8585 /* Methods */
8686
8787 ve.ce.Surface.prototype.annotate = function( method, annotation ) {
88 - var range = this.getSelection(),
 88+ var range = this.getSelectionRange(),
8989 _this = this;
9090
9191 if ( method === 'toggle' ) {
@@ -164,14 +164,14 @@
165165 sel = rangy.getSelection(),
166166 key = sel.getRangeAt(0).toString().replace( /\s/gm, '' );
167167
168 - _this.clipboard[key] = ve.copyArray( _this.documentView.model.getData( _this.getSelection() ) );
 168+ _this.clipboard[key] = ve.copyArray( _this.documentView.model.getData( _this.getSelectionRange() ) );
169169
170170 if ( event.type == 'cut' ) {
171171 setTimeout( function() {
172172 // we don't like how browsers cut, so let's undo it and do it ourselves.
173173 document.execCommand('undo', false, false);
174174
175 - var selection = _this.getSelection(),
 175+ var selection = _this.getSelectionRange(),
176176 node = rangy.getSelection().anchorNode;
177177
178178 // transact
@@ -191,7 +191,7 @@
192192
193193 ve.ce.Surface.prototype.onPaste = function( e ) {
194194 var _this = this,
195 - insertionPoint = _this.getSelection().start,
 195+ insertionPoint = _this.getSelectionRange().start,
196196 node = rangy.getSelection().anchorNode;
197197
198198 $('#paste')
@@ -448,7 +448,7 @@
449449 }
450450 break;
451451 }
452 - var range = this.getSelection();
 452+ var range = this.getSelectionRange();
453453 if ( range.getLength() !== 0 ) {
454454 e.preventDefault();
455455 }
@@ -546,21 +546,23 @@
547547 sel.addRange( range );
548548 };
549549
550 -ve.ce.Surface.prototype.getSelection = function() {
551 - var sel = rangy.getSelection(),
552 - range;
553550
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 );
557561 } 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 )
561565 );
562566 }
563 - range.normalize();
564 - return range;
565567 };
566568
567569 ve.ce.Surface.prototype.getLeafNode = function( elem ) {
@@ -621,7 +623,7 @@
622624
623625 ve.ce.Surface.prototype.handleDelete = function( backspace, isPartial ) {
624626 this.stopPolling();
625 - var selection = this.getSelection().clone(),
 627+ var selection = this.getSelectionRange().clone(),
626628 sourceOffset,
627629 targetOffset,
628630 sourceSplitableNode,
@@ -700,7 +702,7 @@
701703
702704 ve.ce.Surface.prototype.handleEnter = function() {
703705 this.stopPolling();
704 - var selection = this.getSelection().clone(),
 706+ var selection = this.getSelectionRange().clone(),
705707 tx;
706708 if ( selection.from !== selection.to ) {
707709 this.handleDelete( false, true );

Status & tagging log