From 0b6bac7fd2fa5bc96062aa75acdf3b71d7d5f259 Mon Sep 17 00:00:00 2001 From: Wayne Mather Date: Mon, 29 Jan 2024 11:04:00 +1000 Subject: [PATCH 1/3] #5650 - Fix inserting component using text from the view rather than the model --- src/dom_components/view/ComponentTextView.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dom_components/view/ComponentTextView.ts b/src/dom_components/view/ComponentTextView.ts index b0b379c352..cb732321b0 100644 --- a/src/dom_components/view/ComponentTextView.ts +++ b/src/dom_components/view/ComponentTextView.ts @@ -182,13 +182,13 @@ export default class ComponentTextView extends ComponentView { const offset = range.startOffset; const textModel = getComponentModel(textNode); const newCmps: (ComponentDefinition | Component)[] = []; - + let 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; + const cnt = (data = '' ? cmp.content : data); newCmps.push({ type, content: cnt.slice(0, offset) }); newCmps.push(content); newCmps.push({ type, content: cnt.slice(offset) }); From 2a952a71b6df53715aba7000161b132f2a9b1779 Mon Sep 17 00:00:00 2001 From: Wayne Mather Date: Thu, 1 Feb 2024 06:03:20 +1000 Subject: [PATCH 2/3] #5650 - Updated code to be better based on PR feedback --- src/dom_components/view/ComponentTextView.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dom_components/view/ComponentTextView.ts b/src/dom_components/view/ComponentTextView.ts index cb732321b0..7465638ba1 100644 --- a/src/dom_components/view/ComponentTextView.ts +++ b/src/dom_components/view/ComponentTextView.ts @@ -182,13 +182,13 @@ export default class ComponentTextView extends ComponentView { const offset = range.startOffset; const textModel = getComponentModel(textNode); const newCmps: (ComponentDefinition | Component)[] = []; - let data = textNode.textContent ?? ''; + const data = textNode.textContent || ''; if (textModel && textModel.is?.('textnode')) { const cmps = textModel.collection; cmps.forEach(cmp => { if (cmp === textModel) { const type = 'textnode'; - const cnt = (data = '' ? cmp.content : data); + const cnt = data || cmp.content; newCmps.push({ type, content: cnt.slice(0, offset) }); newCmps.push(content); newCmps.push({ type, content: cnt.slice(offset) }); From 0368806e43da7ff8dbaa87b991e6261291166a81 Mon Sep 17 00:00:00 2001 From: Wayne Mather Date: Wed, 14 Feb 2024 06:33:57 +1000 Subject: [PATCH 3/3] #5650 - Made the content replacement controlled by property on the options object --- src/dom_components/view/ComponentTextView.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/dom_components/view/ComponentTextView.ts b/src/dom_components/view/ComponentTextView.ts index 7465638ba1..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(); @@ -188,7 +188,10 @@ export default class ComponentTextView extends ComponentView { cmps.forEach(cmp => { if (cmp === textModel) { const type = 'textnode'; - const cnt = data || 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) });