From e7a8ade63482c716e74e2075f726b29cba5ae8cc Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sat, 6 Jun 2026 09:16:39 +0100 Subject: [PATCH] refac --- .../src/lib/components/chat/ChatInput.svelte | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/cptr/frontend/src/lib/components/chat/ChatInput.svelte b/cptr/frontend/src/lib/components/chat/ChatInput.svelte index 4c510dd..9c4d41b 100644 --- a/cptr/frontend/src/lib/components/chat/ChatInput.svelte +++ b/cptr/frontend/src/lib/components/chat/ChatInput.svelte @@ -60,6 +60,8 @@ // ── @file mention suggestion ──────────────────── let popupEl: HTMLDivElement | null = null; let popupComponent: Record | null = null; + let activeClientRectFn: (() => DOMRect | null) | null = null; + let repositionRafId: number | null = null; async function fetchSuggestions({ query }: { query: string }): Promise { if (!workspace) return []; @@ -92,6 +94,24 @@ }); } + function startRepositionLoop() { + stopRepositionLoop(); + function tick() { + if (activeClientRectFn) { + updatePopupPosition(activeClientRectFn()); + repositionRafId = requestAnimationFrame(tick); + } + } + repositionRafId = requestAnimationFrame(tick); + } + + function stopRepositionLoop() { + if (repositionRafId !== null) { + cancelAnimationFrame(repositionRafId); + repositionRafId = null; + } + } + function createSuggestionRenderer() { let selectedIndex = 0; let currentItems: FileMentionAttrs[] = []; @@ -111,13 +131,16 @@ command = props.command; currentItems = props.items; selectedIndex = 0; + activeClientRectFn = props.clientRect ?? null; remount(); updatePopupPosition(props.clientRect?.()); + startRepositionLoop(); }, onUpdate(props: any) { command = props.command; currentItems = props.items; selectedIndex = 0; + activeClientRectFn = props.clientRect ?? null; remount(); updatePopupPosition(props.clientRect?.()); }, @@ -160,6 +183,8 @@ } function destroyPopup() { + stopRepositionLoop(); + activeClientRectFn = null; if (popupComponent) { try { unmount(popupComponent); } catch {} popupComponent = null;