mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-03 23:06:49 +01:00
list: reveal
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
import 'vs/css!./list';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { isNumber } from 'vs/base/common/types';
|
||||
import { toggleClass } from 'vs/base/browser/dom';
|
||||
import { IDelegate, IRenderer } from './list';
|
||||
import { ListView } from './listView';
|
||||
@@ -144,6 +145,30 @@ export class List<T> implements IDisposable {
|
||||
indexes.forEach(i => this.view.splice(i, 1, this.view.element(i)));
|
||||
}
|
||||
|
||||
reveal(index: number, relativeTop?: number): void {
|
||||
const scrollTop = this.view.getScrollTop();
|
||||
const elementTop = this.view.elementTop(index);
|
||||
const elementHeight = this.view.elementHeight(index);
|
||||
|
||||
if (isNumber(relativeTop)) {
|
||||
relativeTop = relativeTop < 0 ? 0 : relativeTop;
|
||||
relativeTop = relativeTop > 1 ? 1 : relativeTop;
|
||||
|
||||
// y = mx + b
|
||||
var m = elementHeight - this.view.height;
|
||||
this.view.setScrollTop(m * relativeTop + elementTop);
|
||||
} else {
|
||||
var viewItemBottom = elementTop + elementHeight;
|
||||
var wrapperBottom = scrollTop + this.view.height;
|
||||
|
||||
if (elementTop < scrollTop) {
|
||||
this.view.setScrollTop(elementTop);
|
||||
} else if (viewItemBottom >= wrapperBottom) {
|
||||
this.view.setScrollTop(viewItemBottom - this.view.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.view = dispose(this.view);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user