diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 061192504..fbca15718 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -671,6 +671,8 @@ function _Chat() { const config = useAppConfig(); const fontSize = config.fontSize; + const slashOffsetRef = useRef(0); + const [showExport, setShowExport] = useState(false); const inputRef = useRef(null); @@ -751,10 +753,13 @@ function _Chat() { setPromptHints([]); } else if (text.startsWith(ChatCommandPrefix)) { setPromptHints(chatCommands.search(text)); - } else if (!config.disablePromptHint && n < SEARCH_TEXT_LIMIT) { + } else if ( + !config.disablePromptHint && + text.length < slashOffsetRef.current + SEARCH_TEXT_LIMIT + ) { // check if need to trigger auto completion - if (text.startsWith("/")) { - let searchText = text.slice(1); + if (text.slice(slashOffsetRef.current).startsWith("/")) { + let searchText = text.slice(slashOffsetRef.current + 1); onSearch(searchText); } } @@ -792,7 +797,7 @@ function _Chat() { setUserInput(""); } else { // or fill the prompt - setUserInput(prompt.content); + setUserInput(prompt.content + userInput.slice(0, slashOffsetRef.current)); } inputRef.current?.focus(); }, 30); @@ -843,6 +848,8 @@ function _Chat() { setUserInput(localStorage.getItem(LAST_INPUT_KEY) ?? ""); e.preventDefault(); return; + } else if (e.key === "/") { + slashOffsetRef.current = userInput.length; } if (shouldSubmit(e) && promptHints.length === 0) { doSubmit(userInput);