Use native selectionchange event as opposed to React's onSelect
See original GitHub issueI want to take a shot at implementing this but before I do I want to see what people think.
Currently, I believe Slate is relying on React’s onSelect
event. The problem with that is that it only fires when the user releases their mouse. This causes a desync between the selection state in the editor state and what is actually on the screen mid-highlight. Consider this workflow:
- User types
- Some kind of polling mechanism sets of some async actions, (in my case this would be an autosaving service)
- User starts highlighting text
- mid-highlight a prop gets updated because of the async autosave call
- Editor rerenders and resets the selection, causing it to collapse
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:16 (10 by maintainers)
Top Results From Across the Web
Document: selectionchange event - Web APIs | MDN
The selectionchange event of the Selection API is fired when the current Selection of a Document is changed.
Read more >OnChange event using React JS for drop down - Stack Overflow
The change event is triggered on the <select> element, not the <option> element. However, that's not the only problem.
Read more >Events Available for TinyMCE | Docs
List of common editor events. ... The following examples illustrate how to use supported native events, editor core events, and plugin events with...
Read more >ion-select: Select One or Multiple Value Boxes or Placeholders
ion-select is represented by selected value(s), or a placeholder, and dropdown icon. When you tap select, a dialog box appears with an easy...
Read more >Simulating Events in Angular Unit Tests | by Netanel Basal
It will invoke the event handler only if it was declared on the native element by using Angular event bindings, the @HostListener() or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone that comes here and has a similar problem here’s the status, i’m trying to get this in at React core, and i’m waiting for some feedback on my approach from the React team.
But, if you need to fix this problem now, here is what you can do.
Outside your editor, when your editor mounts attach a
selectionchange
event listener. When you’re editor fires amousedown
event, set a flag that allows for that selection change event to make changes. When your editor firesmouseup
set that flag to false. Whenselectionchange
fires, and the editor is the active element, create a selection state, and use change’s select to set it.I’m going to try to get it in there!