r105519 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105518‎ | r105519 | r105520 >
Date:06:40, 8 December 2011
Author:inez
Status:deferred
Tags:
Comment:
Update selection after unlisting list items
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/tools/es.ListButtonTool.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/tools/es.ListButtonTool.js
@@ -150,7 +150,10 @@
151151 offset: 0,
152152 length: 0
153153 },
154 - surface = this.toolbar.surfaceView;
 154+ surface = this.toolbar.surfaceView,
 155+ selection = surface.currentSelection.clone(),
 156+ from = 0,
 157+ to = 0;
155158
156159 for( i = 0; i < listItems.length; i++ ) {
157160 if( stack.nodes.length > 0 ) {
@@ -201,6 +204,8 @@
202205 surface.model.transact( tx );
203206 tx = surface.model.getDocument().prepareInsertion( stack.offset - 1, data );
204207 surface.model.transact( tx );
 208+ from = -2;
 209+ to += -(stack.nodes.length * 2);
205210 } else if ( stack.first === true && stack.last === false ) {
206211 tx = surface.model.getDocument().prepareRemoval(
207212 new es.Range( stack.offset, stack.offset + stack.length )
@@ -208,6 +213,8 @@
209214 surface.model.transact( tx );
210215 tx = surface.model.getDocument().prepareInsertion( stack.offset - 1, data );
211216 surface.model.transact( tx );
 217+ from = -2;
 218+ to += -(stack.nodes.length * 2);
212219 } else if ( stack.first === false && stack.last === true ) {
213220 tx = surface.model.getDocument().prepareRemoval(
214221 new es.Range( stack.offset, stack.offset + stack.length )
@@ -215,6 +222,8 @@
216223 surface.model.transact( tx );
217224 tx = surface.model.getDocument().prepareInsertion( stack.offset + 1, data );
218225 surface.model.transact( tx );
 226+ to += -(stack.nodes.length * 2);
 227+ to += 2;
219228 } else if ( stack.first === false && stack.last === false ) {
220229 var parent = stack.nodes[0].getParent();
221230 var parentOffset = surface.documentView.model.getOffsetFromNode( parent, false );
@@ -239,8 +248,23 @@
240249
241250 tx = surface.model.getDocument().prepareInsertion( stack.offset + 1, data );
242251 surface.model.transact( tx );
 252+ to += -(stack.nodes.length * 2);
 253+ to += 2;
243254 }
244255 }
 256+ if ( selection.from === selection.to ) {
 257+ selection.from += from;
 258+ selection.to += from;
 259+ } else {
 260+ if ( selection.to > selection.from ) {
 261+ selection.from += from;
 262+ selection.to += to;
 263+ } else {
 264+ selection.to += from;
 265+ selection.from += to;
 266+ }
 267+ }
 268+ surface.model.select( selection, true );
245269 };
246270
247271 es.ListButtonTool.prototype.onClick = function() {

Status & tagging log