Merge "Remove remaining uses of surfaceModel#getSelection in dialogs"

This commit is contained in:
jenkins-bot 2014-04-11 18:43:14 +00:00 committed by Gerrit Code Review
commit d8453acff5
6 changed files with 46 additions and 49 deletions

View file

@ -154,29 +154,25 @@ ve.dm.MWReferenceModel.prototype.updateInternalItem = function ( surfaceModel )
};
/**
* Insert reference into a surface.
* Insert reference at the end of a surface fragment.
*
* Reference is inserted at the current cursor position in `surfaceModel`.
*
* @param {ve.dm.Surface} surfaceModel Surface model of main document
* @param {ve.Range} [at] Location to insert at
* @param {ve.dm.SurfaceFragment} surfaceModel Surface fragment to insert at
*/
ve.dm.MWReferenceModel.prototype.insertReferenceNode = function ( surfaceModel, at ) {
surfaceModel
.getFragment( at || surfaceModel.getSelection().clone(), true )
.collapseRangeToEnd()
.insertContent( [
{
'type': 'mwReference',
'attributes': {
'listKey': this.listKey,
'listGroup': this.listGroup,
'listIndex': this.listIndex,
'refGroup': this.group
}
},
{ 'type': '/mwReference' }
] );
ve.dm.MWReferenceModel.prototype.insertReferenceNode = function ( surfaceFragment ) {
surfaceFragment
.collapseRangeToEnd()
.insertContent( [
{
'type': 'mwReference',
'attributes': {
'listKey': this.listKey,
'listGroup': this.listGroup,
'listIndex': this.listIndex,
'refGroup': this.group
}
},
{ 'type': '/mwReference' }
] );
};
/**

View file

@ -49,26 +49,22 @@ OO.mixinClass( ve.dm.MWTransclusionModel, OO.EventEmitter );
/* Methods */
/**
* Insert transclusion into a surface.
* Insert transclusion at the end of a surface fragment.
*
* Transclusion is inserted at the current cursor position in `surfaceModel`.
*
* @param {ve.dm.Surface} surfaceModel Surface model of main document
* @param {ve.Range} [at] Location to insert at
* @param {ve.dm.SurfaceFragment} surfaceModel Surface fragment to insert at
*/
ve.dm.MWTransclusionModel.prototype.insertTransclusionNode = function ( surfaceModel, at ) {
surfaceModel
.getFragment( at || surfaceModel.getSelection().clone(), true )
.collapseRangeToEnd()
.insertContent( [
{
'type': 'mwTransclusionInline',
'attributes': {
'mw': this.getPlainObject()
}
},
{ 'type': '/mwTransclusionInline' }
] );
ve.dm.MWTransclusionModel.prototype.insertTransclusionNode = function ( surfaceFragment ) {
surfaceFragment
.collapseRangeToEnd()
.insertContent( [
{
'type': 'mwTransclusionInline',
'attributes': {
'mw': this.getPlainObject()
}
},
{ 'type': '/mwTransclusionInline' }
] );
};
/**

View file

@ -715,11 +715,14 @@ ve.init.mw.ViewPageTarget.prototype.onToolbarMetaButtonClick = function () {
* @param {ve.dm.Transaction} transaction
*/
ve.init.mw.ViewPageTarget.prototype.checkForWikitextWarning = function () {
var text, doc = this.surface.getView().getDocument(),
var text, node, doc = this.surface.getView().getDocument(),
selection = this.surface.getModel().getSelection(),
node = doc.getNodeFromOffset( selection.start ),
textMatches,
viewPageTarget = this;
if ( !selection ) {
return;
}
node = doc.getNodeFromOffset( selection.start );
if ( !( node instanceof ve.ce.ContentBranchNode ) ) {
return;
}

View file

@ -83,7 +83,8 @@ ve.ui.MWCitationDialog.prototype.getTransclusionNode = function () {
*/
ve.ui.MWCitationDialog.prototype.saveChanges = function () {
var item,
surfaceModel = this.getFragment().getSurface(),
surfaceFragment = this.getFragment(),
surfaceModel = surfaceFragment.getSurface(),
doc = surfaceModel.getDocument(),
internalList = doc.getInternalList(),
obj = this.transclusion.getPlainObject();
@ -92,7 +93,7 @@ ve.ui.MWCitationDialog.prototype.saveChanges = function () {
surfaceModel.getFragment().collapseRangeToEnd();
this.referenceModel = new ve.dm.MWReferenceModel();
this.referenceModel.insertInternalItem( surfaceModel );
this.referenceModel.insertReferenceNode( surfaceModel );
this.referenceModel.insertReferenceNode( surfaceFragment );
}
item = this.referenceModel.findInternalItem( surfaceModel );
@ -101,14 +102,13 @@ ve.ui.MWCitationDialog.prototype.saveChanges = function () {
this.transclusion.updateTransclusionNode( surfaceModel, this.transclusionNode );
} else if ( obj !== null ) {
this.transclusion.insertTransclusionNode(
surfaceModel,
// HACK: This is trying to place the cursor inside the first content branch node
// but this theoretically not a safe assumption - in practice, the citation dialog
// will only reach this code if we are inserting (not updating) a transclusion, so
// the referenceModel will have already initialized the internal node with a
// paragraph - getting the range of the item covers the entire paragraph so we have
// to get the range of it's first (and empty) child
item.getChildren()[0].getRange()
surfaceFragment.clone( item.getChildren()[0].getRange() )
);
}
}

View file

@ -323,7 +323,8 @@ ve.ui.MWReferenceDialog.prototype.setup = function ( data ) {
* @inheritdoc
*/
ve.ui.MWReferenceDialog.prototype.teardown = function ( data ) {
var surfaceModel = this.getFragment().getSurface();
var surfaceFragment = this.getFragment(),
surfaceModel = surfaceFragment.getSurface();
// Data initialization
data = data || {};
@ -336,7 +337,7 @@ ve.ui.MWReferenceDialog.prototype.teardown = function ( data ) {
if ( !this.referenceModel.findInternalItem( surfaceModel ) ) {
this.referenceModel.insertInternalItem( surfaceModel );
}
this.referenceModel.insertReferenceNode( surfaceModel );
this.referenceModel.insertReferenceNode( surfaceFragment );
}
// Update internal item
this.referenceModel.updateInternalItem( surfaceModel );

View file

@ -480,13 +480,14 @@ ve.ui.MWTransclusionDialog.prototype.getTransclusionNode = function () {
* Save changes.
*/
ve.ui.MWTransclusionDialog.prototype.saveChanges = function () {
var surfaceModel = this.getFragment().getSurface(),
var surfaceFragment = this.getFragment(),
surfaceModel = surfaceFragment.getSurface(),
obj = this.transclusion.getPlainObject();
if ( this.transclusionNode instanceof ve.dm.MWTransclusionNode ) {
this.transclusion.updateTransclusionNode( surfaceModel, this.transclusionNode );
} else if ( obj !== null ) {
this.transclusion.insertTransclusionNode( surfaceModel );
this.transclusion.insertTransclusionNode( surfaceFragment );
}
};