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

Pass the original events or add events types in selectionchange #65

Open
caub opened this issue Feb 9, 2016 · 2 comments
Open

Pass the original events or add events types in selectionchange #65

caub opened this issue Feb 9, 2016 · 2 comments
Labels

Comments

@caub
Copy link

caub commented Feb 9, 2016

selectionchange is really useful, it would be even better if the event parameter of the callback could say more about what triggered the selection change, either passing a MouseEvent, a KeyEvent etc.. or giving a type property to the event

document.addEventListener('selectionchange', e=>{
  if (e instanceof KeyEvent) console.log(e.keyCode) // very useful if I want to act on undo/redo..
  else if (e instanceof MouseEvent) console.log(e.target)// e.target is not really needed
             // since I can use the current Range to know in what elements the selection is
  // ...
});

the idea is to have something like that http://jsfiddle.net/crl/rk6f74tw/12/

@caub
Copy link
Author

caub commented Feb 15, 2016

http://jsfiddle.net/crl/rk6f74tw/14/ for me this is actually better than the current selectionchange event

@caub
Copy link
Author

caub commented Jun 20, 2016

update: I've aslso been in a situation where I need to know a 'target' for the selection change, or other times I needed an event type that triggered that change in selection.

Since selection change is always triggered by another event (I think), wouldn't it be better to include more information in this event?

I've done things like http://jsfiddle.net/rk6f74tw/34/ (check console and select content either in the blue menu or elsewhere) as also a polyfill, but it's of course more heavy

When using user-select:none CSS property, it doesn't work the same on all browsers, I posted bugs on edge and chrome, only Firefox (nightly, because they forgot to enable selectionchange on current releases) doesn't send selectionchange event on element with user-select:none, which makes sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants