Native browser cursor "jumps" when there is a widget at the same position

Probably related to this issue: Cursor jumps from the line end to widget decorator , but the “key” property solution does not work.

Minimal example:!/apple-veil

To reproduce:

  1. Click on the last empty line in the document
  2. Wait 3 seconds for the “fake” cursor to appear
  3. Type something quickly, for example “123123”

Notice that native browser cursor is at the end of the line, but as soon as the “fake” cursor starts to catch up, browser cursor jumps to it and follows it.

  • The problem ONLY happens when you start typing on the empty line. At the end of an existing line, or in the middle of it it works fine (cursor does not jump)
  • The problem happens in Chrome, but does not happen in Firefox
  • The problem goes away if you comment out the .widget() call
  • The problem goes away if you add +1 (but not -1) to the widget position

I can confirm I’m having the same issue. This seems related to this Chrome bug possibly?

Does anyone have any specific fixes/suggestions here?

Yes, that appears to be the same issue as #710. I’ve attached a patch there, which seems to help for this case as well — if you are able to test it in the coming days to verify that it works for you, that’d be very useful.

This is the error I get if I use the latest master branch prosemirror-view in my project. It happens when I do the following:

  1. Click on the last empty line in the document.
  2. Wait 3 seconds for the “fake” cursor to appear
  3. Type any character

The character shows up in the editor, and the “fake” cursor (widget) is in the right place (after the character), but the native browser cursor stays in the beginning of the line (before the character). If I continue typing, the error is thrown for every character I type, the browser cursor stays in the beginning of the line, and the “fake” cursor properly moves (always at the end of the line).

Happens in Chrome and Firefox.

That error, especially since it also happens in Firefox, seems like it might not be related to my changes. Are you sure it isn’t something caused by your code?

Well, the error is not present when I’m switching back to the latest prosemirror-view release version. But maybe your patch exposed an issue in my code? I will investigate.

Strange. It’s kind of by definition impossible for position 0 to be out of range, so it seems something is going very wrong. I am not able to reproduce the error or figure out why it’s happening right now.