Skip to content

Commit

Permalink
fix(files): Ensure that focussed file is always scrolled right
Browse files Browse the repository at this point in the history
Ensure the correct file is scrolled if the content changes,
this also sets a minimal height to the virtual scrolling area
so that the `scrollTop` can be set.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Jun 5, 2024
1 parent 78465cf commit 5dfc00f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions apps/files/src/components/VirtualList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,17 @@ export default Vue.extend({
return Math.floor(this.filesListWidth / this.itemWidth)
},
/**
* Index of the first item to be rendered
*/
startIndex() {
return Math.max(0, this.index - this.bufferItems)
},
/**
* Number of items to be rendered at the same time
* For list view this is the same as `rowCount`, for grid view this is `rowCount` * `columnCount`
*/
shownItems() {
// If in grid mode, we need to multiply the number of rows by the number of columns
if (this.gridMode) {
Expand All @@ -157,6 +165,7 @@ export default Vue.extend({
return this.rowCount
},
renderedItems(): RecycledPoolItem[] {
if (!this.isReady) {
return []
Expand Down Expand Up @@ -185,20 +194,35 @@ export default Vue.extend({
})
},
/**
* The total number of rows that are available
*/
totalRowCount() {
return Math.floor(this.dataSources.length / this.columnCount)
},
tbodyStyle() {
const isOverScrolled = this.startIndex + this.rowCount > this.dataSources.length
const lastIndex = this.dataSources.length - this.startIndex - this.shownItems
const hiddenAfterItems = Math.floor(Math.min(this.dataSources.length - this.startIndex, lastIndex) / this.columnCount)
return {
paddingTop: `${Math.floor(this.startIndex / this.columnCount) * this.itemHeight}px`,
paddingBottom: isOverScrolled ? 0 : `${hiddenAfterItems * this.itemHeight}px`,
minHeight: `${this.totalRowCount * this.itemHeight + this.beforeHeight}px`,
}
},
},
watch: {
scrollToIndex(index) {
this.scrollTo(index)
},
totalRowCount() {
if (this.scrollToIndex) {
this.$nextTick(() => this.scrollTo(this.scrollToIndex))
}
},
columnCount(columnCount, oldColumnCount) {
if (oldColumnCount === 0) {
// We're initializing, the scroll position
Expand Down

0 comments on commit 5dfc00f

Please sign in to comment.