Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/core/src/editor/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,8 @@ For the ShowSelectionPlugin
background-color: highlight;
padding: 2px 0;
}

/* Hide trailing block when editor is not editable. */
.bn-editor[contenteditable="false"] .bn-trailing-block {
display: none;
}
36 changes: 36 additions & 0 deletions packages/core/src/extensions/TrailingNode/TrailingNode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Plugin, PluginKey } from "prosemirror-state";
import { Decoration, DecorationSet } from "prosemirror-view";
import { createExtension } from "../../editor/BlockNoteExtension.js";

// based on https://github.com/ueberdosis/tiptap/blob/40a9404c94c7fef7900610c195536384781ae101/demos/src/Experiments/TrailingNode/Vue/trailing-node.ts
Expand All @@ -19,6 +20,41 @@ export const TrailingNodeExtension = createExtension(() => {
prosemirrorPlugins: [
new Plugin({
key: plugin,
props: {
decorations: (state) => {
const { doc } = state;

const lastBlockGroup = doc.lastChild;
if (!lastBlockGroup || lastBlockGroup.type.name !== "blockGroup") {
return;
}

const lastBlockContainer = lastBlockGroup.lastChild;
if (
!lastBlockContainer ||
lastBlockContainer.type.name !== "blockContainer"
) {
return;
}

const lastBlockContent = lastBlockContainer.firstChild;
if (
!lastBlockContent ||
lastBlockContent.type.spec.content !== "inline*" ||
lastBlockContent.content.size > 0
) {
return;
}
Comment thread
matthewlipski marked this conversation as resolved.

const from = doc.content.size - 1 - lastBlockContainer.nodeSize;

return DecorationSet.create(doc, [
Decoration.node(from, from + lastBlockContainer.nodeSize, {
class: "bn-trailing-block",
}),
]);
},
},
appendTransaction: (_, __, state) => {
const { doc, tr, schema } = state;
const shouldInsertNodeAtEnd = plugin.getState(state);
Expand Down
Loading