Skip to content

Commit

Permalink
✨ feat: 为命令前缀( : )支持中文符号
Browse files Browse the repository at this point in the history
  • Loading branch information
frostime committed May 30, 2024
1 parent 6d57e7c commit 29171bd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
17 changes: 12 additions & 5 deletions app/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@ interface ChatCommands {
del?: Command;
}

export const ChatCommandPrefix = ":";
// export const ChatCommandPrefix = ":";
export const ChatCommandPrefix = /^[:]/;

export function useChatCommand(commands: ChatCommands = {}) {
function extract(userInput: string) {
return (
userInput.startsWith(ChatCommandPrefix) ? userInput.slice(1) : userInput
) as keyof ChatCommands;
// 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 +63,8 @@ export function useChatCommand(commands: ChatCommands = {}) {
.filter((c) => c.startsWith(input))
.map((c) => ({
title: desc[c as keyof ChatCommands],
content: ChatCommandPrefix + c,
// content: ChatCommandPrefix + c,
content: ":" + c,
}));
}

Expand Down
3 changes: 2 additions & 1 deletion app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,8 @@ function _Chat() {
// clear search results
if (n === 0) {
setPromptHints([]);
} else if (text.startsWith(ChatCommandPrefix)) {
// } 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
4 changes: 4 additions & 0 deletions changelog-custom.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [2024-05-30] v2.13.2.4

- ✨ 为命令前缀( `:` )支持中文符号 ``

## [2024-05-28] v2.13.2.3

- ✨ 对话框中的代码块根据语言来自行决定是否折行显示
Expand Down

0 comments on commit 29171bd

Please sign in to comment.