-
Notifications
You must be signed in to change notification settings - Fork 560
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
Fix erratic cursor jumps to last line #1193
Conversation
Deprecated
Three kinds of content updates: 1. Another note was selected 2. The content was changed locally 3. A remote change came in from the server
I tested this out and am not seeing the cursor jump any longer 👍 But, I've found that I can get a crash. It's probably not a normal use case though :) It also may be unrelated to this PR. If you type really fast on a line and keep selecting the text you just typed with the mouse, it'll eventually crash. https://cloudup.com/co8U9-Abcgn
|
@roundhill I can confirm that that is unrelated to these updates. I've made that happen before when I was first testing trying to identify the cursor jumping issue. I just double-checked on the production version of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested well for me! I'm afraid I'm out of time for the day so didn't have much time to review the code.
Thank you @roundhill and @qualitymanifest for testing and confirming 🙏 |
* Fix cursor position jump when setting new EditorState * Use const for newSelectionState * Create new editor state preserving undo stack * Remove use of componentWillReceiveProps() Deprecated * Move and rename focus calculating function * Return the new, merged selection state * Add hasRemoteUpdate hint * Rename `noteUpdated` action for clarity * Handle content updates differently Three kinds of content updates: 1. Another note was selected 2. The content was changed locally 3. A remote change came in from the server * Add tests and adjust for new upper bounds * Fix revision selection * Fix New Note * Remove unneeded loadNotes on newNote * Fix state bug when adding new note after trashing * Fix bug when clicking checkbox * Fix bug when making new note when editor has focus
* Fix cursor position jump when setting new EditorState * Use const for newSelectionState * Create new editor state preserving undo stack * Remove use of componentWillReceiveProps() Deprecated * Move and rename focus calculating function * Return the new, merged selection state * Add hasRemoteUpdate hint * Rename `noteUpdated` action for clarity * Handle content updates differently Three kinds of content updates: 1. Another note was selected 2. The content was changed locally 3. A remote change came in from the server * Add tests and adjust for new upper bounds * Fix revision selection * Fix New Note * Remove unneeded loadNotes on newNote * Fix state bug when adding new note after trashing * Fix bug when clicking checkbox * Fix bug when making new note when editor has focus Co-authored-by: cdr <qualitymanifest@gmail.com>
Closes #1185
Based on @qualitymanifest's work in #1192
Some background on the issue is detailed in #1192 (comment).
TODO
In relation to #36
Before this PR, the cursor just moved to the end when a remote change came in. After this PR, the cursor will be restored to the same paragraph/character indices. So definitely a UX improvement. However, we aren't doing any calculation based on the Simperium patch, which means it doesn't do anything fancy like advance the cursor six characters if six characters were inserted before it.
Technical notes
It seemed like @qualitymanifest's approach might be sufficient (as long as the undo stack was preserved 23d10c4), but it turned out that it would cause flickers and data loss if CJK typing was involved 😬
To protect CJK typing, we absolutely need a way to distinguish between
content
updates that come from local changes vs. those coming remotely from the server. I did this by adding a property to the Redux state b8c71f2.Combined with a new
noteId
prop on the component, we can now distinguish between the three kinds ofcontent
updates:a. Another note was selected
b. The content was changed locally
c. A remote change came in from the server
They will be handled as such: (a) will recreate an editorState from scratch, (b) will be ignored (so the internal state in DraftJS will stay in control), and (c) will be sent through @qualitymanifest's special focus handling.
Testing
Some things to try: