diff --git a/packages/core/src/api/nodeConversions/nodeToBlock.ts b/packages/core/src/api/nodeConversions/nodeToBlock.ts index 9e1c95238..671121a60 100644 --- a/packages/core/src/api/nodeConversions/nodeToBlock.ts +++ b/packages/core/src/api/nodeConversions/nodeToBlock.ts @@ -82,6 +82,7 @@ export function contentNodeToTableContent< // Only merge if the last and first content are both styled text nodes and have the same styles if ( + first && isStyledTextInlineContent(last) && isStyledTextInlineContent(first) && JSON.stringify(last.styles) === JSON.stringify(first.styles) diff --git a/packages/core/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts b/packages/core/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts index fb6fbad7e..cecaaeabd 100644 --- a/packages/core/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +++ b/packages/core/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts @@ -20,11 +20,15 @@ function setSelectionToNextContentEditableBlock< I extends InlineContentSchema, S extends StyleSchema >(editor: BlockNoteEditor) { - let block = editor.getTextCursorPosition().block; + let block: Block | undefined = + editor.getTextCursorPosition().block; let contentType = editor.schema.blockSchema[block.type].content; while (contentType === "none") { - block = editor.getTextCursorPosition().nextBlock!; + block = editor.getTextCursorPosition().nextBlock; + if (block === undefined) { + return; + } contentType = editor.schema.blockSchema[block.type].content as | "inline" | "table" diff --git a/packages/core/src/extensions/TableHandles/TableHandlesPlugin.ts b/packages/core/src/extensions/TableHandles/TableHandlesPlugin.ts index 87a15fb6d..b49b175dd 100644 --- a/packages/core/src/extensions/TableHandles/TableHandlesPlugin.ts +++ b/packages/core/src/extensions/TableHandles/TableHandlesPlugin.ts @@ -656,32 +656,27 @@ export class TableHandlesProsemirrorPlugin< } const decorations: Decoration[] = []; - - if (newIndex === this.view.state.draggingState.originalIndex) { - return DecorationSet.create(state.doc, decorations); - } else if ( - this.view.state.draggingState.draggedCellOrientation === "row" && - !canRowBeDraggedInto( - this.view.state.block, - this.view.state.draggingState.originalIndex, - newIndex - ) - ) { - return DecorationSet.create(state.doc, decorations); - } else if ( - this.view.state.draggingState.draggedCellOrientation === "col" && - !canColumnBeDraggedInto( - this.view.state.block, - this.view.state.draggingState.originalIndex, - newIndex - ) + const { block, draggingState } = this.view.state; + const { originalIndex, draggedCellOrientation } = draggingState; + + // Return empty decorations if: + // - Dragging to same position + // - No block exists + // - Row drag not allowed + // - Column drag not allowed + if ( + newIndex === originalIndex || + !block || + (draggedCellOrientation === "row" && + !canRowBeDraggedInto(block, originalIndex, newIndex)) || + (draggedCellOrientation === "col" && + !canColumnBeDraggedInto(block, originalIndex, newIndex)) ) { return DecorationSet.create(state.doc, decorations); } // Gets the table to show the drop cursor in. const tableResolvedPos = state.doc.resolve(this.view.tablePos + 1); - const originalIndex = this.view.state.draggingState.originalIndex; if (this.view.state.draggingState.draggedCellOrientation === "row") { const cellsInRow = getCellsAtRowHandle(