From deb140de739ccda009fc93ffce1e33e53682b042 Mon Sep 17 00:00:00 2001
From: frostime <frostime@foxmail.com>
Date: Fri, 2 Aug 2024 22:27:45 +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          | 13 ++++++++-----
 app/components/chat.tsx |  2 +-
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/app/command.ts b/app/command.ts
index e515e5f0b..bea4e06f3 100644
--- a/app/command.ts
+++ b/app/command.ts
@@ -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) {
@@ -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,
       }));
   }
 
diff --git a/app/components/chat.tsx b/app/components/chat.tsx
index bb4b611ad..785b1f7cd 100644
--- a/app/components/chat.tsx
+++ b/app/components/chat.tsx
@@ -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