diff --git a/src/components/richEditorTransformErrorRecoveryExtension.test.ts b/src/components/richEditorTransformErrorRecoveryExtension.test.ts index 19b6cc5d..177cb0b5 100644 --- a/src/components/richEditorTransformErrorRecoveryExtension.test.ts +++ b/src/components/richEditorTransformErrorRecoveryExtension.test.ts @@ -139,6 +139,13 @@ describe('installRichEditorTransformErrorRecovery', () => { ) }) + it('repairs invalid table-cell joins while editing table contents', () => { + expectDocumentRepairRecovery( + transformError('Cannot join tableCell onto blockContainer'), + 'invalid_block_join', + ) + }) + it('recovers invalid block joins thrown during keydown handling before dispatch', () => { const { view, keyDownPlugin } = createViewWithSomeProp(() => { throw transformError('Cannot join blockGroup onto blockContainer') @@ -155,6 +162,22 @@ describe('installRichEditorTransformErrorRecovery', () => { }) }) + it('recovers invalid table-cell joins thrown during keydown handling', () => { + const { view, keyDownPlugin } = createViewWithSomeProp(() => { + throw transformError('Cannot join tableCell onto blockContainer') + }) + const recoverDocument = vi.fn() + + installRichEditorTransformErrorRecovery(view, { recoverDocument }) + + expect(view.someProp('handleKeyDown', (handler) => handler())).toBe(true) + expect(keyDownPlugin).toHaveBeenCalledTimes(1) + expect(recoverDocument).toHaveBeenCalledTimes(1) + expect(trackEvent).toHaveBeenCalledWith('rich_editor_transform_error_recovered', { + reason: 'invalid_block_join', + }) + }) + it('keeps unrelated keydown handler failures visible', () => { const { view } = createViewWithSomeProp(() => { throw new Error('keyboard plugin failed') diff --git a/src/components/richEditorTransformErrorRecoveryExtension.ts b/src/components/richEditorTransformErrorRecoveryExtension.ts index 14fadd42..0dc04f9c 100644 --- a/src/components/richEditorTransformErrorRecoveryExtension.ts +++ b/src/components/richEditorTransformErrorRecoveryExtension.ts @@ -92,7 +92,7 @@ function isTablePositionOutOfRangeError(error: unknown): boolean { } function isInvalidBlockJoinError(error: unknown): boolean { - return isTransformError(error) && error.message === 'Cannot join blockGroup onto blockContainer' + return isTransformError(error) && /^Cannot join (blockGroup|tableCell) onto blockContainer$/.test(error.message) } export function isStaleBlockReferenceError(error: unknown): boolean {