Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desktop: Fixes #8960: Fix cursor jump in the Rich Text Editor on sync #10558

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1240,8 +1240,11 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => {
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
async function onKeyDown(event: any) {
async function onKeyDown(event: KeyboardEvent) {
// Although the onChangeHandler also marks the editor content as changed, it's important
// to set changed to true as soon as possible. See https://github.com/laurent22/joplin/issues/8960.
props.setChanged(true);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What even are actually processed by this handler? Would it be triggered by non-printable keys too? Because in that case the note wouldn't actually be changed


// It seems "paste as text" is handled automatically on Windows and Linux,
// so we need to run the below code only on macOS. If we were to run this
// on Windows/Linux, we would have this double-paste issue:
Expand Down
3 changes: 2 additions & 1 deletion packages/app-desktop/gui/NoteEditor/NoteEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function NoteEditor(props: NoteEditorProps) {

const effectiveNoteId = useEffectiveNoteId(props);

const { formNote, setFormNote, isNewNote, resourceInfos } = useFormNote({
const { formNote, setFormNote, isNewNote, resourceInfos, setChanged } = useFormNote({
syncStarted: props.syncStarted,
decryptionStarted: props.decryptionStarted,
noteId: effectiveNoteId,
Expand Down Expand Up @@ -396,6 +396,7 @@ function NoteEditor(props: NoteEditorProps) {
whiteBackgroundNoteRendering,
onChange: onBodyChange,
onWillChange: onBodyWillChange,
setChanged,
onMessage: onMessage,
content: formNote.body,
contentMarkupLanguage: formNote.markup_language,
Expand Down
1 change: 1 addition & 0 deletions packages/app-desktop/gui/NoteEditor/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export interface NoteBodyEditorProps {
contentKey: string;
contentMarkupLanguage: number;
contentOriginalCss: string;
setChanged(changed: boolean): void;
onChange(event: OnChangeEvent): void;
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
onWillChange(event: any): void;
Expand Down
7 changes: 7 additions & 0 deletions packages/app-desktop/gui/NoteEditor/utils/useFormNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,17 @@ export default function useFormNote(dependencies: HookDependencies) {
}
}, [setFormNote]);

const setChanged = useCallback((changed: boolean) => {
if (formNoteRef.current.hasChanged !== changed) {
onSetFormNote({ ...formNoteRef.current, hasChanged: changed });
}
}, [onSetFormNote]);

return {
isNewNote,
formNote,
setFormNote: onSetFormNote,
setChanged,
resourceInfos,
};
}
Loading