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

Fire an event on caret position change #111

Closed
SebastianZ opened this issue Oct 23, 2016 · 5 comments
Closed

Fire an event on caret position change #111

SebastianZ opened this issue Oct 23, 2016 · 5 comments

Comments

@SebastianZ
Copy link

For a syntax highlighter I'd like to get the current caret position while pressing keys on the keyboard.

I tried to use the keydown event and the legacy keypress event, but they are fired continuously before the caret position changes. And the keyup event is only fired once after the key is released. Besides that there is also the input event, though that's just fired on text input and not when the text cursor changes.

So, what is missing is an event that is either

  1. fired continuously while a key is pressed like input but even when no input happens like keydown, or
  2. fired everytime right after the caret position changed.

I slightly prefer the second solution, because it allows to get the caret position even on other input types like mouse events.

Sebastian

@garykac
Copy link
Member

garykac commented Jan 25, 2017

This feature request is unlikely to go forward as it doesn't appear to be broadly useful, and there is active pushback to adding any new events.

Since I have not heard of any other requests for this, my recommendation would be to use the workaround suggested on the stackoverflow page you link to.

Having said that, since this seems editing (contenteditable) related, you might want to see if there is any interest from other developers of text editors.
@johanneswilm (editing spec editor), do you have any comments on this?

@dziesig
Copy link

dziesig commented Nov 18, 2018

Well, even though it is almost two years since SebastianZ requested this event, I, too, could really use such an event. Since it appears that there are only two users in the world interested in this, it is off to the workaround I go. ;)

@SebastianZ
Copy link
Author

@dziesig wrote:

... it is off to the workaround I go.

Which workaround is that?

Sebastian

@garykac garykac closed this as completed Jul 23, 2020
@rniwa
Copy link

rniwa commented Aug 10, 2020

Why not listen for selectionchange event? FWIW, this is an issue which should be tracked by https://github.com/w3c/selection-api.

@SebastianZ
Copy link
Author

Looks like the selectionchange event serves my use case. Thank you for pointing that out, @rniwa! I didn't know about that event.

Sebastian

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

No branches or pull requests

4 participants