Skip to content

Commit

Permalink
Don't short-circuit out of measures when editor elt is visible
Browse files Browse the repository at this point in the history
FIX: Fix an issue where some kinds of relayouts could put the editor
in a state where it believed it wasn't in window, preventing relayout,
though it in fact was.

Closes codemirror/dev#1493
  • Loading branch information
marijnh committed Dec 20, 2024
1 parent 1118dff commit 4e47f5c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/viewstate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ function visiblePixelRange(dom: HTMLElement, paddingTop: number): Rect {
top: top - (rect.top + paddingTop), bottom: Math.max(top, bottom) - (rect.top + paddingTop)}
}

function inWindow(elt: HTMLElement) {
let rect = elt.getBoundingClientRect(), win = elt.ownerDocument.defaultView || window
return rect.left < win.innerWidth && rect.right > 0 &&
rect.top < win.innerHeight && rect.bottom > 0
}

function fullPixelRange(dom: HTMLElement, paddingTop: number): Rect {
let rect = dom.getBoundingClientRect()
return {left: 0, right: rect.right - rect.left,
Expand Down Expand Up @@ -305,7 +311,7 @@ export class ViewState {
this.inView = inView
if (inView) measureContent = true
}
if (!this.inView && !this.scrollTarget) return 0
if (!this.inView && !this.scrollTarget && !inWindow(view.dom)) return 0

let contentWidth = domRect.width
if (this.contentDOMWidth != contentWidth || this.editorHeight != view.scrollDOM.clientHeight) {
Expand Down

0 comments on commit 4e47f5c

Please sign in to comment.