From d4965fe4dbf1d6ee26eb59e298561ab6fda3cd15 Mon Sep 17 00:00:00 2001 From: raivaibhav Date: Mon, 18 Oct 2021 18:51:34 +0530 Subject: [PATCH] Fix: Regression on contenteditable Fixes: https://github.com/sveltejs/svelte/issues/5018 Fixes: https://github.com/sveltejs/svelte/issues/5931 Issue caused because of setting the updated value to the data property of moustache text node, use innerText if parent have contenteditable attribute --- src/runtime/internal/dev.ts | 10 +++++++--- src/runtime/internal/dom.ts | 8 +++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/runtime/internal/dev.ts b/src/runtime/internal/dev.ts index 76d68086c841..f8a0a313cabf 100644 --- a/src/runtime/internal/dev.ts +++ b/src/runtime/internal/dev.ts @@ -83,10 +83,14 @@ export function dataset_dev(node: HTMLElement, property: string, value?: any) { export function set_data_dev(text, data) { data = '' + data; - if (text.wholeText === data) return; + if (text.data === data) return; - dispatch_dev('SvelteDOMSetData', { node: text, data }); - text.data = data; + console.log(text.parentNode.hasAttribute('contenteditable')); + if (text.parentNode && text.parentNode.hasAttribute('contenteditable')) { + text.innerText = data; + } else { + text.data = data; + } } export function validate_each_argument(arg) { diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index eb3389e3f863..ac17c263e229 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -514,7 +514,13 @@ export function claim_html_tag(nodes) { export function set_data(text, data) { data = '' + data; - if (text.wholeText !== data) text.data = data; + if (text.data === data) return; + + if (text.parentNode && text.parentNode.hasAttribute('contenteditable')) { + text.innerText = data; + } else { + text.data = data; + } } export function set_input_value(input, value) {