1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-29 22:48:10 +02:00

Desktop: Rich Text Editor: Preserve cursor location when updating editor content (#10781)

This commit is contained in:
Henry Heino
2024-07-28 06:49:51 -07:00
committed by GitHub
parent 819de1cfa4
commit 40bd2dfe21

View File

@@ -942,6 +942,13 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => {
);
if (cancelled) return;
// Use an offset bookmark -- the default bookmark type is not preserved after unloading
// and reloading the editor.
// See https://github.com/tinymce/tinymce/issues/9736 for a brief description of the
// different bookmark types. An offset bookmark seems to have the smallest change
// when the note content is updated externally.
const offsetBookmarkId = 2;
const bookmark = editor.selection.getBookmark(offsetBookmarkId);
editor.setContent(awfulInitHack(result.html));
if (lastOnChangeEventInfo.current.contentKey !== props.contentKey) {
@@ -960,6 +967,9 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => {
// times would result in an empty note.
// https://github.com/laurent22/joplin/issues/3534
editor.undoManager.reset();
} else {
// Restore the cursor location
editor.selection.bookmarkManager.moveToBookmark(bookmark);
}
lastOnChangeEventInfo.current = {