demo · v139

Contenteditable Drift

Pre-v139, an editable element absorbed scroll-anchor priority just by being focused. If the document grew offscreen above the caret, the browser tried to keep the whole editable in view — yanking the caret. v139 picks the deepest onscreen element within the priority scope, killing the drift. Click into the editor, then insert text far above.

caret position: not measured

large contenteditable (scrolls internally)

placeholder content above (this becomes 'offscreen' once you scroll down)

more placeholder

more placeholder

more placeholder

more placeholder

more placeholder

more placeholder

more placeholder

more placeholder

EDIT HERE — put your cursor in this paragraph, then click "Insert paragraph above". With the v139 fix, your cursor stays where you put it. Pre-v139, the editable as a whole was anchored, so this paragraph slid out of view.

more placeholder

more placeholder

more placeholder

what the fix changes

Scroll anchoring picks an element to stay visually fixed when layout shifts. Pre-v139 the algorithm preferred focused editables and find-in-page highlights as the anchor, but it picked the whole editable element — even a multi-screen-tall one. If content inserted upstream made it shift, the browser scrolled so the editable's top stayed in place, which pushed the caret offscreen. v139 keeps the priority bias but now picks the deepest onscreen element within that editable as the anchor. Result: edits near the caret stay stable.

see also