Skip to content

armgit / plane

Public Imported from GitHub
0

πŸ”₯πŸ”₯πŸ”₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.

[WIKI-306] fix: handle editor click behavior on the last node #6879

Vipin Chaudhary2b411de1e3ed
diff --git a/packages/editor/src/core/components/editors/editor-container.tsx b/packages/editor/src/core/components/editors/editor-container.tsx
index 2dfc6425bc..d0811cd410 100644
--- a/packages/editor/src/core/components/editors/editor-container.tsx
+++ b/packages/editor/src/core/components/editors/editor-container.tsx
@@ -47,15 +47,23 @@ export const EditorContainer: FC<EditorContainerProps> = (props) => {
return;
}
- // Insert a new paragraph at the end of the document
- const endPosition = editor?.state.doc.content.size;
- editor?.chain().insertContentAt(endPosition, { type: "paragraph" }).run();
+ // Get the last node in the document
+ const docSize = editor.state.doc.content.size;
+ const lastNodePos = editor.state.doc.resolve(Math.max(0, docSize - 2));
+ const lastNode = lastNodePos.node();
- // Focus the newly added paragraph for immediate editing
- editor
- .chain()
- .setTextSelection(endPosition + 1)
- .run();
+ // Check if the last node is a not paragraph
+ if (lastNode && lastNode.type.name !== "paragraph") {
+ // If last node is not a paragraph, insert a new paragraph at the end
+ const endPosition = editor?.state.doc.content.size;
+ editor?.chain().insertContentAt(endPosition, { type: "paragraph" }).run();
+
+ // Focus the newly added paragraph for immediate editing
+ editor
+ .chain()
+ .setTextSelection(endPosition + 1)
+ .run();
+ }
} catch (error) {
console.error("An error occurred while handling container click to insert new empty node at bottom:", error);
}