question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use native selectionchange event as opposed to React's onSelect

See original GitHub issue

I 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:

  1. User types
  2. Some kind of polling mechanism sets of some async actions, (in my case this would be an autosaving service)
  3. User starts highlighting text
  4. mid-highlight a prop gets updated because of the async autosave call
  5. Editor rerenders and resets the selection, causing it to collapse

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
YurkaninRyancommented, Sep 19, 2017

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 a mousedown event, set a flag that allows for that selection change event to make changes. When your editor fires mouseup set that flag to false. When selectionchange fires, and the editor is the active element, create a selection state, and use change’s select to set it.

3reactions
YurkaninRyancommented, Sep 18, 2017

I’m going to try to get it in there!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found