Skip to content

fix: editor ignoring changes #102

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

Merged
merged 1 commit into from
Jun 28, 2024
Merged

fix: editor ignoring changes #102

merged 1 commit into from
Jun 28, 2024

Conversation

Nemikolh
Copy link
Member

@Nemikolh Nemikolh commented Jun 27, 2024

This PR fixes a bug reported by @SamVerschueren where the editor sometimes remove a changes that was just made.

It's caused by the debounce which delay when the document is updated. However, the document might also be updated in the meantime by something else: here the scroll.

When the scroll position changes, the document will be updated which then cause the useEffect hook which calls setEditorDocument to be called and it would then think that the document has changed given the editor state content and the document content are different. So it resets the cursor to the beginning which is incorrect. With this PR, we ignore external scroll position changes as they are expected to be entirely controlled by the editor.

Note that there still could be a bug if an external component was also editing the editor state as if you keep pressing the same key you essentially prevent the document from ever being updated.

Before:

now.webm

After:

after.webm

Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

changeset-bot bot commented Jun 27, 2024

⚠️ No Changeset found

Latest commit: f7aa32f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@SamVerschueren SamVerschueren left a comment

Choose a reason for hiding this comment

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

Great find 😱 ! Now it all makes sense why this happened. Because when I pasted something that was larger than the edtior size, scrollbars appeared causing it to reset it probably.

@Nemikolh
Copy link
Member Author

@SamVerschueren Exactly! It's so subtle, it's crazy 😆

@Nemikolh Nemikolh merged commit 0f01e31 into main Jun 28, 2024
9 checks passed
@Nemikolh Nemikolh deleted the joan/fix-editor-bug branch June 28, 2024 08:29
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.

2 participants