Preserve selection when inserting references

Some browsers (e.g. Firefox) change the CE range when the dialog
is opened, so after the first surfaceModel change (to modify the
internal item) the surface's selection is modified, and the reference
is inserted in the wrong place.

Bug: 52159
Change-Id: Ia5da33b95a599ba78f308cf0554279ad44616f50
This commit is contained in:
Ed Sanders 2013-08-20 18:18:37 +01:00
parent f25d34d0a6
commit b6443b262c

View file

@ -167,6 +167,9 @@ ve.ui.MWReferenceDialog.prototype.onOpen = function () {
ve.ui.MWReferenceDialog.prototype.onClose = function ( action ) {
var i, len, txs, item, data, group, refGroup, listGroup, keyIndex, refNode, refNodes,
surfaceModel = this.surface.getModel(),
// Store the original selection browsers may reset it after
// the first model change.
selection = surfaceModel.getSelection().clone(),
doc = surfaceModel.getDocument(),
internalList = doc.getInternalList();
@ -252,7 +255,7 @@ ve.ui.MWReferenceDialog.prototype.onClose = function ( action ) {
this.ref.listIndex = item.index;
}
// Add reference at cursor
surfaceModel.getFragment().collapseRangeToEnd().insertContent( [
surfaceModel.getFragment( selection ).collapseRangeToEnd().insertContent( [
{ 'type': 'mwReference', 'attributes': this.ref }, { 'type': '/mwReference' }
] );
}