Skip to content

Commit

Permalink
Force a content measure when the editor comes into view
Browse files Browse the repository at this point in the history
FIX: Fix a bug that could cause the editor to not measure its layout the first time
it came into view.

See https://discuss.codemirror.net/t/bug-gutters-height-miscalculate-when-the-view-is-not-on-viewport/3812
  • Loading branch information
marijnh committed Dec 15, 2021
1 parent 942cd1e commit 7cfee21
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/domobserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class DOMObserver {
if (typeof IntersectionObserver == "function") {
this.intersection = new IntersectionObserver(entries => {
if (this.parentCheck < 0) this.parentCheck = setTimeout(this.listenForScroll.bind(this), 1000)
if (entries.length > 0 && entries[entries.length - 1].intersectionRatio > 0 != this.intersecting) {
if (entries.length > 0 && (entries[entries.length - 1].intersectionRatio > 0) != this.intersecting) {
this.intersecting = !this.intersecting
if (this.intersecting != this.view.inView)
this.onScrollChanged(document.createEvent("Event"))
Expand Down
6 changes: 5 additions & 1 deletion src/viewstate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ export class ViewState {
let pixelViewport = this.printing ? {top: -1e8, bottom: 1e8, left: -1e8, right: 1e8} : visiblePixelRange(dom, this.paddingTop)
let dTop = pixelViewport.top - this.pixelViewport.top, dBottom = pixelViewport.bottom - this.pixelViewport.bottom
this.pixelViewport = pixelViewport
this.inView = this.pixelViewport.bottom > this.pixelViewport.top && this.pixelViewport.right > this.pixelViewport.left
let inView = this.pixelViewport.bottom > this.pixelViewport.top && this.pixelViewport.right > this.pixelViewport.left
if (inView != this.inView) {
this.inView = inView
if (inView) measureContent = true
}
if (!this.inView) return 0

if (measureContent) {
Expand Down

0 comments on commit 7cfee21

Please sign in to comment.