Merge pull request #304 from SuanmoSuanyangTechnology/fix/release_web_zy
Fix/release web zy
This commit is contained in:
@@ -138,6 +138,7 @@ const Prompt: FC<{ editVo: HistoryItem | null; refresh: () => void; }> = ({ edit
|
|||||||
currentPromptValueRef.current = undefined;
|
currentPromptValueRef.current = undefined;
|
||||||
setChatList([])
|
setChatList([])
|
||||||
refresh()
|
refresh()
|
||||||
|
updateSession()
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ const Editor: FC<LexicalEditorProps> =({
|
|||||||
{enableLineNumbers && <LineNumberPlugin />}
|
{enableLineNumbers && <LineNumberPlugin />}
|
||||||
<AutocompletePlugin options={options} enableJinja2={enableJinja2} />
|
<AutocompletePlugin options={options} enableJinja2={enableJinja2} />
|
||||||
<CharacterCountPlugin setCount={(count) => { setCount(count) }} onChange={onChange} />
|
<CharacterCountPlugin setCount={(count) => { setCount(count) }} onChange={onChange} />
|
||||||
<InitialValuePlugin value={value} options={options} enableLineNumbers={enableLineNumbers} />
|
<InitialValuePlugin key={language} value={value} options={options} enableLineNumbers={enableLineNumbers} />
|
||||||
{enableLineNumbers && <BlurPlugin />}
|
{enableLineNumbers && <BlurPlugin />}
|
||||||
</div>
|
</div>
|
||||||
</LexicalComposer>
|
</LexicalComposer>
|
||||||
|
|||||||
@@ -16,6 +16,12 @@ export default function BlurPlugin() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查是否是粘贴操作导致的焦点变化
|
||||||
|
const relatedTarget = e.relatedTarget as HTMLElement;
|
||||||
|
if (!relatedTarget || relatedTarget === document.body) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
editor.update(() => {
|
editor.update(() => {
|
||||||
$setSelection(null);
|
$setSelection(null);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect, useRef } from 'react';
|
||||||
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
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([
|
const JS_KEYWORDS = new Set([
|
||||||
'async', 'await', 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default',
|
'async', 'await', 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default',
|
||||||
@@ -11,13 +11,31 @@ const JS_KEYWORDS = new Set([
|
|||||||
|
|
||||||
const JavaScriptHighlightPlugin = () => {
|
const JavaScriptHighlightPlugin = () => {
|
||||||
const [editor] = useLexicalComposerContext();
|
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(() => {
|
useEffect(() => {
|
||||||
return editor.registerNodeTransform(TextNode, (textNode: TextNode) => {
|
return editor.registerNodeTransform(TextNode, (textNode: TextNode) => {
|
||||||
|
if (isPastingRef.current) return;
|
||||||
|
|
||||||
const text = textNode.getTextContent();
|
const text = textNode.getTextContent();
|
||||||
|
|
||||||
if (textNode.hasFormat('code')) return;
|
if (textNode.hasFormat('code')) return;
|
||||||
if (!needsHighlight(text)) return;
|
if (!needsHighlight(text)) return;
|
||||||
|
if (textNode.getStyle()) return;
|
||||||
|
|
||||||
const parent = textNode.getParent();
|
const parent = textNode.getParent();
|
||||||
if (!parent) return;
|
if (!parent) return;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect, useRef } from 'react';
|
||||||
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
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([
|
const PYTHON_KEYWORDS = new Set([
|
||||||
'False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue',
|
'False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue',
|
||||||
@@ -11,12 +11,30 @@ const PYTHON_KEYWORDS = new Set([
|
|||||||
|
|
||||||
const Python3HighlightPlugin = () => {
|
const Python3HighlightPlugin = () => {
|
||||||
const [editor] = useLexicalComposerContext();
|
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(() => {
|
useEffect(() => {
|
||||||
return editor.registerNodeTransform(TextNode, (textNode: TextNode) => {
|
return editor.registerNodeTransform(TextNode, (textNode: TextNode) => {
|
||||||
|
if (isPastingRef.current) return;
|
||||||
|
|
||||||
const text = textNode.getTextContent();
|
const text = textNode.getTextContent();
|
||||||
|
|
||||||
if (textNode.hasFormat('code')) return;
|
if (textNode.hasFormat('code')) return;
|
||||||
|
if (textNode.getStyle()) return;
|
||||||
if (!needsHighlight(text)) return;
|
if (!needsHighlight(text)) return;
|
||||||
|
|
||||||
const parent = textNode.getParent();
|
const parent = textNode.getParent();
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ const codeTemplate = {
|
|||||||
const CodeExecution: FC<CodeExecutionProps> = ({ options }) => {
|
const CodeExecution: FC<CodeExecutionProps> = ({ options }) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const form = Form.useFormInstance()
|
const form = Form.useFormInstance()
|
||||||
const values = Form.useWatch([], form) || {}
|
|
||||||
|
|
||||||
const handleRefresh = () => {
|
const handleRefresh = () => {
|
||||||
const code = form.getFieldValue('code') || ''
|
const code = form.getFieldValue('code') || ''
|
||||||
@@ -66,7 +65,6 @@ const CodeExecution: FC<CodeExecutionProps> = ({ options }) => {
|
|||||||
form.setFieldValue('code', newTemplate)
|
form.setFieldValue('code', newTemplate)
|
||||||
}
|
}
|
||||||
const handleChangeLanguage = (value: string) => {
|
const handleChangeLanguage = (value: string) => {
|
||||||
form.setFieldValue('code', codeTemplate[value as keyof typeof codeTemplate])
|
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
input_variables: [{ name: 'arg1' }, { name: 'arg2' }],
|
input_variables: [{ name: 'arg1' }, { name: 'arg2' }],
|
||||||
code: codeTemplate[value as keyof typeof codeTemplate]
|
code: codeTemplate[value as keyof typeof codeTemplate]
|
||||||
@@ -109,8 +107,12 @@ const CodeExecution: FC<CodeExecutionProps> = ({ options }) => {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<Form.Item name="code" noStyle>
|
<Form.Item noStyle shouldUpdate={(prev, curr) => prev.language !== curr.language}>
|
||||||
<Editor size="small" language={values.language} />
|
{() => (
|
||||||
|
<Form.Item name="code" noStyle>
|
||||||
|
<Editor size="small" language={form.getFieldValue('language')} />
|
||||||
|
</Form.Item>
|
||||||
|
)}
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Space>
|
</Space>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user