Index: trunk/extensions/VisualEditor/modules/es/tools/es.ListButtonTool.js |
— | — | @@ -150,7 +150,10 @@ |
151 | 151 | offset: 0, |
152 | 152 | length: 0 |
153 | 153 | }, |
154 | | - surface = this.toolbar.surfaceView; |
| 154 | + surface = this.toolbar.surfaceView, |
| 155 | + selection = surface.currentSelection.clone(), |
| 156 | + from = 0, |
| 157 | + to = 0; |
155 | 158 | |
156 | 159 | for( i = 0; i < listItems.length; i++ ) { |
157 | 160 | if( stack.nodes.length > 0 ) { |
— | — | @@ -201,6 +204,8 @@ |
202 | 205 | surface.model.transact( tx ); |
203 | 206 | tx = surface.model.getDocument().prepareInsertion( stack.offset - 1, data ); |
204 | 207 | surface.model.transact( tx ); |
| 208 | + from = -2; |
| 209 | + to += -(stack.nodes.length * 2); |
205 | 210 | } else if ( stack.first === true && stack.last === false ) { |
206 | 211 | tx = surface.model.getDocument().prepareRemoval( |
207 | 212 | new es.Range( stack.offset, stack.offset + stack.length ) |
— | — | @@ -208,6 +213,8 @@ |
209 | 214 | surface.model.transact( tx ); |
210 | 215 | tx = surface.model.getDocument().prepareInsertion( stack.offset - 1, data ); |
211 | 216 | surface.model.transact( tx ); |
| 217 | + from = -2; |
| 218 | + to += -(stack.nodes.length * 2); |
212 | 219 | } else if ( stack.first === false && stack.last === true ) { |
213 | 220 | tx = surface.model.getDocument().prepareRemoval( |
214 | 221 | new es.Range( stack.offset, stack.offset + stack.length ) |
— | — | @@ -215,6 +222,8 @@ |
216 | 223 | surface.model.transact( tx ); |
217 | 224 | tx = surface.model.getDocument().prepareInsertion( stack.offset + 1, data ); |
218 | 225 | surface.model.transact( tx ); |
| 226 | + to += -(stack.nodes.length * 2); |
| 227 | + to += 2; |
219 | 228 | } else if ( stack.first === false && stack.last === false ) { |
220 | 229 | var parent = stack.nodes[0].getParent(); |
221 | 230 | var parentOffset = surface.documentView.model.getOffsetFromNode( parent, false ); |
— | — | @@ -239,8 +248,23 @@ |
240 | 249 | |
241 | 250 | tx = surface.model.getDocument().prepareInsertion( stack.offset + 1, data ); |
242 | 251 | surface.model.transact( tx ); |
| 252 | + to += -(stack.nodes.length * 2); |
| 253 | + to += 2; |
243 | 254 | } |
244 | 255 | } |
| 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 ); |
245 | 269 | }; |
246 | 270 | |
247 | 271 | es.ListButtonTool.prototype.onClick = function() { |