You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-06 23:56:13 +02:00
Desktop: Fixes #5955: Changing the currently opened note from plugins or the data API does not refresh the note content
This commit is contained in:
@ -76,11 +76,18 @@ function NoteEditor(props: NoteEditorProps) {
|
||||
}, []);
|
||||
|
||||
const effectiveNoteId = useEffectiveNoteId(props);
|
||||
const effectiveNote = props.notes.find(n => n.id === effectiveNoteId);
|
||||
|
||||
const { formNote, setFormNote, isNewNote, resourceInfos } = useFormNote({
|
||||
syncStarted: props.syncStarted,
|
||||
decryptionStarted: props.decryptionStarted,
|
||||
noteId: effectiveNoteId,
|
||||
|
||||
// The effective updated_time property of the note. It may be different
|
||||
// from the last time the note was saved, if it was modified outside the
|
||||
// editor (eg. via API).
|
||||
dbNote: effectiveNote ? { id: effectiveNote.id, updated_time: effectiveNote.updated_time } : { id: '', updated_time: 0 },
|
||||
|
||||
isProvisional: props.isProvisional,
|
||||
titleInputRef: titleInputRef,
|
||||
editorRef: editorRef,
|
||||
@ -120,12 +127,32 @@ function NoteEditor(props: NoteEditorProps) {
|
||||
return async function() {
|
||||
const note = await formNoteToNote(formNote);
|
||||
reg.logger().debug('Saving note...', note);
|
||||
const savedNote: any = await Note.save(note);
|
||||
const noteUpdatedTime = Date.now();
|
||||
|
||||
// First we set the formNote object, then we save the note. We
|
||||
// do it in that order, otherwise `useFormNote` will be rendered
|
||||
// with the newly saved note and the timestamp of that note will
|
||||
// be more recent that the one in the editor, which will trigger
|
||||
// an update. We do not want this since we already have the
|
||||
// latest changes.
|
||||
//
|
||||
// It also means that we manually set the timestamp, so that we
|
||||
// have it before the note is saved.
|
||||
|
||||
setFormNote((prev: FormNote) => {
|
||||
return { ...prev, user_updated_time: savedNote.user_updated_time, hasChanged: false };
|
||||
return {
|
||||
...prev,
|
||||
user_updated_time: noteUpdatedTime,
|
||||
updated_time: noteUpdatedTime,
|
||||
hasChanged: false,
|
||||
};
|
||||
});
|
||||
|
||||
const savedNote = await Note.save({
|
||||
...note,
|
||||
updated_time: noteUpdatedTime,
|
||||
}, { autoTimestamp: false });
|
||||
|
||||
void ExternalEditWatcher.instance().updateNoteFile(savedNote);
|
||||
|
||||
props.dispatch({
|
||||
|
Reference in New Issue
Block a user