editor: fix paragraph not inserted at the end of some nodes

This commit is contained in:
Ammar Ahmed
2024-09-23 17:43:35 +05:00
parent 8d25d03390
commit bdb0474645

View File

@@ -390,24 +390,28 @@ const Tiptap = ({
);
const onClickBottomArea = useCallback(() => {
const editor = editors[tab.id];
const docSize = editor?.state.doc.content.size;
if (!docSize) return;
const lastChild = editor?.state.doc.lastChild;
const isParagraph = lastChild?.type.name === "paragraph";
const isLastChildEmpty =
!lastChild?.textContent || lastChild?.textContent?.length === 0;
if (isParagraph && isLastChildEmpty) {
editor?.commands.focus("end");
return;
try {
const editor = editors[tab.id];
const docSize = editor?.state.doc.content.size;
if (!docSize) return;
const lastChild = editor?.state.doc.lastChild;
const isParagraph = lastChild?.type.name === "paragraph";
const isLastChildEmpty =
!lastChild?.textContent || lastChild?.textContent?.length === 0;
if (isParagraph && isLastChildEmpty) {
editor?.commands.focus("end");
return;
}
editor
?.chain()
.insertContentAt(docSize, "<p></p>", {
updateSelection: true
})
.focus("end")
.run();
} catch (e) {
console.log(e);
}
editor
?.chain()
.insertContentAt(docSize - 1, "<p></p>", {
updateSelection: true
})
.focus("end")
.run();
}, [tab.id]);
return (