-
-
Notifications
You must be signed in to change notification settings - Fork 575
fix(Console): auto-scroll disengages on output #1823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
v1ne
wants to merge
1
commit into
fluidd-core:develop
Choose a base branch
from
v1ne:fix-auto-scroll-disengaging
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+80
−15
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,7 @@ | |
|
|
||
| <script lang="ts"> | ||
| import { Component, Prop, Mixins, Watch, Ref, PropSync } from 'vue-property-decorator' | ||
| import { consola } from 'consola' | ||
| import StateMixin from '@/mixins/state' | ||
| import ConsoleCommand from './ConsoleCommand.vue' | ||
| import ConsoleItem from './ConsoleItem.vue' | ||
|
|
@@ -86,6 +87,9 @@ export default class Console extends Mixins(StateMixin) { | |
| readonly dynamicScroller!: DinamicScroller | ||
|
|
||
| _pauseScroll = false | ||
| declare _programmaticFrames: number | ||
| declare _programmaticRaf: number | null | ||
| _stopSizesWatcher: (() => void) | null = null | ||
|
|
||
| get currentCommand (): string { | ||
| return this.$typedState.console.consoleCommand | ||
|
|
@@ -104,11 +108,43 @@ export default class Console extends Mixins(StateMixin) { | |
| } | ||
|
|
||
| mounted () { | ||
| this.dynamicScroller.$el.addEventListener('scroll', this.onScroll) | ||
| // Vue 2 does not proxy _-prefixed properties onto the instance, so class-field | ||
| // initializers for these are silently dropped. Set them as own properties here. | ||
| this._programmaticFrames = 0 | ||
| this._programmaticRaf = null | ||
|
|
||
| const el = this.dynamicScroller.$el | ||
| el.addEventListener('scroll', this.onScroll) | ||
|
|
||
| // DynamicScroller's internal `itemsWithSize` watcher adjusts scrollTop on item | ||
| // measurement, producing a scroll event indistinguishable from user input. | ||
| // Mirror vscrollData.sizes so we can open a programmatic window before that event. | ||
| const scroller = this.dynamicScroller as unknown as { | ||
| vscrollData?: { sizes: Record<string | number, number> } | ||
| } | ||
| const vscrollData = scroller.vscrollData | ||
| if (vscrollData) { | ||
| this._stopSizesWatcher = this.$watch( | ||
| () => vscrollData.sizes, | ||
| () => this.markProgrammatic(), | ||
| { deep: true } | ||
| ) | ||
| } else { | ||
| consola.warn('[Console] DynamicScroller.vscrollData not found; auto-scroll pause detection may misfire on item measurement.') | ||
| } | ||
| } | ||
|
|
||
| beforeDestroy () { | ||
| this.dynamicScroller.$el.removeEventListener('scroll', this.onScroll) | ||
| const el = this.dynamicScroller.$el | ||
| el.removeEventListener('scroll', this.onScroll) | ||
| if (this._stopSizesWatcher) { | ||
| this._stopSizesWatcher() | ||
| this._stopSizesWatcher = null | ||
| } | ||
| if (this._programmaticRaf !== null) { | ||
| cancelAnimationFrame(this._programmaticRaf) | ||
| this._programmaticRaf = null | ||
| } | ||
| } | ||
|
|
||
| @Watch('items', { immediate: true }) | ||
|
|
@@ -121,6 +157,7 @@ export default class Console extends Mixins(StateMixin) { | |
|
|
||
| if (scrollHeight > clientHeight) { | ||
| this.$nextTick(() => { | ||
| this.markProgrammatic() | ||
| el.scrollTop += el.scrollHeight - scrollHeight | ||
| }) | ||
| } | ||
|
|
@@ -130,21 +167,48 @@ export default class Console extends Mixins(StateMixin) { | |
| } | ||
| } | ||
|
|
||
| updateScrollingPaused () { | ||
| this.$nextTick(() => { | ||
| const { scrollTop, scrollHeight, clientHeight } = this.dynamicScroller.$el | ||
|
|
||
| const pauseScroll = this.flipLayout ? scrollTop > 1 : scrollHeight - scrollTop - clientHeight > 1 | ||
|
|
||
| if (this._pauseScroll !== pauseScroll) { | ||
| this._pauseScroll = pauseScroll | ||
| this.scrollingPausedModel = pauseScroll | ||
| markProgrammatic (frames = 2) { | ||
| this._programmaticFrames = Math.max(this._programmaticFrames, frames) | ||
| if (this._programmaticRaf === null) { | ||
| const tick = () => { | ||
| this._programmaticFrames-- | ||
| if (this._programmaticFrames > 0) { | ||
| this._programmaticRaf = requestAnimationFrame(tick) | ||
| } else { | ||
| this._programmaticRaf = null | ||
| } | ||
| } | ||
| }) | ||
| this._programmaticRaf = requestAnimationFrame(tick) | ||
| } | ||
|
Comment on lines
+170
to
+182
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will not be reused. |
||
| } | ||
|
|
||
| // Must be a method, not a getter: vue-class-component turns getters into cached | ||
| // computed properties. Because _programmaticFrames is non-reactive (Vue 2 does not | ||
| // proxy _-prefixed props), no dep is recorded and the cached value never updates. | ||
| isProgrammaticScroll (): boolean { | ||
| return this._programmaticFrames > 0 | ||
| } | ||
|
|
||
| onScroll () { | ||
| this.updateScrollingPaused() | ||
| const { scrollTop, scrollHeight, clientHeight } = this.dynamicScroller.$el | ||
| const atLatest = this.flipLayout | ||
| ? scrollTop <= 1 | ||
| : scrollHeight - scrollTop - clientHeight <= 1 | ||
|
|
||
| if (this._pauseScroll) { | ||
| if (atLatest) { | ||
| this._pauseScroll = false | ||
| this.scrollingPausedModel = false | ||
| } | ||
| return | ||
| } | ||
|
|
||
| if (this.isProgrammaticScroll()) return | ||
|
|
||
| if (!atLatest) { | ||
| this._pauseScroll = true | ||
| this.scrollingPausedModel = true | ||
| } | ||
| } | ||
|
|
||
| scrollToLatest (force?: boolean) { | ||
|
|
@@ -156,6 +220,7 @@ export default class Console extends Mixins(StateMixin) { | |
| this.readonly || | ||
| force | ||
| ) { | ||
| this.markProgrammatic(3) // 3 frames covers scrollToBottom's async rAF settle | ||
| if (this.flipLayout) { | ||
| this.dynamicScroller.scrollToItem(0) | ||
| } else { | ||
|
|
@@ -164,8 +229,8 @@ export default class Console extends Mixins(StateMixin) { | |
| } | ||
|
|
||
| if (force) { | ||
| // The fixed/floating nature of the console may only change if the scroll is forced. | ||
| this.updateScrollingPaused() | ||
| this._pauseScroll = false | ||
| this.scrollingPausedModel = false | ||
| } | ||
| } | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am open for any cheaper solution that actually works. But there is no public API on the scroller to support this.