Skip to content
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

Fix Sticky Scroll Double Header in Settings UI #202506

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/vs/base/browser/ui/list/listWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,10 @@ export class List<T> implements ISpliceable<T>, IDisposable {
return this.view.indexOf(element);
}

indexAt(position: number): number {
return this.view.indexAt(position);
}

get length(): number {
return this.view.length;
}
Expand Down
49 changes: 25 additions & 24 deletions src/vs/base/browser/ui/tree/abstractTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1265,16 +1265,6 @@ class StickyScrollController<T, TFilterData, TRef> extends Disposable {

private readonly _widget: StickyScrollWidget<T, TFilterData, TRef>;

private get firstVisibleNode() {
const index = this.view.firstVisibleIndex;

if (index < 0 || index >= this.view.length) {
return undefined;
}

return this.view.element(index);
}

constructor(
private readonly tree: AbstractTree<T, TFilterData, TRef>,
private readonly model: ITreeModel<T, TFilterData, TRef>,
Expand Down Expand Up @@ -1313,8 +1303,23 @@ class StickyScrollController<T, TFilterData, TRef> extends Disposable {
return this._widget.getNode(node);
}

private getNodeAtHeight(height: number): ITreeNode<T, TFilterData> | undefined {
let index;
if (height === 0) {
index = this.view.firstVisibleIndex;
} else {
index = this.view.indexAt(height + this.view.scrollTop);
}

if (index < 0 || index >= this.view.length) {
return undefined;
}

return this.view.element(index);
}

private update() {
const firstVisibleNode = this.firstVisibleNode;
const firstVisibleNode = this.getNodeAtHeight(0);

// Don't render anything if there are no elements
if (!firstVisibleNode || this.tree.scrollTop === 0) {
Expand All @@ -1338,7 +1343,7 @@ class StickyScrollController<T, TFilterData, TRef> extends Disposable {
stickyNodesHeight += nextStickyNode.height;

if (stickyNodes.length <= this.stickyScrollMaxItemCount) {
firstVisibleNodeUnderWidget = this.getNextVisibleNode(firstVisibleNodeUnderWidget);
firstVisibleNodeUnderWidget = this.getNextVisibleNode(nextStickyNode);
if (!firstVisibleNodeUnderWidget) {
break;
}
Expand All @@ -1351,13 +1356,8 @@ class StickyScrollController<T, TFilterData, TRef> extends Disposable {
return contrainedStickyNodes.length ? new StickyScrollState(contrainedStickyNodes) : undefined;
}

private getNextVisibleNode(node: ITreeNode<T, TFilterData>): ITreeNode<T, TFilterData> | undefined {
const nodeIndex = this.getNodeIndex(node);
if (nodeIndex === -1 || nodeIndex === this.view.length - 1) {
return undefined;
}
const nextNode = this.view.element(nodeIndex + 1);
return nextNode;
private getNextVisibleNode(previousStickyNode: StickyScrollNode<T, TFilterData>): ITreeNode<T, TFilterData> | undefined {
return this.getNodeAtHeight(previousStickyNode.position + previousStickyNode.height);
}

private getNextStickyNode(firstVisibleNodeUnderWidget: ITreeNode<T, TFilterData>, previousStickyNode: ITreeNode<T, TFilterData> | undefined, stickyNodesHeight: number): StickyScrollNode<T, TFilterData> | undefined {
Expand Down Expand Up @@ -1390,7 +1390,7 @@ class StickyScrollController<T, TFilterData, TRef> extends Disposable {
const height = this.treeDelegate.getHeight(node);
const { startIndex, endIndex } = this.getNodeRange(node);

const position = this.calculateStickyNodePosition(endIndex, currentStickyNodesHeight);
const position = this.calculateStickyNodePosition(endIndex, currentStickyNodesHeight, height);

return { node, position, height, startIndex, endIndex };
}
Expand All @@ -1414,7 +1414,7 @@ class StickyScrollController<T, TFilterData, TRef> extends Disposable {
return undefined;
}

private calculateStickyNodePosition(lastDescendantIndex: number, stickyRowPositionTop: number): number {
private calculateStickyNodePosition(lastDescendantIndex: number, stickyRowPositionTop: number, stickyNodeHeight: number): number {
let lastChildRelativeTop = this.view.getRelativeTop(lastDescendantIndex);

// If the last descendant is only partially visible at the top of the view, getRelativeTop() returns null
Expand All @@ -1434,8 +1434,8 @@ class StickyScrollController<T, TFilterData, TRef> extends Disposable {
const topOfLastChild = lastChildRelativeTop * this.view.renderHeight;
const bottomOfLastChild = topOfLastChild + lastChildHeight;

if (stickyRowPositionTop > topOfLastChild && stickyRowPositionTop <= bottomOfLastChild) {
return topOfLastChild;
if (stickyRowPositionTop + stickyNodeHeight > bottomOfLastChild && stickyRowPositionTop <= bottomOfLastChild) {
return bottomOfLastChild - stickyNodeHeight;
}

return stickyRowPositionTop;
Expand Down Expand Up @@ -1641,10 +1641,11 @@ class StickyScrollWidget<T, TFilterData, TRef> implements IDisposable {

this.stickyScrollFocus.updateElements(elements, state);

this._previousState = state;
this._previousElements = elements;
}

this._previousState = state;

// Set the height of the widget to the bottom of the last sticky node
this._rootDomNode.style.height = `${lastStickyNode.position + lastStickyNode.height}px`;
}
Expand Down