Skip to content

Commit 03a938d

Browse files
committed
fix(web): allow for content removal when text=''
1 parent 2e418a5 commit 03a938d

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

src/web/utils/insertValue.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,27 @@ export function insertValue(
2020
end: number,
2121
useHtmlNormalizer: boolean | undefined
2222
): void {
23-
if (!value) return;
24-
2523
const doc = editor.state.doc;
2624
const docLength = nativeLeafText(doc, 0, doc.content.size).length;
2725

28-
if (docLength === 0 && isPlainEmptyDoc(doc)) {
29-
editor.commands.setContent(prepareHtmlForTiptap(value, useHtmlNormalizer));
30-
return;
31-
}
32-
3326
const from = nativePosToTiptapPos(doc, Math.min(start, docLength));
3427
const to = nativePosToTiptapPos(
3528
doc,
3629
Math.min(Math.max(start, end), docLength)
3730
);
31+
32+
if (!value) {
33+
if (start === end) return;
34+
35+
editor.chain().focus().deleteRange({ from, to }).run();
36+
return;
37+
}
38+
39+
if (docLength === 0 && isPlainEmptyDoc(doc)) {
40+
editor.commands.setContent(prepareHtmlForTiptap(value, useHtmlNormalizer));
41+
return;
42+
}
43+
3844
const content = prepareHtmlForTiptap(value, useHtmlNormalizer);
3945

4046
const parsedRaw = createNodeFromContent(content, editor.schema, {

0 commit comments

Comments
 (0)