From f4856a13c23051daa34a765841db7fb4692560ef Mon Sep 17 00:00:00 2001 From: Arek Nawo Date: Fri, 14 Jun 2024 14:51:14 +0200 Subject: [PATCH] fix: GPT extension --- .../src/lib/editor/extensions/block-action-menu/plugin.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/web/src/lib/editor/extensions/block-action-menu/plugin.tsx b/apps/web/src/lib/editor/extensions/block-action-menu/plugin.tsx index c2c926bd..82e38825 100644 --- a/apps/web/src/lib/editor/extensions/block-action-menu/plugin.tsx +++ b/apps/web/src/lib/editor/extensions/block-action-menu/plugin.tsx @@ -71,10 +71,10 @@ const repositionMenu = (editor: SolidEditor): void => { if (isTextSelection) { try { - const p = findParentAtDepth(selection.$from, selection.$from.depth - 1); + const p = findParentAtDepth(selection.$from, selection.$from.depth); - rangeFrom = p.start - 1; - rangeTo = p.start + p.node.nodeSize - 1; + rangeFrom = Math.max(p.start - 1, 0); + rangeTo = Math.min(p.start + p.node.nodeSize - 1, editor.state.doc.nodeSize - 2); } catch (error) { box.style.display = "none"; }