jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/373557 )
Change subject: Create wrapper paragraph when converting block image to inline ...................................................................... Create wrapper paragraph when converting block image to inline This prevents the image jumping into another paragraph, e.g. in a different table cell. Move the logic for removing the old image out of MWMediaDialog and into MWImageModel#insertImageNode. Bug: T121449 Change-Id: Ibd7c92f3f90c382ceffd3e0defb12ba36a3786d2 --- M modules/ve-mw/dm/models/ve.dm.MWImageModel.js M modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js 2 files changed, 17 insertions(+), 13 deletions(-) Approvals: jenkins-bot: Verified Jforrester: Looks good to me, approved diff --git a/modules/ve-mw/dm/models/ve.dm.MWImageModel.js b/modules/ve-mw/dm/models/ve.dm.MWImageModel.js index e7c0e9f..cdcf1a6 100644 --- a/modules/ve-mw/dm/models/ve.dm.MWImageModel.js +++ b/modules/ve-mw/dm/models/ve.dm.MWImageModel.js @@ -438,7 +438,7 @@ * @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 @@ 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 ) ) ); } diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js index 36ca56d..0f15028 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js @@ -1393,16 +1393,6 @@ 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() ); } -- To view, visit https://gerrit.wikimedia.org/r/373557 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ibd7c92f3f90c382ceffd3e0defb12ba36a3786d2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> Gerrit-Reviewer: DLynch <dly...@wikimedia.org> Gerrit-Reviewer: Esanders <esand...@wikimedia.org> Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits