Skip to content

Commit

Permalink
Fix: Regression on contenteditable
Browse files Browse the repository at this point in the history
Fixes: sveltejs#5018
Fixes: sveltejs#5931

Issue caused because of setting the updated value to
the data property of moustache text node, use innerText if
parent have contenteditable attribute
  • Loading branch information
RaiVaibhav committed Oct 18, 2021
1 parent 883c47b commit d4965fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/runtime/internal/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion src/runtime/internal/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d4965fe

Please sign in to comment.