r112833 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112832‎ | r112833 | r112834 >
Date:20:49, 1 March 2012
Author:inez
Status:deferred
Tags:
Comment:
Added getSelection method to Surface
Modified paths:
  • /trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js
@@ -123,11 +123,13 @@
124124
125125 ve.es.Surface.prototype.pollContent = function() {
126126 if ( this.poll.compositionStart !== null && this.poll.compositionEnd !== null ) {
 127+
127128 var text = ve.es.Surface.getDOMText2( this.poll.node ),
128129 hash = ve.es.Surface.getDOMHash( this.poll.node ),
129130 localOffset = this.poll.compositionEnd;
130131 this.poll.compositionStart = null;
131132 this.poll.compositionEnd = null;
 133+
132134 } else {
133135 var rangySel = rangy.getSelection();
134136
@@ -183,7 +185,7 @@
184186 nodeOffset + 1 + this.poll.prevText.length - sameFromRight
185187 ) ) );
186188 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 );
188190 ve.dm.DocumentNode.addAnnotationsToData( newData, annotations );
189191 this.model.transact( this.documentView.model.prepareInsertion(
190192 nodeOffset + 1 + sameFromLeft,
@@ -295,6 +297,20 @@
296298 sel.addRange(range);
297299 };
298300
 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+
299315 ve.es.Surface.prototype.getLeafNode = function( elem ) {
300316 var $node = $( elem );
301317 while( !$node.hasClass( 'ce-leafNode' ) ) {

Status & tagging log