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

Conversation

personalizedrefrigerator
Copy link
Collaborator

Summary

This pull request tries to fix #8960 (#10449 seems to have failed to do so). It does so by marking the current note as changed immediately after a key is pressed (rather than waiting for an onChange event to be received).

In particular, this pull request focuses on the Rich Text Editor because it's simpler to implement and I am not certain that this will fix the issue. If it does, a similar change can be made to the beta and legacy markdown editors.

May fix #8960.

Rationale

Logs collected before #10449 was merged suggest that #8960 was caused by a race condition where:

  1. The user types something.
  2. Sync completes. The form note updates and doesn't match the editor's content. The editor isn't marked as changed by the user, so is updated. This moves the cursor to the start of the note.
  3. The note is marked as changed by step 1, too late to stop the editor's contents from being replaced by step 2.

#10449 eliminated the need for a React re-render between the editor's change event and marking the editor's content as changed (in step 3). If #8960 is still happening because the change event isn't firing soon enough after the editor is changed, marking the editor as changed on key down events might fix the issue.

Testing plan

Regression testing:

  1. Create a new note.
  2. Type several paragraphs in the Rich Text editor.
  3. Switch notes.
  4. Switch back to the original note.
  5. Verify that changes made to the original were saved.

This has been tested successfully on Ubuntu 24.04.

…r on sync

Marks the current note as changed immediately after pressing a key.
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

@laurent22
Copy link
Owner

Is the cursor jump an issue in the RTE too? I don't remember having had this problem in this editor

@personalizedrefrigerator
Copy link
Collaborator Author

Is the cursor jump an issue in the RTE too? I don't remember having had this problem in this editor

Users in #8960 listed the issue as occurring in the RTE. On reflection, however, we only have confirmation that this is still an issue in the legacy markdown editor. As such, a better approach could be something similar to this, but for CodeMirror 5.

I'm closing this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cursor jumps to top of editor when typing
2 participants