From 0618b2532f15224be9dca7b9e20c01e280323557 Mon Sep 17 00:00:00 2001 From: zhsama Date: Thu, 5 Feb 2026 01:36:02 +0800 Subject: [PATCH] feat: Add Enter key handler support to assemble variables generate modal --- .../components/base/prompt-editor/index.tsx | 29 ++++++++++ .../components/chat-view.tsx | 25 ++++----- .../components/left-panel.tsx | 54 ++++++++++++++----- .../hooks/use-context-generate.ts | 4 ++ .../context-generate-modal/index.tsx | 4 ++ 5 files changed, 92 insertions(+), 24 deletions(-) diff --git a/web/app/components/base/prompt-editor/index.tsx b/web/app/components/base/prompt-editor/index.tsx index 1ad380bd8d..2dcc8beed0 100644 --- a/web/app/components/base/prompt-editor/index.tsx +++ b/web/app/components/base/prompt-editor/index.tsx @@ -26,6 +26,8 @@ import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin' import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin' import { $getRoot, + COMMAND_PRIORITY_LOW, + KEY_ENTER_COMMAND, TextNode, } from 'lexical' import * as React from 'react' @@ -124,6 +126,30 @@ const ValueSyncPlugin: FC<{ value?: string }> = ({ value }) => { return null } +const EnterCommandPlugin: FC<{ onEnter?: (event: KeyboardEvent) => void }> = ({ onEnter }) => { + const [editor] = useLexicalComposerContext() + + useEffect(() => { + if (!onEnter) + return + return editor.registerCommand( + KEY_ENTER_COMMAND, + (event: KeyboardEvent) => { + if (!event || event.defaultPrevented) + return false + if (event.isComposing || event.shiftKey) + return false + event.preventDefault() + onEnter(event) + return true + }, + COMMAND_PRIORITY_LOW, + ) + }, [editor, onEnter]) + + return null +} + export type PromptEditorProps = { instanceId?: string compact?: boolean @@ -152,6 +178,7 @@ export type PromptEditorProps = { isSupportFileVar?: boolean isSupportSandbox?: boolean disableToolBlocks?: boolean + onEnter?: (event: KeyboardEvent) => void } const PromptEditor: FC = ({ @@ -182,6 +209,7 @@ const PromptEditor: FC = ({ isSupportFileVar, isSupportSandbox, disableToolBlocks, + onEnter, }) => { const { eventEmitter } = useEventEmitterContextContext() const initialConfig = { @@ -436,6 +464,7 @@ const PromptEditor: FC = ({ } + diff --git a/web/app/components/workflow/nodes/tool/components/context-generate-modal/components/chat-view.tsx b/web/app/components/workflow/nodes/tool/components/context-generate-modal/components/chat-view.tsx index 8e4a957a83..efea695bd9 100644 --- a/web/app/components/workflow/nodes/tool/components/context-generate-modal/components/chat-view.tsx +++ b/web/app/components/workflow/nodes/tool/components/context-generate-modal/components/chat-view.tsx @@ -1,6 +1,7 @@ import type { ReactNode } from 'react' import type { ContextGenerateChatMessage } from '../hooks/use-context-generate' import type { VersionOption } from '../types' +import type { WorkflowVariableBlockType } from '@/app/components/base/prompt-editor/types' import type { FormValue } from '@/app/components/header/account-setting/model-provider-page/declarations' import type { TriggerProps } from '@/app/components/header/account-setting/model-provider-page/model-parameter-modal/trigger' import type { Model } from '@/types/app' @@ -10,6 +11,7 @@ import { useTranslation } from 'react-i18next' import Button from '@/app/components/base/button' import LoadingAnim from '@/app/components/base/chat/chat/loading-anim' import { CodeAssistant } from '@/app/components/base/icons/src/vender/line/general' +import PromptEditor from '@/app/components/base/prompt-editor' import ModelParameterModal from '@/app/components/header/account-setting/model-provider-page/model-parameter-modal' import { cn } from '@/utils/classnames' @@ -27,6 +29,7 @@ type ChatViewProps = { onModelChange: (newValue: { modelId: string, provider: string, mode?: string, features?: string[] }) => void onCompletionParamsChange: (newParams: FormValue) => void renderModelTrigger: (params: TriggerProps) => ReactNode + workflowVariableBlock: WorkflowVariableBlockType } const ChatView = ({ @@ -43,6 +46,7 @@ const ChatView = ({ onModelChange, onCompletionParamsChange, renderModelTrigger, + workflowVariableBlock, }: ChatViewProps) => { const { t } = useTranslation() const chatListRef = useRef(null) @@ -130,19 +134,16 @@ const ChatView = ({
-