fix: unnecessary focus in editor on swr sync (#4215)

This commit is contained in:
M. Palanikannan 2024-04-16 20:35:10 +05:30 committed by GitHub
parent 1549f3a808
commit ec5667194f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -112,12 +112,9 @@ export const useEditor = ({
editor.commands.setContent(value);
const currentSavedSelection = savedSelectionRef.current;
if (currentSavedSelection) {
editor.view.focus();
const docLength = editor.state.doc.content.size;
const relativePosition = Math.min(currentSavedSelection.from, docLength - 1);
editor.commands.setTextSelection(relativePosition);
} else {
editor.commands.focus("end");
}
} catch (error) {
console.error("Error syncing editor content with external value:", error);