Jforrester has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/360907 )
Change subject: Ensure MWInlineImages get the ve-ce-leafNode class ...................................................................... Ensure MWInlineImages get the ve-ce-leafNode class Without this class, offset calculations fail and model/view sync can be lost. Bug: T167009 Change-Id: Ie7b6551ac5a532949c14122b9ee7584a794af0f2 --- M VisualEditor.hooks.php M modules/ve-mw/ce/nodes/ve.ce.MWInlineImageNode.js M modules/ve-mw/tests/ce/ve.ce.ContentBranchNode.test.js A modules/ve-mw/tests/ce/ve.ce.Document.test.js M modules/ve-mw/tests/ce/ve.ce.Surface.test.js M modules/ve-mw/tests/dm/ve.dm.mwExample.js 6 files changed, 51 insertions(+), 11 deletions(-) Approvals: Divec: Looks good to me, approved Jforrester: Verified; Looks good to me, but someone else must approve diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php index 68b7622..620728d 100644 --- a/VisualEditor.hooks.php +++ b/VisualEditor.hooks.php @@ -926,6 +926,7 @@ // VisualEditor ContentEditable Tests 'lib/ve/tests/ce/ve.ce.test.js', 'lib/ve/tests/ce/ve.ce.Document.test.js', + 'modules/ve-mw/tests/ce/ve.ce.Document.test.js', 'lib/ve/tests/ce/ve.ce.Surface.test.js', 'modules/ve-mw/tests/ce/ve.ce.Surface.test.js', 'lib/ve/tests/ce/ve.ce.RangeState.test.js', diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWInlineImageNode.js b/modules/ve-mw/ce/nodes/ve.ce.MWInlineImageNode.js index c7314e6..a258af9 100644 --- a/modules/ve-mw/ce/nodes/ve.ce.MWInlineImageNode.js +++ b/modules/ve-mw/ce/nodes/ve.ce.MWInlineImageNode.js @@ -16,20 +16,16 @@ * @param {ve.dm.MWInlineImageNode} model Model to observe * @param {Object} [config] Configuration options */ -ve.ce.MWInlineImageNode = function VeCeMWInlineImageNode() { - var isError, $image; - // Parent constructor - ve.ce.MWInlineImageNode.super.apply( this, arguments ); +ve.ce.MWInlineImageNode = function VeCeMWInlineImageNode( model, config ) { + var $image; - isError = this.model.getAttribute( 'isError' ); - - if ( isError ) { + if ( model.getAttribute( 'isError' ) ) { this.$element = $( '<a>' ) .addClass( 'new' ) - .text( this.model.getFilename() ); + .text( model.getFilename() ); $image = $( [] ); } else { - if ( this.model.getAttribute( 'isLinked' ) ) { + if ( model.getAttribute( 'isLinked' ) ) { this.$element = $( '<a>' ).addClass( 'image' ); $image = $( '<img>' ).appendTo( this.$element ); } else { @@ -37,6 +33,11 @@ } } + // Parent constructor + // this.$element has already been created and styled, so pass through as config.$element + // The constructor will add more classes to this.$element, such as ve-ce-leafNode + ve.ce.MWInlineImageNode.super.call( this, model, ve.extendObject( {}, config, { $element: this.$element } ) ); + // Mixin constructors ve.ce.MWImageNode.call( this, this.$element, $image ); diff --git a/modules/ve-mw/tests/ce/ve.ce.ContentBranchNode.test.js b/modules/ve-mw/tests/ce/ve.ce.ContentBranchNode.test.js index c02dcbc..1f328fc 100644 --- a/modules/ve-mw/tests/ce/ve.ce.ContentBranchNode.test.js +++ b/modules/ve-mw/tests/ce/ve.ce.ContentBranchNode.test.js @@ -1,5 +1,5 @@ /*! - * VisualEditor ContentEditable MediaWiki-specific ContentBranchNode tests. + * VisualEditor MediaWiki-specific ContentEditable ContentBranchNode tests. * * @copyright 2011-2017 VisualEditor Team and others; see AUTHORS.txt * @license The MIT License (MIT); see LICENSE.txt diff --git a/modules/ve-mw/tests/ce/ve.ce.Document.test.js b/modules/ve-mw/tests/ce/ve.ce.Document.test.js new file mode 100644 index 0000000..f4224dc --- /dev/null +++ b/modules/ve-mw/tests/ce/ve.ce.Document.test.js @@ -0,0 +1,31 @@ +/*! + * VisualEditor MediaWiki-specific ContentEditable Document tests. + * + * @copyright 2011-2017 VisualEditor Team and others; see http://ve.mit-license.org + */ + +QUnit.module( 've.ce.Document (MW)' ); + +/* Tests */ + +QUnit.test( 'Converter tests', function ( assert ) { + var msg, model, view, caseItem, $documentElement, + cases = ve.dm.mwExample.domToDataCases; + + for ( msg in cases ) { + if ( cases[ msg ].ceHtml ) { + caseItem = ve.copy( cases[ msg ] ); + model = ve.test.utils.getModelFromTestCase( caseItem ); + view = new ve.ce.Document( model ); + $documentElement = view.getDocumentNode().$element; + // Simplify slugs + $documentElement.find( '.ve-ce-branchNode-slug' ).contents().remove(); + assert.equalDomElement( + // Wrap both in plain DIVs as we are only comparing the child nodes + $( '<div>' ).append( $documentElement.contents() )[ 0 ], + $( '<div>' ).append( ve.createDocumentFromHtml( caseItem.ceHtml ).body.childNodes )[ 0 ], + msg + ); + } + } +} ); diff --git a/modules/ve-mw/tests/ce/ve.ce.Surface.test.js b/modules/ve-mw/tests/ce/ve.ce.Surface.test.js index 0d67b82..5e4ffa7 100644 --- a/modules/ve-mw/tests/ce/ve.ce.Surface.test.js +++ b/modules/ve-mw/tests/ce/ve.ce.Surface.test.js @@ -1,5 +1,5 @@ /*! - * VisualEditor ContentEditable MediaWiki-specific Surface tests. + * VisualEditor MediaWiki-specific ContentEditable Surface tests. * * @copyright 2011-2017 VisualEditor Team and others; see AUTHORS.txt * @license The MIT License (MIT); see LICENSE.txt diff --git a/modules/ve-mw/tests/dm/ve.dm.mwExample.js b/modules/ve-mw/tests/dm/ve.dm.mwExample.js index 2617121..d088f8c 100644 --- a/modules/ve-mw/tests/dm/ve.dm.mwExample.js +++ b/modules/ve-mw/tests/dm/ve.dm.mwExample.js @@ -650,6 +650,13 @@ { type: 'internalList' }, { type: '/internalList' } ], + ceHtml: '<p class="ve-ce-branchNode ve-ce-contentBranchNode ve-ce-paragraphNode">' + + '<span class="ve-ce-branchNode-slug ve-ce-branchNode-inlineSlug"></span>' + + '<a class="image ve-ce-leafNode ve-ce-focusableNode ve-ce-mwInlineImageNode" contenteditable="false">' + + '<img src="http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png" width="135" height="155" style="vertical-align: text-top;">' + + '</a>' + + ve.dm.example.inlineSlug + + '</p>', storeItems: ve.dm.mwExample.MWInlineImage.storeItems }, 'mwHeading and mwPreformatted nodes': { -- To view, visit https://gerrit.wikimedia.org/r/360907 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ie7b6551ac5a532949c14122b9ee7584a794af0f2 Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> Gerrit-Reviewer: DLynch <dly...@wikimedia.org> Gerrit-Reviewer: Deskana <dga...@wikimedia.org> Gerrit-Reviewer: Divec <da...@troi.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