🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix: Fix editor key handling (#9189)
CanisMinor8be822b0b7f2
diff --git a/locales/ar/chat.json b/locales/ar/chat.jsonindex bdfba7f2fe4..36307499791 100644--- a/locales/ar/chat.json+++ b/locales/ar/chat.json@@ -77,7 +77,8 @@"sendWithCmdEnter": "اضغط <key/> للإرسال","sendWithEnter": "اضغط <key/> للإرسال","stop": "توقف",- "warp": "تغيير السطر"+ "warp": "تغيير السطر",+ "warpWithKey": "اضغط على مفتاح <key/> للانتقال إلى السطر"},"intentUnderstanding": {"title": "جارٍ فهم وتحليل نواياك..."diff --git a/locales/bg-BG/chat.json b/locales/bg-BG/chat.jsonindex 409d0f5415f..073be2fd8ac 100644--- a/locales/bg-BG/chat.json+++ b/locales/bg-BG/chat.json@@ -77,7 +77,8 @@"sendWithCmdEnter": "Натиснете <key/> за изпращане","sendWithEnter": "Натиснете <key/> за изпращане","stop": "Спри",- "warp": "Нов ред"+ "warp": "Нов ред",+ "warpWithKey": "Натиснете <key/> за нов ред"},"intentUnderstanding": {"title": "Разбирам и анализирам вашето намерение..."diff --git a/locales/de-DE/chat.json b/locales/de-DE/chat.jsonindex 19027ddcba8..a1d123cc869 100644--- a/locales/de-DE/chat.json+++ b/locales/de-DE/chat.json@@ -77,7 +77,8 @@"sendWithCmdEnter": "Drücken Sie <key/>, um zu senden","sendWithEnter": "Drücken Sie <key/>, um zu senden","stop": "Stoppen",- "warp": "Zeilenumbruch"+ "warp": "Zeilenumbruch",+ "warpWithKey": "Mit der Taste <key/> umbrechen"},"intentUnderstanding": {"title": "Verstehe und analysiere gerade Ihre Absicht..."diff --git a/locales/en-US/chat.json b/locales/en-US/chat.jsonindex 57171bc194d..6d80f415051 100644--- a/locales/en-US/chat.json+++ b/locales/en-US/chat.json@@ -77,7 +77,8 @@"sendWithCmdEnter": "Press <key/> to send","sendWithEnter": "Press <key/> to send","stop": "Stop",- "warp": "New Line"+ "warp": "New Line",+ "warpWithKey": "Press <key/> to insert a line break"},"intentUnderstanding": {"title": "Understanding and analyzing your intent..."diff --git a/locales/es-ES/chat.json b/locales/es-ES/chat.jsonindex 7603dd60f80..90409601004 100644--- a/locales/es-ES/chat.json+++ b/locales/es-ES/chat.json@@ -77,7 +77,8 @@"sendWithCmdEnter": "Presiona <key/> para enviar","sendWithEnter": "Presiona <key/> para enviar","stop": "Detener",- "warp": "Salto de línea"+ "warp": "Salto de línea",+ "warpWithKey": "Presione la tecla <key/> para hacer un salto de línea"},"intentUnderstanding": {"title": "Entendiendo y analizando su intención..."diff --git a/locales/fa-IR/chat.json b/locales/fa-IR/chat.jsonindex 68bfd5eb219..9871ca4795b 100644--- a/locales/fa-IR/chat.json+++ b/locales/fa-IR/chat.json@@ -77,7 +77,8 @@"sendWithCmdEnter": "برای ارسال، کلید <key/> را فشار دهید","sendWithEnter": "برای ارسال، کلید <key/> را فشار دهید","stop": "توقف",- "warp": "خط جدید"+ "warp": "خط جدید",+ "warpWithKey": "با فشار دادن کلید <key/> خط جدید ایجاد کنید"},"intentUnderstanding": {"title": "در حال درک و تحلیل نیت شما..."diff --git a/locales/fr-FR/chat.json b/locales/fr-FR/chat.jsonindex 2961344d2ca..f29a74048f6 100644--- a/locales/fr-FR/chat.json+++ b/locales/fr-FR/chat.json@@ -77,7 +77,8 @@"sendWithCmdEnter": "Appuyez sur <key/> pour envoyer","sendWithEnter": "Appuyez sur <key/> pour envoyer","stop": "Arrêter",- "warp": "Saut de ligne"+ "warp": "Saut de ligne",+ "warpWithKey": "Appuyez sur la touche <key/> pour un retour à la ligne"},"intentUnderstanding": {"title": "En train de comprendre et d'analyser votre intention..."diff --git a/locales/it-IT/chat.json b/locales/it-IT/chat.jsonindex eefb816f379..83ad9a93a68 100644--- a/locales/it-IT/chat.json+++ b/locales/it-IT/chat.json@@ -77,7 +77,8 @@"sendWithCmdEnter": "Premi <key/> per inviare","sendWithEnter": "Premi <key/> per inviare","stop": "Ferma",- "warp": "A capo"+ "warp": "A capo",+ "warpWithKey": "Vai a capo premendo il tasto <key/>"},"intentUnderstanding": {"title": "Stiamo comprendendo e analizzando la tua intenzione..."diff --git a/locales/ja-JP/chat.json b/locales/ja-JP/chat.jsonindex 43a27bcb905..fc38fab9177 100644--- a/locales/ja-JP/chat.json+++ b/locales/ja-JP/chat.json@@ -77,7 +77,8 @@"sendWithCmdEnter": "<key/> キーを押して送信","sendWithEnter": "<key/> キーを押して送信","stop": "停止",- "warp": "改行"+ "warp": "改行",+ "warpWithKey": "<key/> キーを押して改行"},"intentUnderstanding": {"title": "あなたの意図を理解し、分析しています..."diff --git a/locales/ko-KR/chat.json b/locales/ko-KR/chat.jsonindex ff62d47ec8f..4f56b59718d 100644--- a/locales/ko-KR/chat.json+++ b/locales/ko-KR/chat.json@@ -77,7 +77,8 @@"sendWithCmdEnter": "<key/> 키를 눌러 전송","sendWithEnter": "<key/> 키를 눌러 전송","stop": "중지",- "warp": "줄바꿈"+ "warp": "줄바꿈",+ "warpWithKey": "<key/> 키를 눌러 줄 바꿈"},"intentUnderstanding": {"title": "귀하의 의도를 이해하고 분석하는 중입니다..."diff --git a/locales/nl-NL/chat.json b/locales/nl-NL/chat.jsonindex 0420d48a74c..8b7b5b72eb2 100644--- a/locales/nl-NL/chat.json+++ b/locales/nl-NL/chat.json@@ -77,7 +77,8 @@"sendWithCmdEnter": "Druk op <key/> om te verzenden","sendWithEnter": "Druk op <key/> om te verzenden","stop": "Stoppen",- "warp": "Nieuwe regel"+ "warp": "Nieuwe regel",+ "warpWithKey": "Druk op <key/> om een nieuwe regel te beginnen"},"intentUnderstanding": {"title": "Bezig met het begrijpen en analyseren van uw intentie..."diff --git a/locales/pl-PL/chat.json b/locales/pl-PL/chat.jsonindex dd162004694..8dd7148cdeb 100644--- a/locales/pl-PL/chat.json+++ b/locales/pl-PL/chat.json@@ -77,7 +77,8 @@"sendWithCmdEnter": "Naciśnij <key/>, aby wysłać","sendWithEnter": "Naciśnij <key/>, aby wysłać","stop": "Zatrzymaj",- "warp": "Złamanie wiersza"+ "warp": "Złamanie wiersza",+ "warpWithKey": "Zawijaj wiersz klawiszem <key/>"},"intentUnderstanding": {"title": "Rozumiemy i analizujemy Twoje intencje..."diff --git a/locales/pt-BR/chat.json b/locales/pt-BR/chat.jsonindex e91813e2d45..d7e86833eea 100644--- a/locales/pt-BR/chat.json+++ b/locales/pt-BR/chat.json@@ -77,7 +77,8 @@"sendWithCmdEnter": "Pressione <key/> para enviar","sendWithEnter": "Pressione <key/> para enviar","stop": "Parar",- "warp": "Quebrar linha"+ "warp": "Quebrar linha",+ "warpWithKey": "Quebrar linha pressionando <key/> tecla"},"intentUnderstanding": {"title": "Entendendo e analisando sua intenção..."diff --git a/locales/ru-RU/chat.json b/locales/ru-RU/chat.jsonindex 04fd5c47495..c308185b59e 100644--- a/locales/ru-RU/chat.json+++ b/locales/ru-RU/chat.json@@ -77,7 +77,8 @@"sendWithCmdEnter": "Нажмите <key/> для отправки","sendWithEnter": "Нажмите <key/> для отправки","stop": "Остановить",- "warp": "Перенос строки"+ "warp": "Перенос строки",+ "warpWithKey": "Нажмите клавишу <key/> для переноса строки"},"intentUnderstanding": {"title": "Мы понимаем и анализируем ваше намерение..."diff --git a/locales/tr-TR/chat.json b/locales/tr-TR/chat.jsonindex 781a2fc1ade..b758619a1e6 100644--- a/locales/tr-TR/chat.json+++ b/locales/tr-TR/chat.json@@ -77,7 +77,8 @@"sendWithCmdEnter": "<key/> tuşuna basarak gönder","sendWithEnter": "<key/> tuşuna basarak gönder","stop": "Dur",- "warp": "Satır atla"+ "warp": "Satır atla",+ "warpWithKey": "<key/> tuşuna basarak satır sonu yap"},"intentUnderstanding": {"title": "Niyetinizi anlama ve analiz etme aşamasındayız..."diff --git a/locales/vi-VN/chat.json b/locales/vi-VN/chat.jsonindex ec034a389c8..fb64e6acb77 100644--- a/locales/vi-VN/chat.json+++ b/locales/vi-VN/chat.json@@ -77,7 +77,8 @@"sendWithCmdEnter": "Nhấn <key/> để gửi","sendWithEnter": "Nhấn <key/> để gửi","stop": "Dừng",- "warp": "Xuống dòng"+ "warp": "Xuống dòng",+ "warpWithKey": "Nhấn phím <key/> để xuống dòng"},"intentUnderstanding": {"title": "Đang hiểu và phân tích ý định của bạn..."diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.jsonindex dfea95df01c..5f5a7e4810e 100644--- a/locales/zh-CN/chat.json+++ b/locales/zh-CN/chat.json@@ -77,7 +77,8 @@"sendWithCmdEnter": "按 <key/> 键发送","sendWithEnter": "按 <key/> 键发送","stop": "停止",- "warp": "换行"+ "warp": "换行",+ "warpWithKey": "按 <key/> 键换行"},"intentUnderstanding": {"title": "正在理解并分析您的意图..."diff --git a/locales/zh-TW/chat.json b/locales/zh-TW/chat.jsonindex 6ecb28b7498..3e27b10ad12 100644--- a/locales/zh-TW/chat.json+++ b/locales/zh-TW/chat.json@@ -77,7 +77,8 @@"sendWithCmdEnter": "按 <key/> 鍵發送","sendWithEnter": "按 <key/> 鍵發送","stop": "停止",- "warp": "換行"+ "warp": "換行",+ "warpWithKey": "按 <key/> 鍵換行"},"intentUnderstanding": {"title": "正在理解並分析您的意圖..."diff --git a/package.json b/package.jsonindex d520d8fd08f..92b47d0e6d9 100644--- a/package.json+++ b/package.json@@ -155,11 +155,11 @@"@lobehub/charts": "^2.0.0","@lobehub/chat-plugin-sdk": "^1.32.4","@lobehub/chat-plugins-gateway": "^1.9.0",- "@lobehub/editor": "^1.5.4",+ "@lobehub/editor": "^1.5.8","@lobehub/icons": "^2.31.0","@lobehub/market-sdk": "^0.22.7","@lobehub/tts": "^2.0.1",- "@lobehub/ui": "^2.11.9",+ "@lobehub/ui": "^2.12.2","@modelcontextprotocol/sdk": "^1.17.1","@neondatabase/serverless": "^1.0.1","@next/third-parties": "^15.4.6",diff --git a/packages/utils/src/keyboard.ts b/packages/utils/src/keyboard.tsindex 9ef29f7226a..96d293bd82c 100644--- a/packages/utils/src/keyboard.ts+++ b/packages/utils/src/keyboard.ts@@ -1,5 +1,3 @@-import { KeyboardEvent } from 'react';-import { isMacOS } from './platform';export const isCommandPressed = (event: KeyboardEvent) => {diff --git a/src/features/ChatInput/InputEditor/index.tsx b/src/features/ChatInput/InputEditor/index.tsxindex 541af15c338..3bc75b77e15 100644--- a/src/features/ChatInput/InputEditor/index.tsx+++ b/src/features/ChatInput/InputEditor/index.tsx@@ -1,5 +1,5 @@import { isDesktop } from '@lobechat/const';-import { HotkeyEnum } from '@lobechat/types';+import { HotkeyEnum, KeyEnum } from '@lobechat/types';import { isCommandPressed } from '@lobechat/utils';import {INSERT_TABLE_COMMAND,@@ -12,13 +12,15 @@ import {ReactTablePlugin,} from '@lobehub/editor';import { Editor, FloatMenu, SlashMenu, useEditorState } from '@lobehub/editor/react';+import { Hotkey, combineKeys } from '@lobehub/ui';import { Table2Icon } from 'lucide-react';import { memo, useEffect, useRef } from 'react';import { useHotkeysContext } from 'react-hotkeys-hook';-import { useTranslation } from 'react-i18next';+import { Trans, useTranslation } from 'react-i18next';+import { Flexbox } from 'react-layout-kit';import { useUserStore } from '@/store/user';-import { preferenceSelectors } from '@/store/user/selectors';+import { preferenceSelectors, settingsSelectors } from '@/store/user/selectors';import { useChatInputStore, useStoreApi } from '../store';@@ -32,14 +34,17 @@ const InputEditor = memo<{ defaultRows?: number }>(({ defaultRows = 2 }) => {]);const storeApi = useStoreApi();-const state = useEditorState(editor);+ const hotkey = useUserStore(settingsSelectors.getHotkeyById(HotkeyEnum.AddUserMessage));const { enableScope, disableScope } = useHotkeysContext();const { t } = useTranslation(['editor', 'chat']);const isChineseInput = useRef(false);const useCmdEnterToSend = useUserStore(preferenceSelectors.useCmdEnterToSend);+ const wrapperShortcut = useCmdEnterToSend+ ? KeyEnum.Enter+ : combineKeys([KeyEnum.Mod, KeyEnum.Enter]);useEffect(() => {const fn = (e: BeforeUnloadEvent) => {@@ -91,16 +96,44 @@ const InputEditor = memo<{ defaultRows?: number }>(({ defaultRows = 2 }) => {}}onInit={(editor) => storeApi.setState({ editor })}onPressEnter={({ event: e }) => {- if (e.altKey || e.shiftKey || isChineseInput.current) return;+ if (e.shiftKey || isChineseInput.current) return;+ // when user like alt + enter to add ai message+ if (e.altKey && hotkey === combineKeys([KeyEnum.Alt, KeyEnum.Enter])) return true;const commandKey = isCommandPressed(e);// when user like cmd + enter to send messageif (useCmdEnterToSend) {- if (commandKey) send();+ if (commandKey) {+ send();+ return true;+ }} else {- if (!commandKey) send();+ if (!commandKey) {+ send();+ return true;+ }}}}- placeholder={t('sendPlaceholder', { ns: 'chat' })}+ placeholder={+ <Flexbox align={'center'} gap={4} horizontal>+ {t('sendPlaceholder', { ns: 'chat' }).replace('...', ', ')}+ <Trans+ as={'div'}+ components={{+ key: (+ <Hotkey+ keys={wrapperShortcut}+ style={{ color: 'inherit' }}+ styles={{ kbdStyle: { color: 'inhert' } }}+ variant={'borderless'}+ />+ ),+ }}+ i18nKey={'input.warpWithKey'}+ ns={'chat'}+ />+ {'...'}+ </Flexbox>+ }plugins={[ReactListPlugin,ReactLinkPlugin,diff --git a/src/features/ChatInput/TypoBar/index.tsx b/src/features/ChatInput/TypoBar/index.tsxindex ee37ed1e190..e6e273bc4d7 100644--- a/src/features/ChatInput/TypoBar/index.tsx+++ b/src/features/ChatInput/TypoBar/index.tsx@@ -18,6 +18,7 @@ import {SigmaIcon,SquareDashedBottomCodeIcon,StrikethroughIcon,+ UnderlineIcon,} from 'lucide-react';import { memo } from 'react';import { useTranslation } from 'react-i18next';@@ -50,14 +51,13 @@ const TypoBar = memo(() => {label: t('typobar.italic'),onClick: editorState.italic,},- // TODO: 目前 markdown 不支持 <u>- // {- // active: editorState.isUnderline,- // icon: UnderlineIcon,- // key: 'underline',- // label: t('typobar.underline'),- // onClick: editorState.underline,- // },+ {+ active: editorState.isUnderline,+ icon: UnderlineIcon,+ key: 'underline',+ label: t('typobar.underline'),+ onClick: editorState.underline,+ },{active: editorState.isStrikethrough,icon: StrikethroughIcon,diff --git a/src/hooks/useHotkeys/chatScope.ts b/src/hooks/useHotkeys/chatScope.tsindex e1a2bb345f6..45d2a6dbe39 100644--- a/src/hooks/useHotkeys/chatScope.ts+++ b/src/hooks/useHotkeys/chatScope.ts@@ -18,12 +18,12 @@ import { useHotkeyById } from './useHotkeyById';export const useSaveTopicHotkey = () => {const openNewTopicOrSaveTopic = useChatStore((s) => s.openNewTopicOrSaveTopic);const { mutate } = useActionSWR('openNewTopicOrSaveTopic', openNewTopicOrSaveTopic);- return useHotkeyById(HotkeyEnum.SaveTopic, () => mutate());+ return useHotkeyById(HotkeyEnum.SaveTopic, () => mutate(), { enableOnContentEditable: true });};export const useToggleZenModeHotkey = () => {const toggleZenMode = useGlobalStore((s) => s.toggleZenMode);- return useHotkeyById(HotkeyEnum.ToggleZenMode, toggleZenMode);+ return useHotkeyById(HotkeyEnum.ToggleZenMode, toggleZenMode, { enableOnContentEditable: true });};export const useOpenChatSettingsHotkey = () => {@@ -41,6 +41,7 @@ export const useRegenerateMessageHotkey = () => {HotkeyEnum.RegenerateMessage,() => !disable && regenerateMessage(lastMessage.id),{+ enableOnContentEditable: true,enabled: !disable,},);@@ -60,6 +61,7 @@ export const useToggleLeftPanelHotkey = () => {showSessionPanel: !showSessionPanel,}),{+ enableOnContentEditable: true,enabled: !isZenMode && !isPinned,},);@@ -70,20 +72,29 @@ export const useToggleRightPanelHotkey = () => {const toggleConfig = useGlobalStore((s) => s.toggleChatSideBar);return useHotkeyById(HotkeyEnum.ToggleRightPanel, () => toggleConfig(), {+ enableOnContentEditable: true,enabled: !isZenMode,});};export const useAddUserMessageHotkey = () => {const { send } = useSend();- return useHotkeyById(HotkeyEnum.AddUserMessage, () => {- send({ onlyAddUserMessage: true });- });+ return useHotkeyById(+ HotkeyEnum.AddUserMessage,+ () => {+ send({ onlyAddUserMessage: true });+ },+ {+ enableOnContentEditable: true,+ },+ );};export const useClearCurrentMessagesHotkey = () => {const clearCurrentMessages = useClearCurrentMessages();- return useHotkeyById(HotkeyEnum.ClearCurrentMessages, () => clearCurrentMessages());+ return useHotkeyById(HotkeyEnum.ClearCurrentMessages, () => clearCurrentMessages(), {+ enableOnContentEditable: true,+ });};// 注册聚合diff --git a/src/locales/default/chat.ts b/src/locales/default/chat.tsindex c6175494f37..9dcc452cb93 100644--- a/src/locales/default/chat.ts+++ b/src/locales/default/chat.ts@@ -79,6 +79,7 @@ export default {sendWithEnter: '按 <key/> 键发送',stop: '停止',warp: '换行',+ warpWithKey: '按 <key/> 键换行',},intentUnderstanding: {title: '正在理解并分析您的意图...',