mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-12 09:09:25 +00:00
Merge "Create wrapper paragraph when converting block image to inline"
This commit is contained in:
commit
b73deb1690
|
@ -438,7 +438,7 @@ ve.dm.MWImageModel.prototype.updateImageNode = function ( node, surfaceModel ) {
|
|||
* @throws {Error} Unknown image node type
|
||||
*/
|
||||
ve.dm.MWImageModel.prototype.insertImageNode = function ( fragment ) {
|
||||
var captionDoc, offset, contentToInsert,
|
||||
var captionDoc, offset, contentToInsert, selectedNode,
|
||||
nodeType = this.getImageNodeType(),
|
||||
surfaceModel = fragment.getSurface();
|
||||
|
||||
|
@ -446,12 +446,26 @@ ve.dm.MWImageModel.prototype.insertImageNode = function ( fragment ) {
|
|||
return fragment;
|
||||
}
|
||||
|
||||
selectedNode = fragment.getSelectedNode();
|
||||
|
||||
// If there was a previous node, remove it first
|
||||
if ( selectedNode ) {
|
||||
// Remove the old image
|
||||
fragment.removeContent();
|
||||
}
|
||||
|
||||
contentToInsert = this.getData();
|
||||
|
||||
switch ( nodeType ) {
|
||||
case 'mwInlineImage':
|
||||
// Try to put the image inside the nearest content node
|
||||
offset = fragment.getDocument().data.getNearestContentOffset( fragment.getSelection().getRange().start );
|
||||
if ( selectedNode.type === 'mwBlockImage' ) {
|
||||
// If converting from a block image, create a wrapper paragraph for the inline image to go in.
|
||||
fragment.insertContent( [ { type: 'paragraph', internal: { generated: 'wrapper' } }, { type: '/paragraph' } ] );
|
||||
offset = fragment.getSelection().getRange().start + 1;
|
||||
} else {
|
||||
// Try to put the image inside the nearest content node
|
||||
offset = fragment.getDocument().data.getNearestContentOffset( fragment.getSelection().getRange().start );
|
||||
}
|
||||
if ( offset > -1 ) {
|
||||
fragment = fragment.clone( new ve.dm.LinearSelection( fragment.getDocument(), new ve.Range( offset ) ) );
|
||||
}
|
||||
|
|
|
@ -1386,16 +1386,6 @@ ve.ui.MWMediaDialog.prototype.getActionProcess = function ( action ) {
|
|||
this.imageModel.updateImageNode( this.selectedNode, surfaceModel );
|
||||
} else {
|
||||
// Replacing an image or inserting a brand new one
|
||||
|
||||
// If there was a previous node, remove it first
|
||||
if ( this.selectedNode ) {
|
||||
// Remove the old image
|
||||
this.fragment = this.getFragment().clone(
|
||||
new ve.dm.LinearSelection( this.fragment.getDocument(), this.selectedNode.getOuterRange() )
|
||||
);
|
||||
this.fragment.removeContent();
|
||||
}
|
||||
// Insert the new image
|
||||
this.fragment = this.imageModel.insertImageNode( this.getFragment() );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue