mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Desktop: Rich Text Editor: Preserve cursor location when updating editor content (#10781)
This commit is contained in:
parent
819de1cfa4
commit
40bd2dfe21
@ -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 = {
|
||||
|
Loading…
Reference in New Issue
Block a user