r103581 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103580‎ | r103581 | r103582 >
Date:08:10, 18 November 2011
Author:inez
Status:deferred
Tags:
Comment:
Place cursor in correct place after deleting selected content.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js
@@ -170,10 +170,12 @@
171171
172172 } else if ( e.originalEvent.detail >= 3 ) { // triple click
173173 this.mouse.selectingMode = 3; // used in mouseMove handler
174 -
175 - var node = this.documentView.getNodeFromOffset( offset );
176 - this.selection.from = this.documentView.getOffsetFromNode( node, false ) + 1;
177 - this.selection.to = this.selection.from + node.getElementLength() - 2;
 174+
 175+ var node = this.documentView.getNodeFromOffset( offset ),
 176+ nodeOffset = this.documentView.getOffsetFromNode( node, false );
 177+
 178+ this.selection.from = this.documentView.getModel().getRelativeContentOffset( nodeOffset, 1 );
 179+ this.selection.to = this.documentView.getModel().getRelativeContentOffset( nodeOffset + node.getElementLength(), -1 );
178180 this.mouse.selectedRange = this.selection.clone();
179181 }
180182
@@ -214,14 +216,17 @@
215217 this.selection.to = offset;
216218 }
217219 } else if ( this.mouse.selectingMode === 3 ) {
 220+
 221+ this.mouse.selectingMode = 3; // used in mouseMove handler
 222+
218223 var nodeRange = this.documentView.getRangeFromNode(
219224 this.documentView.getNodeFromOffset( offset )
220225 );
221226 if ( nodeRange.to <= this.mouse.selectedRange.from ) {
222 - this.selection.to = nodeRange.from;
 227+ this.selection.to = this.documentView.getModel().getRelativeContentOffset( nodeRange.from, 1 );
223228 this.selection.from = this.mouse.selectedRange.to;
224229 } else {
225 - this.selection.to = nodeRange.to;
 230+ this.selection.to = this.documentView.getModel().getRelativeContentOffset( nodeRange.to, -1 );
226231 this.selection.from = this.mouse.selectedRange.from;
227232 }
228233 }
@@ -359,7 +364,7 @@
360365 var tx = this.documentView.model.prepareRemoval( this.selection );
361366 this.documentView.model.commit( tx );
362367 this.documentView.clearSelection();
363 - this.selection.to = this.selection.from;
 368+ this.selection.from = this.selection.to = Math.min( this.selection.from, this.selection.to );
364369 this.showCursor();
365370 }
366371 break;
@@ -403,7 +408,7 @@
404409 var tx = this.documentView.model.prepareRemoval( this.selection );
405410 this.documentView.model.commit( tx );
406411 this.documentView.clearSelection();
407 - this.selection.to = this.selection.from;
 412+ this.selection.from = this.selection.to = Math.min( this.selection.from, this.selection.to );
408413 this.showCursor();
409414 }
410415 break;
@@ -480,11 +485,13 @@
481486 var tx = this.documentView.model.prepareRemoval( this.selection );
482487 this.documentView.model.commit( tx );
483488 this.documentView.clearSelection();
 489+ this.selection.from = this.selection.to = Math.min( this.selection.from, this.selection.to );
484490 }
485491
486492 var tx = this.documentView.model.prepareInsertion( this.selection.from, val.split('') );
487493 this.documentView.model.commit ( tx );
488 - this.selection.to = this.selection.from += val.length;
 494+ this.selection.from += val.length;
 495+ this.selection.to += val.length;
489496 this.showCursor();
490497 }
491498 };

Status & tagging log