From 7ed2e96db492a2d3a1d7bd8fc47574d7b6c3c327 Mon Sep 17 00:00:00 2001 From: Vincent Chan Date: Wed, 6 Dec 2023 13:10:03 +0800 Subject: [PATCH] fix: delete cursor error --- packages/blocky-core/src/view/controller.ts | 17 ++++++++++++++--- .../defaultSpannerMenu/defaultSpannerMenu.tsx | 3 ++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/blocky-core/src/view/controller.ts b/packages/blocky-core/src/view/controller.ts index c8f3ce4..8acf588 100644 --- a/packages/blocky-core/src/view/controller.ts +++ b/packages/blocky-core/src/view/controller.ts @@ -410,14 +410,25 @@ export class EditorController { if (!blockNode) { return; } + const { nextSibling, prevSibling } = blockNode; if (!isUpperCase(blockNode.t)) { return; } - new Changeset(this.state).removeNode(blockNode).apply({ - refreshCursor: true, - }); + let nextCusorState: CursorState | null = null; + if (nextSibling instanceof BlockDataElement) { + nextCusorState = CursorState.collapse(nextSibling.id, 0); + } else if (prevSibling instanceof BlockDataElement) { + nextCusorState = CursorState.collapse(prevSibling.id, 0); + } + + new Changeset(this.state) + .removeNode(blockNode) + .setCursorState(nextCusorState) + .apply({ + refreshCursor: true, + }); } /** diff --git a/packages/blocky-react/src/defaultSpannerMenu/defaultSpannerMenu.tsx b/packages/blocky-react/src/defaultSpannerMenu/defaultSpannerMenu.tsx index 5fb9a26..bba7e9b 100644 --- a/packages/blocky-react/src/defaultSpannerMenu/defaultSpannerMenu.tsx +++ b/packages/blocky-react/src/defaultSpannerMenu/defaultSpannerMenu.tsx @@ -139,9 +139,10 @@ function DefaultSpannerMenu(props: SpannerProps) { const renderMenu = () => { return ( - {commands.map((command) => { + {commands.map((command, index) => { return ( { if (!isUndefined(command.insertText)) {