question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Contenteditable causes line jumping when gaining focus with keyboard.

See original GitHub issue

With 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

  1. Visit: https://codepen.io/billiam/pen/abBNLOz
  2. Scroll to end of codemirror element, and select last line
  3. Type tab to focus on next input or click input element, blurring codemirror
  4. 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:

I thought this might be a regression of https://github.com/codemirror/CodeMirror/issues/3979 but I’m not sure.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
marijnhcommented, Feb 8, 2021

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.

0reactions
marijnhcommented, Feb 12, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found