From 9ee52e62cbebcab626504ddd6076195eb29d626d Mon Sep 17 00:00:00 2001 From: Wayne Mather Date: Tue, 20 Feb 2024 07:41:46 +1000 Subject: [PATCH] Bugfix/5650 inserting text uses model data not current view (#5651) * #5650 - Fix inserting component using text from the view rather than the model * #5650 - Updated code to be better based on PR feedback * #5650 - Made the content replacement controlled by property on the options object --------- Co-authored-by: Wayne Mather --- src/dom_components/view/ComponentTextView.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/dom_components/view/ComponentTextView.ts b/src/dom_components/view/ComponentTextView.ts index b0b379c352..22627cfa3a 100644 --- a/src/dom_components/view/ComponentTextView.ts +++ b/src/dom_components/view/ComponentTextView.ts @@ -171,7 +171,7 @@ export default class ComponentTextView extends ComponentView { } } - insertComponent(content: ComponentDefinition, opts = {}) { + insertComponent(content: ComponentDefinition, opts: any = {}) { const { model, el } = this; const doc = el.ownerDocument; const selection = doc.getSelection(); @@ -182,13 +182,16 @@ export default class ComponentTextView extends ComponentView { const offset = range.startOffset; const textModel = getComponentModel(textNode); const newCmps: (ComponentDefinition | Component)[] = []; - + const data = textNode.textContent || ''; if (textModel && textModel.is?.('textnode')) { const cmps = textModel.collection; cmps.forEach(cmp => { if (cmp === textModel) { const type = 'textnode'; - const cnt = cmp.content; + let cnt = cmp.content; + if ('useDomContent' in opts && opts.useDomContent) { + cnt = data || cmp.content; + } newCmps.push({ type, content: cnt.slice(0, offset) }); newCmps.push(content); newCmps.push({ type, content: cnt.slice(offset) });