From 015f4ea10a524fad732566920b08ae6aba769b34 Mon Sep 17 00:00:00 2001 From: Innei Date: Wed, 22 Oct 2025 21:51:06 +0800 Subject: [PATCH] fix(editor): is input empty state - Modified the isEmpty method in both ChatInput and LexicalRichEditor components to check if the editor's content is empty by verifying if the trimmed text content is an empty string. - Added an accessories prop to LexicalRichEditor for improved flexibility in rendering additional UI elements. Signed-off-by: Innei --- .../src/modules/ai-chat/components/layouts/ChatInput.tsx | 2 +- .../src/ui/lexical-rich-editor/LexicalRichEditor.tsx | 5 ++++- .../internal/components/src/ui/lexical-rich-editor/types.ts | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatInput.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatInput.tsx index 59c2ff75d..dee4219bd 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatInput.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatInput.tsx @@ -78,7 +78,7 @@ export const ChatInput = memo(({ onSend, variant, ref: forwardedRef }: ChatInput setCurrentEditor(editor) editorState.read(() => { - setIsEmpty($getRoot().isEmpty()) + setIsEmpty($getRoot().getTextContent().trim() === "") }) }, []) diff --git a/packages/internal/components/src/ui/lexical-rich-editor/LexicalRichEditor.tsx b/packages/internal/components/src/ui/lexical-rich-editor/LexicalRichEditor.tsx index 2fc557dd4..3569a63e0 100644 --- a/packages/internal/components/src/ui/lexical-rich-editor/LexicalRichEditor.tsx +++ b/packages/internal/components/src/ui/lexical-rich-editor/LexicalRichEditor.tsx @@ -71,6 +71,7 @@ export const LexicalRichEditor = function LexicalRichEditor({ enabledPlugins = defaultEnabledPlugins, initalEditorState, plugins, + accessories, onKeyDown, onChange, @@ -103,12 +104,14 @@ export const LexicalRichEditor = function LexicalRichEditor({ root.clear() }) }, - isEmpty: () => editorRef?.getEditorState().read(() => $getRoot().isEmpty()) || false, + isEmpty: () => + editorRef?.getEditorState().read(() => $getRoot().getTextContent().trim() === "") || false, })) return (
+ {accessories} void onChange?: (editorState: EditorState, editor: LexicalEditor) => void onKeyDown?: (event: KeyboardEvent) => boolean