From ddacdd3083b84b3ee2fceea4302d129f7f24f366 Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Mon, 25 Sep 2023 15:47:56 +0300 Subject: [PATCH] overlay position --- .../src/AiService/components/AskAIOverlay.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/wax-prosemirror-services/src/AiService/components/AskAIOverlay.js b/wax-prosemirror-services/src/AiService/components/AskAIOverlay.js index 3d90d5466..1d17d47a9 100644 --- a/wax-prosemirror-services/src/AiService/components/AskAIOverlay.js +++ b/wax-prosemirror-services/src/AiService/components/AskAIOverlay.js @@ -112,14 +112,18 @@ const AskAIOverlay = ({ setPosition, position, config }) => { const WaxSurface = activeView.dom.getBoundingClientRect(); const { selection } = activeView.state; const { to } = selection; - const end = activeView.coordsAtPos(to); - // const overLayComponent = document.getElementById('ai-overlay'); - // let overLayComponentCoords; - // if (overLayComponent) - // overLayComponentCoords = overLayComponent.getBoundingClientRect(); + const end = activeView.coordsAtPos(to - 1); + const overLayComponent = document.getElementById('ai-overlay'); + + const overLayComponentCoords = overLayComponent.getBoundingClientRect(); const top = end.top - WaxSurface.top + 20; - // const left = end.left - WaxSurface.left - overLayComponentCoords.width / 2; - const left = end.left - WaxSurface.left - 50; + let left = end.left - WaxSurface.left; + + // Don't get out of right boundary of the surface + if (end.left + overLayComponentCoords.width > WaxSurface.right) { + left -= end.left + overLayComponentCoords.width - WaxSurface.right; + } + setPosition({ ...position, left, top }); }, [position.left]); -- GitLab