This commit is contained in:
jasongwq
2025-02-17 03:00:59 +00:00
committed by GitHub
2 changed files with 11 additions and 16 deletions

View File

@@ -995,6 +995,8 @@ function _Chat() {
const fontSize = config.fontSize;
const fontFamily = config.fontFamily;
const slashOffsetRef = useRef(0);
const [showExport, setShowExport] = useState(false);
const inputRef = useRef<HTMLTextAreaElement>(null);
@@ -1093,10 +1095,13 @@ function _Chat() {
setPromptHints([]);
} else if (text.match(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);
}
}
@@ -1134,7 +1139,7 @@ function _Chat() {
setUserInput("");
} else {
// or fill the prompt
setUserInput(prompt.content);
setUserInput(prompt.content + userInput.slice(0, slashOffsetRef.current));
}
inputRef.current?.focus();
}, 30);
@@ -1185,6 +1190,8 @@ function _Chat() {
setUserInput(chatStore.lastInput ?? "");
e.preventDefault();
return;
} else if (e.key === "/") {
slashOffsetRef.current = userInput.length;
}
if (shouldSubmit(e) && promptHints.length === 0) {
doSubmit(userInput);