From 7fe0d60d8fb1d83193b40c1befb72bf1e91d80d8 Mon Sep 17 00:00:00 2001 From: robin Date: Tue, 18 Jun 2024 16:17:32 +0800 Subject: [PATCH] fix(editor): Fixed the issue of editor focus being lost --- ui/src/components/Editor/ToolBars/image.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ui/src/components/Editor/ToolBars/image.tsx b/ui/src/components/Editor/ToolBars/image.tsx index b4d395e29..4f72e4e1a 100644 --- a/ui/src/components/Editor/ToolBars/image.tsx +++ b/ui/src/components/Editor/ToolBars/image.tsx @@ -110,12 +110,12 @@ const Image = ({ editorInstance }) => { return; } - // const startPos = editor.getCursor(''); codemirror 6 const startPos = editor.getCursor(); const endPos = { ...startPos, ch: startPos.ch + loadingText.length }; editor.replaceSelection(loadingText); + editor.setReadOnly(true); const urls = await upload(fileList).catch((ex) => { console.error('upload file error: ', ex); }); @@ -131,9 +131,10 @@ const Image = ({ editorInstance }) => { if (text.length) { editor.replaceRange(text.join('\n'), startPos, endPos); } else { - // Clear loading text editor.replaceRange('', startPos, endPos); } + editor.setReadOnly(false); + editor.focus(); }; const paste = async (event) => { @@ -155,6 +156,7 @@ const Image = ({ editorInstance }) => { editor.replaceRange(text.join('\n'), startPos, endPos); editor.setReadOnly(false); + editor.focus(); return; }