import type { Editor } from '@tiptap/react' // Drops the empty paragraph `appendTrailingParagraph` left at the end when the phone focus view // closes without anything typed into it, so opening the view never adds a blank line to the value. export function removeTrailingEmptyParagraph(editor: Editor): void { const { state, view } = editor const lastBlock = state.doc.lastChild if (state.doc.childCount < 2 || !lastBlock) return if (lastBlock.type !== state.schema.nodes.paragraph || lastBlock.content.size > 0) return const end = state.doc.content.size view.dispatch(state.tr.delete(end - lastBlock.nodeSize, end)) }