diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js index d30d197e88..b7d8cb5136 100644 --- a/modules/ve/ce/ve.ce.Surface.js +++ b/modules/ve/ce/ve.ce.Surface.js @@ -701,9 +701,7 @@ ve.ce.Surface.prototype.onCopy = function ( e ) { // Clone the elements in the slice slice.data.cloneElements(); - ve.dm.converter.store = slice.getStore(); - ve.dm.converter.internalList = slice.getInternalList(); - ve.dm.converter.getDomSubtreeFromData( slice.getData(), this.$pasteTarget[0] ); + ve.dm.converter.getDomSubtreeFromModel( slice, this.$pasteTarget[0] ); // Some browsers strip out spans when they match the styling of the // paste target (e.g. plain spans) so we must protect against this @@ -842,9 +840,13 @@ ve.ce.Surface.prototype.beforePaste = function ( e ) { } context.push( { 'type': '/' + context[0].type } ); - ve.dm.converter.store = doc.getStore(); - ve.dm.converter.internalList = doc.getInternalList(); - ve.dm.converter.getDomSubtreeFromData( context, this.$pasteTarget[0] ); + ve.dm.converter.getDomSubtreeFromModel( + new ve.dm.Document( + new ve.dm.ElementLinearData( doc.getStore(), context ), + doc.getHtmlDocument(), undefined, doc.getInternalList() + ), + this.$pasteTarget[0] + ); // Giving the paste target focus too late can cause problems in FF (!?) // so do it up here. diff --git a/modules/ve/dm/ve.dm.Converter.js b/modules/ve/dm/ve.dm.Converter.js index 6f8839b3f3..9a5c222b22 100644 --- a/modules/ve/dm/ve.dm.Converter.js +++ b/modules/ve/dm/ve.dm.Converter.js @@ -1072,19 +1072,30 @@ ve.dm.Converter.prototype.isDomAllMetaOrWhitespace = function ( domElements, exc ve.dm.Converter.prototype.getDomFromModel = function ( model ) { var doc = ve.createDocumentFromHtml( '' ); + this.getDomSubtreeFromModel( model, doc.body ); + + return doc; +}; + +/** + * Convert document model to an HTML DOM subtree and add it to a container element. + * + * @method + * @param {ve.dm.Document} model Document model + * @param {HTMLElement} container DOM element to add the generated elements to. Should be empty. + */ +ve.dm.Converter.prototype.getDomSubtreeFromModel = function ( model, container ) { // Set up the converter state this.documentData = model.getFullData(); this.store = model.getStore(); this.internalList = model.getInternalList(); - this.getDomSubtreeFromData( this.documentData, doc.body, model.getInnerWhitespace() ); + this.getDomSubtreeFromData( this.documentData, container, model.getInnerWhitespace() ); // Clear the state this.documentData = null; this.store = null; this.internalList = null; - - return doc; }; /**