Contenteditable causes line jumping when gaining focus with keyboard.
See original GitHub issueWith the contenteditable input style, focusing CodeMirror with the tab key causes the active line jumps a about a page upwards
Browser
Occurs in:
Linux & Win Chrome 88.0.4324.146 (Official Build) (64-bit) Win Edge 88.0.705.63 (Official build) (64-bit)
Works correctly in Firefox 85.0 (64-bit)
Reproduction
- Visit: https://codepen.io/billiam/pen/abBNLOz
- Scroll to end of codemirror element, and select last line
- Type tab to focus on next input or click input element, blurring codemirror
- Type shift+tab to focus codemirror again
Expected
Previously active line is still active
Actual behavior
A line that was not visible before focusing codemirror scrolls into focus and is selected instead.
https://user-images.githubusercontent.com/242008/107131772-1ec13780-689f-11eb-9bbc-ddccb77778e6.mp4
Other variations:
- Works as expected with textarea input style: https://codepen.io/billiam/pen/ExNKwgj
- Weirdly, it works as expected with
lineNumbers: true
: https://codepen.io/billiam/pen/qBqZPNZ - Does not work with active-line / styleActiveLine disabled, but is slightly different (always scrolls to the top): https://codepen.io/billiam/pen/JjbXrbX
I thought this might be a regression of https://github.com/codemirror/CodeMirror/issues/3979 but I’m not sure.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Contenteditable causes line jumping when gaining focus with ...
Actual behavior. A line that was not visible before focusing codemirror scrolls into focus and is selected instead.
Read more >Why Is My Contenteditable caret Jumping to the End in Chrome?
The problem is that your contenteditable element is a div , which by default is display: block . This is what causes your...
Read more >The Curious Case of Cursor Jumping - Mutually Human
Cursor jumping is simply when the cursor jumps from one location to another, unexpectedly, while the user is typing into a text field....
Read more >Contenteditable on Android is the Absolute Worst - Discuss
I haven't seen the cursor jumps due to cursor wrappers. If you can create a minimal (and reasonable) script that causes this effect...
Read more >new line in a contentEditable div - Google Groups
If i insert a line break into this contentEditable div : ... Even Google still makes a mess of it when using content-editable,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I suppose what’s happening is that the browser puts the selection at the start of the editable element (which, since the document is viewported, would be about a page up from the top of the visible content). Browsers don’t really keep a ‘current selection’ for unfocused elements, so they just put it at their start when the focus is moved in via the keyboard.
Okay, right, CM6 jumps back to the start of the document, but not to an arbitrary start of the viewport. I’m not entirely sure if this we should be overriding that native behavior.