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

[WIP] Add onMouseMove method; Fix incorrect selection when click and drag move #2104

Closed
wants to merge 8 commits into from

Conversation

zhujinxuan
Copy link
Contributor

@zhujinxuan zhujinxuan commented Aug 21, 2018

Is this adding or improving a feature or fixing a bug?

bug

What's the new behavior?

If user click and drag, and an selection event is fired during dragging. Then we shall expect an extended range instead of an collapsed range. When the browser accidentally causes an collapsed range, then we shall extend it to the new selection instead of select.

Have you checked that...?

  • 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 prettier.)
  • The relevant examples still work. (Run examples with yarn watch.)

Does this fix any issues or need any specific reviewers?

Fixes: #1969
Reviewers: @

@zhujinxuan zhujinxuan changed the title Add onMouseMove method; Fix 1969 [WIP] Add onMouseMove method; Fix 1969 Aug 21, 2018
@zhujinxuan zhujinxuan changed the title [WIP] Add onMouseMove method; Fix 1969 [WIP] Add onMouseMove method; Fix incorrect selection when click and drag move Aug 21, 2018
@codecov
Copy link

codecov bot commented Aug 21, 2018

Codecov Report

Merging #2104 into master will decrease coverage by 0.11%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2104      +/-   ##
==========================================
- Coverage   69.54%   69.42%   -0.12%     
==========================================
  Files          73       73              
  Lines        5437     5446       +9     
==========================================
  Hits         3781     3781              
- Misses       1656     1665       +9
Impacted Files Coverage Δ
...ckages/slate-react/src/constants/event-handlers.js 100% <ø> (ø) ⬆️
packages/slate-react/src/plugins/after.js 4.42% <0%> (-0.14%) ⬇️
packages/slate-react/src/components/content.js 23.76% <0%> (-0.24%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ba9b791...27f0084. Read the comment docs.

@zhujinxuan zhujinxuan changed the title [WIP] Add onMouseMove method; Fix incorrect selection when click and drag move Add onMouseMove method; Fix incorrect selection when click and drag move Aug 21, 2018
@ianstormtaylor
Copy link
Owner

Hey @zhujinxuan, this sounds like a good call. Can you explain exactly what's going on here in terms of the events that are firing in the browser? I'm not sure I understand.

@zhujinxuan
Copy link
Contributor Author

@ianstormtaylor Sometimes, when you press and drag from a empty block start. The browser will fire onSelection events with collapsed selection, rather than selection extended from the mouse down selection. (#1969)

This PR tries to fix the problem that, for any onSelection event during onMouseMove, if the left key is pressed when mouse moves (click and drag) and if the previous selection and current selection is both collapsed, we identify that the bug occurs. Then we fix the selection with extending between previous and current selection.

@ianstormtaylor
Copy link
Owner

@zhujinxuan is this something that other editors experience? I remember someone mentioning that the reason this happens might be due to the zero-width spaces. But in #1969 it sounds like there might even be cases where this happens without the zero-width spaces?

I'd like to have more research before we merge this, because having a constant timeout timer for any mouse movements (with a magic 24ms delay) seems like something that should be a last resort for us.

@zhujinxuan
Copy link
Contributor Author

@ianstormtaylor I can only reproduce it in the slate. I can only reproduce #1969 (comment) but unable to reproduce #1969 (comment). (only able to reproduce the zero-width condition but not the second one).

Can we just change this PR to add onMouseMove handlers (without adding the timer to the core)?
Then a temporary solution can be provided as a plugin.

@zhujinxuan
Copy link
Contributor Author

zhujinxuan commented Aug 22, 2018

@ianstormtaylor BTW, the timer is initialized only on (pressed & mouse move). Because the setTimeout is called only when (event.buttons % 2 == 1) (which means left mouse button is pressed)

But I agree that the timer solution is an ugly solution.

@zhujinxuan zhujinxuan changed the title Add onMouseMove method; Fix incorrect selection when click and drag move [WIP] Add onMouseMove method; Fix incorrect selection when click and drag move Aug 24, 2018
@zhujinxuan zhujinxuan changed the title [WIP] Add onMouseMove method; Fix incorrect selection when click and drag move Add onMouseMove method; Fix incorrect selection when click and drag move Aug 24, 2018
@zhujinxuan zhujinxuan changed the title Add onMouseMove method; Fix incorrect selection when click and drag move [WIP] Add onMouseMove method; Fix incorrect selection when click and drag move Aug 24, 2018
@zhujinxuan
Copy link
Contributor Author

Will use another PR to fix the problem

@zhujinxuan zhujinxuan closed this Sep 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clicking on a zero-width node and dragging does not select text
2 participants