From f4e79276f0eda692be89ff67944aac785583f0fc Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sat, 14 Mar 2026 00:13:48 +0100 Subject: [PATCH] Refactor state management in App.tsx --- src/App.tsx | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index b79db5e..2077b25 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -460,7 +460,9 @@ export default function App() { const [selectedHistoryId, setSelectedHistoryId] = useState(null); const [confirmState, setConfirmState] = useState(null); const [settingsOpen, setSettingsOpen] = useState(false); - const [customPromptOpen, setCustomPromptOpen] = useState(false); + const [pendingAiScopeChoice, setPendingAiScopeChoice] = + useState(null); + const [customPromptState, setCustomPromptState] = useState(null); const [customPromptText, setCustomPromptText] = useState(""); const [dbExporting, setDbExporting] = useState(false); const [dbExportStatus, setDbExportStatus] = useState(null); @@ -900,9 +902,27 @@ export default function App() { setExpandedPromptId((current) => (current === templateId ? null : current)); }, []); + const getCurrentAiSelection = useCallback((): AiSelection | null => { + const view = editorViewRef.current; + if (!view) return null; + const main = view.state.selection.main; + if (main.empty) return null; + const from = Math.min(main.from, main.to); + const to = Math.max(main.from, main.to); + if (from === to) return null; + return { + from, + to, + text: view.state.doc.sliceString(from, to) + }; + }, []); + const openCustomPromptLightbox = useCallback(() => { setCustomPromptText(""); - setCustomPromptOpen(true); + setCustomPromptState({ + scope: "document", + selection: null + }); }, []); const statusKey = useMemo(() => {