mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-20 21:18:13 +02:00
fix Ask SurfSense: pre-fill with initialText and cursor positioning
This commit is contained in:
parent
f36e5f8287
commit
9f13da3fd1
3 changed files with 24 additions and 15 deletions
|
|
@ -166,22 +166,16 @@ function QuickAskAutoSubmit() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!window.electronAPI || handledRef.current) return;
|
if (!window.electronAPI || handledRef.current) return;
|
||||||
|
if (sessionStorage.getItem("quickAskAutoSubmit") === "false") return;
|
||||||
|
|
||||||
const prompt = searchParams.get("quickAskPrompt");
|
const prompt = searchParams.get("quickAskPrompt");
|
||||||
const initialText = searchParams.get("quickAskInitialText");
|
if (!prompt) return;
|
||||||
|
|
||||||
if (prompt) {
|
handledRef.current = true;
|
||||||
handledRef.current = true;
|
setTimeout(() => {
|
||||||
setTimeout(() => {
|
aui.composer().setText(prompt);
|
||||||
aui.composer().setText(prompt);
|
aui.composer().send();
|
||||||
aui.composer().send();
|
}, 500);
|
||||||
}, 500);
|
|
||||||
} else if (initialText) {
|
|
||||||
handledRef.current = true;
|
|
||||||
setTimeout(() => {
|
|
||||||
aui.composer().setText(initialText);
|
|
||||||
}, 500);
|
|
||||||
}
|
|
||||||
}, [searchParams, aui]);
|
}, [searchParams, aui]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ export default function QuickAskPage() {
|
||||||
|
|
||||||
const navigateToChat = (prompt: string, mode: string) => {
|
const navigateToChat = (prompt: string, mode: string) => {
|
||||||
sessionStorage.setItem("quickAskMode", mode);
|
sessionStorage.setItem("quickAskMode", mode);
|
||||||
|
sessionStorage.setItem("quickAskAutoSubmit", "true");
|
||||||
const encoded = encodeURIComponent(prompt);
|
const encoded = encodeURIComponent(prompt);
|
||||||
window.location.href = `/dashboard?quickAskPrompt=${encoded}`;
|
window.location.href = `/dashboard?quickAskPrompt=${encoded}`;
|
||||||
};
|
};
|
||||||
|
|
@ -44,8 +45,9 @@ export default function QuickAskPage() {
|
||||||
const navigateWithInitialText = () => {
|
const navigateWithInitialText = () => {
|
||||||
if (!clipboardText) return;
|
if (!clipboardText) return;
|
||||||
sessionStorage.setItem("quickAskMode", "explore");
|
sessionStorage.setItem("quickAskMode", "explore");
|
||||||
const encoded = encodeURIComponent(clipboardText);
|
sessionStorage.setItem("quickAskAutoSubmit", "false");
|
||||||
window.location.href = `/dashboard?quickAskInitialText=${encoded}`;
|
sessionStorage.setItem("quickAskInitialText", clipboardText);
|
||||||
|
window.location.href = `/dashboard?quickAskPrompt=${encodeURIComponent(clipboardText)}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAction = (actionId: string) => {
|
const handleAction = (actionId: string) => {
|
||||||
|
|
|
||||||
|
|
@ -306,6 +306,18 @@ const Composer: FC = () => {
|
||||||
const aui = useAui();
|
const aui = useAui();
|
||||||
const hasAutoFocusedRef = useRef(false);
|
const hasAutoFocusedRef = useRef(false);
|
||||||
|
|
||||||
|
const [quickAskInitialText, setQuickAskInitialText] = useState<string | undefined>();
|
||||||
|
useEffect(() => {
|
||||||
|
if (!window.electronAPI) return;
|
||||||
|
if (sessionStorage.getItem("quickAskAutoSubmit") === "false") {
|
||||||
|
const text = sessionStorage.getItem("quickAskInitialText");
|
||||||
|
if (text) {
|
||||||
|
setQuickAskInitialText(text);
|
||||||
|
sessionStorage.removeItem("quickAskInitialText");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
const isThreadEmpty = useAuiState(({ thread }) => thread.isEmpty);
|
const isThreadEmpty = useAuiState(({ thread }) => thread.isEmpty);
|
||||||
const isThreadRunning = useAuiState(({ thread }) => thread.isRunning);
|
const isThreadRunning = useAuiState(({ thread }) => thread.isRunning);
|
||||||
|
|
||||||
|
|
@ -512,6 +524,7 @@ const Composer: FC = () => {
|
||||||
onDocumentRemove={handleDocumentRemove}
|
onDocumentRemove={handleDocumentRemove}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
|
initialText={quickAskInitialText}
|
||||||
className="min-h-[24px]"
|
className="min-h-[24px]"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue