Skip to content

Commit

Permalink
Make sure every editor resize event has a measure scheduled after it
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Nov 23, 2021
1 parent cd14f50 commit 9560923
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/docview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class DocView extends ContentView {
// position, if we know the editor is going to scroll that position
// into view.
update(update: ViewUpdate) {
this.lastUpdate = Date.now()
if (update.transactions.length) this.lastUpdate = Date.now()
let changedRanges = update.changedRanges
if (this.minWidth > 0 && changedRanges.length) {
if (!changedRanges.every(({fromA, toA}) => toA < this.minWidthFrom || fromA > this.minWidthTo)) {
Expand Down
8 changes: 7 additions & 1 deletion src/domobserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class DOMObserver {
ignoreSelection: DOMSelection = new DOMSelection

delayedFlush = -1
resizeTimeout = -1
queue: MutationRecord[] = []
lastFlush = 0

Expand Down Expand Up @@ -77,7 +78,11 @@ export class DOMObserver {
this.onSelectionChange = this.onSelectionChange.bind(this)
if (typeof ResizeObserver == "function") {
this.resize = new ResizeObserver(() => {
if (this.view.docView.lastUpdate < Date.now() - 100) this.view.requestMeasure()
if (this.view.docView.lastUpdate < Date.now() - 50 && this.resizeTimeout < 0)
this.resizeTimeout = setTimeout(() => {
this.resizeTimeout = -1
this.view.requestMeasure()
}, 50)
})
this.resize.observe(view.scrollDOM)
}
Expand Down Expand Up @@ -295,6 +300,7 @@ export class DOMObserver {
for (let dom of this.scrollTargets) dom.removeEventListener("scroll", this.onScroll)
window.removeEventListener("scroll", this.onScroll)
clearTimeout(this.parentCheck)
clearTimeout(this.resizeTimeout)
}
}

Expand Down

0 comments on commit 9560923

Please sign in to comment.