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

fix(react-editor): reset focus offset when triple clicking #4512

Merged
merged 2 commits into from
Sep 13, 2021

Conversation

bytrangle
Copy link
Contributor

@bytrangle bytrangle commented Sep 13, 2021

Description

In my triple click fix, I reset the focusNode but forgot to reset the related focusOffset value. As a result, the Slate range computed from DOM selection is still not correct and cause a number of issues when users try to transform a block by applying formatting or deleting.

Issue
Fixes: #4492

Example
Before the fix

2021-09-08--16-22-05__triple-click-on-marks.mp4

After the fix

  • Selecting a block by clicking and dragging, then hitting Backspace should remove that block.
2021-09-13--17-57-12__select-element-delete.mp4
  • Selecting a block through clicking and hitting Shift + Arrow down, then hitting Backspace should remove that block.
2021-09-13--18-01-13__click-shift-arrow-down.mp4
  • Triple click at the beginning of a Mark should delete the whole block that contains that Mark.
2021-09-13--18-01-38__triple-click-at-mark.mp4

Context
Here's what I did:

  • Refactor the condition for checking for triple clicking or Shift + down arrow. Chrome seems to have issue with selection that is not clicking and dragging.
  • Rewrite the code for getting focusNode to avoid error thrown when accessing property of a potentially null value.
  • Add logic for getting the DOM Text node of the focusNode object.

Checks

  • The new code matches the existing patterns and styles.
  • The tests pass with yarn test.
  • The linter passes with yarn lint. (Fix errors with yarn fix.)
  • The relevant examples still work. (Run examples with yarn start.)
  • You've added a changeset if changing functionality. (Add one with yarn changeset add.)

@changeset-bot
Copy link

changeset-bot bot commented Sep 13, 2021

⚠️ No Changeset found

Latest commit: ed237a1

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.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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

if (innermostFocusElement) {
const lastTextNode = innermostFocusElement.childNodes[0]
focusNode = lastTextNode
// if (anchorNode!.nodeType === 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just remove the commented out code.

Copy link
Contributor Author

@bytrangle bytrangle Sep 13, 2021

Choose a reason for hiding this comment

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

I'm not sure what you meant. Which part is the comment-out code?
EDIT: Okay, I saw it.

@dylans dylans merged commit cc7cb62 into ianstormtaylor:main Sep 13, 2021
@dylans
Copy link
Collaborator

dylans commented Sep 13, 2021

Sigh, I merged without a changeset. opening a PR for the changeset now.

@bytrangle
Copy link
Contributor Author

bytrangle commented Sep 13, 2021

I forgot to ask: When should I add a changeset, and when should I not? I thought this change is a correction for my flawed triple click fix, so I didn't think of adding a changeset.

@dylans dylans mentioned this pull request Sep 13, 2021
jaked added a commit to jaked/slate that referenced this pull request Oct 10, 2021
dylans pushed a commit that referenced this pull request Oct 11, 2021
…4588)

* revert #4455 / #4512; fix triple-click by unhanging range with void

* added changeset
@github-actions github-actions bot mentioned this pull request Oct 11, 2021
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.

Deleting a selection only deletes the last element
2 participants