diff --git a/web/src/views/Prompt/Prompt.tsx b/web/src/views/Prompt/Prompt.tsx index 69a597db..3f1ec96e 100644 --- a/web/src/views/Prompt/Prompt.tsx +++ b/web/src/views/Prompt/Prompt.tsx @@ -138,6 +138,7 @@ const Prompt: FC<{ editVo: HistoryItem | null; refresh: () => void; }> = ({ edit currentPromptValueRef.current = undefined; setChatList([]) refresh() + updateSession() } return ( diff --git a/web/src/views/Workflow/components/Editor/index.tsx b/web/src/views/Workflow/components/Editor/index.tsx index 362e1c81..4c8540a8 100644 --- a/web/src/views/Workflow/components/Editor/index.tsx +++ b/web/src/views/Workflow/components/Editor/index.tsx @@ -242,7 +242,7 @@ const Editor: FC =({ {enableLineNumbers && } { setCount(count) }} onChange={onChange} /> - + {enableLineNumbers && } diff --git a/web/src/views/Workflow/components/Editor/plugin/BlurPlugin.tsx b/web/src/views/Workflow/components/Editor/plugin/BlurPlugin.tsx index b636605b..0fb6c48f 100644 --- a/web/src/views/Workflow/components/Editor/plugin/BlurPlugin.tsx +++ b/web/src/views/Workflow/components/Editor/plugin/BlurPlugin.tsx @@ -16,6 +16,12 @@ export default function BlurPlugin() { return; } + // 检查是否是粘贴操作导致的焦点变化 + const relatedTarget = e.relatedTarget as HTMLElement; + if (!relatedTarget || relatedTarget === document.body) { + return; + } + editor.update(() => { $setSelection(null); }); diff --git a/web/src/views/Workflow/components/Editor/plugin/JavaScriptHighlightPlugin.tsx b/web/src/views/Workflow/components/Editor/plugin/JavaScriptHighlightPlugin.tsx index 90053646..21219139 100644 --- a/web/src/views/Workflow/components/Editor/plugin/JavaScriptHighlightPlugin.tsx +++ b/web/src/views/Workflow/components/Editor/plugin/JavaScriptHighlightPlugin.tsx @@ -1,6 +1,6 @@ -import { useEffect } from 'react'; +import { useEffect, useRef } from 'react'; import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'; -import { TextNode, $createTextNode, $getSelection, $isRangeSelection } from 'lexical'; +import { TextNode, $createTextNode, $getSelection, $isRangeSelection, COMMAND_PRIORITY_LOW, PASTE_COMMAND } from 'lexical'; const JS_KEYWORDS = new Set([ 'async', 'await', 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default', @@ -11,13 +11,31 @@ const JS_KEYWORDS = new Set([ const JavaScriptHighlightPlugin = () => { const [editor] = useLexicalComposerContext(); + const isPastingRef = useRef(false); + + useEffect(() => { + return editor.registerCommand( + PASTE_COMMAND, + () => { + isPastingRef.current = true; + setTimeout(() => { + isPastingRef.current = false; + }, 100); + return false; + }, + COMMAND_PRIORITY_LOW + ); + }, [editor]); useEffect(() => { return editor.registerNodeTransform(TextNode, (textNode: TextNode) => { + if (isPastingRef.current) return; + const text = textNode.getTextContent(); if (textNode.hasFormat('code')) return; if (!needsHighlight(text)) return; + if (textNode.getStyle()) return; const parent = textNode.getParent(); if (!parent) return; diff --git a/web/src/views/Workflow/components/Editor/plugin/Python3HighlightPlugin.tsx b/web/src/views/Workflow/components/Editor/plugin/Python3HighlightPlugin.tsx index 387160ed..12830ffb 100644 --- a/web/src/views/Workflow/components/Editor/plugin/Python3HighlightPlugin.tsx +++ b/web/src/views/Workflow/components/Editor/plugin/Python3HighlightPlugin.tsx @@ -1,6 +1,6 @@ -import { useEffect } from 'react'; +import { useEffect, useRef } from 'react'; import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'; -import { TextNode, $createTextNode, $getSelection, $isRangeSelection } from 'lexical'; +import { TextNode, $createTextNode, $getSelection, $isRangeSelection, COMMAND_PRIORITY_LOW, PASTE_COMMAND } from 'lexical'; const PYTHON_KEYWORDS = new Set([ 'False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', @@ -11,12 +11,30 @@ const PYTHON_KEYWORDS = new Set([ const Python3HighlightPlugin = () => { const [editor] = useLexicalComposerContext(); + const isPastingRef = useRef(false); + + useEffect(() => { + return editor.registerCommand( + PASTE_COMMAND, + () => { + isPastingRef.current = true; + setTimeout(() => { + isPastingRef.current = false; + }, 100); + return false; + }, + COMMAND_PRIORITY_LOW + ); + }, [editor]); useEffect(() => { return editor.registerNodeTransform(TextNode, (textNode: TextNode) => { + if (isPastingRef.current) return; + const text = textNode.getTextContent(); if (textNode.hasFormat('code')) return; + if (textNode.getStyle()) return; if (!needsHighlight(text)) return; const parent = textNode.getParent(); diff --git a/web/src/views/Workflow/components/Properties/CodeExecution/index.tsx b/web/src/views/Workflow/components/Properties/CodeExecution/index.tsx index 7c95a4a2..8a0ea03e 100644 --- a/web/src/views/Workflow/components/Properties/CodeExecution/index.tsx +++ b/web/src/views/Workflow/components/Properties/CodeExecution/index.tsx @@ -33,7 +33,6 @@ const codeTemplate = { const CodeExecution: FC = ({ options }) => { const { t } = useTranslation() const form = Form.useFormInstance() - const values = Form.useWatch([], form) || {} const handleRefresh = () => { const code = form.getFieldValue('code') || '' @@ -66,7 +65,6 @@ const CodeExecution: FC = ({ options }) => { form.setFieldValue('code', newTemplate) } const handleChangeLanguage = (value: string) => { - form.setFieldValue('code', codeTemplate[value as keyof typeof codeTemplate]) form.setFieldsValue({ input_variables: [{ name: 'arg1' }, { name: 'arg2' }], code: codeTemplate[value as keyof typeof codeTemplate] @@ -109,8 +107,12 @@ const CodeExecution: FC = ({ options }) => { - - + prev.language !== curr.language}> + {() => ( + + + + )}