mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Desktop: WYSIWYG: Restored focus logic and fixed undo issue
This commit is contained in:
parent
351306eb03
commit
5e5b6cdc42
@ -442,20 +442,36 @@ function NoteText2(props:NoteTextProps) {
|
||||
|
||||
saveNoteIfWillChange(formNote, editorRef, props.dispatch);
|
||||
|
||||
const loadNote = async () => {
|
||||
function handleAutoFocus(noteIsTodo:boolean) {
|
||||
if (!props.isProvisional) return;
|
||||
|
||||
const focusSettingName = noteIsTodo ? 'newTodoFocus' : 'newNoteFocus';
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
if (Setting.value(focusSettingName) === 'title') {
|
||||
if (titleInputRef.current) titleInputRef.current.focus();
|
||||
} else {
|
||||
if (editorRef.current) editorRef.current.execCommand({ name: 'focus' });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function loadNote() {
|
||||
const n = await Note.load(props.noteId);
|
||||
if (cancelled) return;
|
||||
if (!n) throw new Error(`Cannot find note with ID: ${props.noteId}`);
|
||||
reg.logger().debug('Loaded note:', n);
|
||||
initNoteState(n, setFormNote, setDefaultEditorState);
|
||||
};
|
||||
|
||||
handleAutoFocus(!!n.is_todo);
|
||||
}
|
||||
|
||||
loadNote();
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [props.noteId, formNote, waitingToSaveNote]);
|
||||
}, [props.noteId, props.isProvisional, formNote, waitingToSaveNote]);
|
||||
|
||||
const onFieldChange = useCallback((field:string, value:any, changeId: number = 0) => {
|
||||
handleProvisionalFlag();
|
||||
|
@ -415,6 +415,13 @@ const TinyMCE = (props:TinyMCEProps, ref:any) => {
|
||||
|
||||
editor.getDoc().addEventListener('click', onEditorContentClick);
|
||||
|
||||
// Need to clear UndoManager to avoid this problem:
|
||||
// - Load note 1
|
||||
// - Make a change
|
||||
// - Load note 2
|
||||
// - Undo => content is that of note 1
|
||||
editor.undoManager.clear();
|
||||
|
||||
dispatchDidUpdate(editor);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user