Bizarre tab/diagnostic interaction

In my IDE, if a line starts with a tab character, then a word, and that line is marked as an error (including the tab) using diagnostics, and I put my cursor after the tab and press a key, the cursor first moves to the end of the line before inserting the character. This does not happen if the line does not start with tab, or is not marked as an error, or if the tab is not included in the error diagnostic! Also this behavior happens at the start of any word in the line, not just the one after the tab, but not in the middle of any word. I’ve tried removing all extensions I could, including any odd keymaps or tab-related ones.

You can try it here: TRS-80 IDE Insert a new line with tab, then “foo” (no quotes), then move off the line and back on (to trigger the diagnostic), put your cursor before “foo”, then press a letter.

I wanted to make a simple reproducible case for this, so I tried the “Try” editor, but I get the error “SyntaxError: The requested module ‘./mods/@codemirror-lint.js’ does not provide an export named ‘Diagnostic’”. (See link below).

Any idea how to demo this code in Try? Or other stuff I should check out to debug the actual problem?

Thank you!

Lawrence

https://codemirror.net/try/?c=aW1wb3J0IHtiYXNpY1NldHVwLCBFZGl0b3JWaWV3fSBmcm9tICJjb2RlbWlycm9yIgppbXBvcnQge2phdmFzY3JpcHR9IGZyb20gIkBjb2RlbWlycm9yL2xhbmctamF2YXNjcmlwdCIKaW1wb3J0IHtEaWFnbm9zdGljLCBzZXREaWFnbm9zdGljc30gZnJvbSAiQGNvZGVtaXJyb3IvbGludCIKCm5ldyBFZGl0b3JWaWV3KHsKICBkb2M6ICJcdGZvbyBmb29cbiIsCiAgZXh0ZW5zaW9uczogW2Jhc2ljU2V0dXAsIGphdmFzY3JpcHQoKV0sCiAgcGFyZW50OiBkb2N1bWVudC5ib2R5Cn0pCgp0aGlzLnZpZXcuZGlzcGF0Y2goc2V0RGlhZ25vc3RpY3ModGhpcy52aWV3LnN0YXRlLCBbCiAgewogICAgZnJvbTogMCwKICAgIHRvOiA4LAogICAgc2V2ZXJpdHk6ICJlcnJvciIsCiAgfQpdKSk7Cg==

Write JavaScript, not TypeScript. Diagnostic is a type, so you can’t import it without TypeScript.

It would also be useful to know which browser this happens in.

Thank you for pointing out the type import! I got the bug to reproduce, see below. It happens in Chrome on Mac. It does not happen in Firefox on Mac. Place your cursor at the beginning of either “foo” and type “x”, and the cursor will jump to the end of the line before inserting the “x”. The highlightSelectionMatches() plugin seems to be the culprit. I’ve not dug into it yet.

https://codemirror.net/try/?c=aW1wb3J0IHtiYXNpY1NldHVwLCBFZGl0b3JWaWV3fSBmcm9tICJjb2RlbWlycm9yIgppbXBvcnQge3NldERpYWdub3N0aWNzfSBmcm9tICJAY29kZW1pcnJvci9saW50IgppbXBvcnQge2hpZ2hsaWdodFNlbGVjdGlvbk1hdGNoZXN9IGZyb20gIkBjb2RlbWlycm9yL3NlYXJjaCIKCmNvbnN0IHZpZXcgPSBuZXcgRWRpdG9yVmlldyh7CiAgZG9jOiAiXHRmb28gZm9vXG4iLAogIGV4dGVuc2lvbnM6IFsKICAgIGJhc2ljU2V0dXAsCiAgICBoaWdobGlnaHRTZWxlY3Rpb25NYXRjaGVzKHsKICAgICAgaGlnaGxpZ2h0V29yZEFyb3VuZEN1cnNvcjogdHJ1ZSwKICAgIH0pLAogIF0sCiAgcGFyZW50OiBkb2N1bWVudC5ib2R5Cn0pCgp2aWV3LmRpc3BhdGNoKHNldERpYWdub3N0aWNzKHZpZXcuc3RhdGUsIFsKICB7CiAgICBmcm9tOiAwLAogICAgdG86IDgsCiAgICBzZXZlcml0eTogImVycm9yIiwKICB9Cl0pKTsK

Note that setting highlightWordAroundCursor to false makes the bug go away. I just poked around the code of that plug-in and don’t see a way for it to update the selection, it only adds decoration. Are the two decorations (word highlight and error highlight) conflicting?

Would you like me to open a Github issue for this? Happy to do it.

This seems to be a Chrome bug. Can be reproduced with a very simple piece of HTML.

<div style="white-space: pre" contenteditable=true><span>	<span>foo</span></span></div>

Putting the cursor before foo and typing inserts content at the end of the line. I’ve opened an issue in the Chrome bug tracker.