Skip to content

Commit

Permalink
Merge pull request ChatGPTNextWeb#5175 from frostime/upstream-main
Browse files Browse the repository at this point in the history
✨ feat: 为命令前缀( `:` )增加对中文符号 `:`的支持
  • Loading branch information
Dogtiti authored Aug 3, 2024
2 parents a8c65e3 + deb140d commit d9e407f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions app/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ interface ChatCommands {
del?: Command;
}

export const ChatCommandPrefix = ":";
// Compatible with Chinese colon character ":"
export const ChatCommandPrefix = /^[::]/;

export function useChatCommand(commands: ChatCommands = {}) {
function extract(userInput: string) {
return (
userInput.startsWith(ChatCommandPrefix) ? userInput.slice(1) : userInput
) as keyof ChatCommands;
const match = userInput.match(ChatCommandPrefix);
if (match) {
return userInput.slice(1) as keyof ChatCommands;
}
return userInput as keyof ChatCommands;
}

function search(userInput: string) {
Expand All @@ -57,7 +60,7 @@ export function useChatCommand(commands: ChatCommands = {}) {
.filter((c) => c.startsWith(input))
.map((c) => ({
title: desc[c as keyof ChatCommands],
content: ChatCommandPrefix + c,
content: ":" + c,
}));
}

Expand Down
2 changes: 1 addition & 1 deletion app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ function _Chat() {
// clear search results
if (n === 0) {
setPromptHints([]);
} else if (text.startsWith(ChatCommandPrefix)) {
} else if (text.match(ChatCommandPrefix)) {
setPromptHints(chatCommands.search(text));
} else if (!config.disablePromptHint && n < SEARCH_TEXT_LIMIT) {
// check if need to trigger auto completion
Expand Down

0 comments on commit d9e407f

Please sign in to comment.