From 29171bdf33582936f8399b21956a2f8194fd89b5 Mon Sep 17 00:00:00 2001 From: frostime Date: Thu, 30 May 2024 12:09:09 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E4=B8=BA=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E5=89=8D=E7=BC=80=EF=BC=88=20`:`=20=EF=BC=89=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=B8=AD=E6=96=87=E7=AC=A6=E5=8F=B7=20`=EF=BC=9A`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/command.ts | 17 ++++++++++++----- app/components/chat.tsx | 3 ++- changelog-custom.md | 4 ++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/command.ts b/app/command.ts index e515e5f0bb4..d10ac5d027a 100644 --- a/app/command.ts +++ b/app/command.ts @@ -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) { @@ -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, })); } diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 50ac9caa918..7b8b077bfd8 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -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 diff --git a/changelog-custom.md b/changelog-custom.md index f5ab6f7511a..1cb2755b98f 100644 --- a/changelog-custom.md +++ b/changelog-custom.md @@ -1,3 +1,7 @@ +## [2024-05-30] v2.13.2.4 + +- ✨ 为命令前缀( `:` )支持中文符号 `:` + ## [2024-05-28] v2.13.2.3 - ✨ 对话框中的代码块根据语言来自行决定是否折行显示