Skip to content

Commit

Permalink
fix(editor): Fixed the issue of editor focus being lost
Browse files Browse the repository at this point in the history
  • Loading branch information
robinv8 committed Jun 18, 2024
1 parent 07316da commit 7fe0d60
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ui/src/components/Editor/ToolBars/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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) => {
Expand All @@ -155,6 +156,7 @@ const Image = ({ editorInstance }) => {

editor.replaceRange(text.join('\n'), startPos, endPos);
editor.setReadOnly(false);
editor.focus();

return;
}
Expand Down

0 comments on commit 7fe0d60

Please sign in to comment.