fix: selectionchange should triggered by the user event rather than api event #5777
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The PR is to completely solve issue1 in #5771 by controlling the triggering behavior of users.
inherited from #5772 . Due to uncertainty about the side effects brought by this PR, it is temporarily submitted as a draft PR. In this #5772, in order to solve issue1 inside, I added a variable named
onDOMSelectionChangeThrottleTime
.Then, I found that when this variable is set to the extremely small value of 0, there is still a 20-30% probability that the selection area is invalid when the QPS is 50, and a second click is required to select the selection area.
In the past, when a collaborator selected a certain block for editing, the
scheduleOnDOMSelectionChange
of the other collaborators were actually being rendered all the time. However, the selection area of one collaborator should not be able to affect the selection area of another collaborator. It appears to be a design issue regarding the event stream.Therefore, referring to the event triggering of quill, https://github.com/slab/quill/blob/20f02f55e30ca87c0c539632b36c6c52ca4670eb/packages/quill/src/core/selection.ts#L54-L68
The onClick event was changed to onMouseUp and onMouseDown (the main reason is that the timing of the onClick event is too late. When the onClick event is triggered, the selection area has already changed). And these two events generate a variable mouseDown, which is used to control the triggering of selectionchange. This ensures that only user actions can trigger selectionchange, and API actions cannot actively trigger it.
The
setTimeout
inslate/packages/slate-react/src/components/editable.tsx
Lines 459 to 462 in 5a1c728