Skip to content

Commit d9e407f

Browse files
authored
Merge pull request ChatGPTNextWeb#5175 from frostime/upstream-main
✨ feat: 为命令前缀( `:` )增加对中文符号 `:`的支持
2 parents a8c65e3 + deb140d commit d9e407f

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

app/command.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ interface ChatCommands {
4141
del?: Command;
4242
}
4343

44-
export const ChatCommandPrefix = ":";
44+
// Compatible with Chinese colon character ":"
45+
export const ChatCommandPrefix = /^[:]/;
4546

4647
export function useChatCommand(commands: ChatCommands = {}) {
4748
function extract(userInput: string) {
48-
return (
49-
userInput.startsWith(ChatCommandPrefix) ? userInput.slice(1) : userInput
50-
) as keyof ChatCommands;
49+
const match = userInput.match(ChatCommandPrefix);
50+
if (match) {
51+
return userInput.slice(1) as keyof ChatCommands;
52+
}
53+
return userInput as keyof ChatCommands;
5154
}
5255

5356
function search(userInput: string) {
@@ -57,7 +60,7 @@ export function useChatCommand(commands: ChatCommands = {}) {
5760
.filter((c) => c.startsWith(input))
5861
.map((c) => ({
5962
title: desc[c as keyof ChatCommands],
60-
content: ChatCommandPrefix + c,
63+
content: ":" + c,
6164
}));
6265
}
6366

app/components/chat.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ function _Chat() {
811811
// clear search results
812812
if (n === 0) {
813813
setPromptHints([]);
814-
} else if (text.startsWith(ChatCommandPrefix)) {
814+
} else if (text.match(ChatCommandPrefix)) {
815815
setPromptHints(chatCommands.search(text));
816816
} else if (!config.disablePromptHint && n < SEARCH_TEXT_LIMIT) {
817817
// check if need to trigger auto completion

0 commit comments

Comments
 (0)