Skip to content

Commit

Permalink
Settings editor - lazier paging when scrolling, looks nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Aug 28, 2018
1 parent f704211 commit ba7f67a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ export class SettingsEditor2 extends BaseEditor {

private updateTreePagingByScroll(): void {
const lastVisibleElement = this.settingsTree.getLastVisibleElement();
if (lastVisibleElement && this.settingsTreeDataSource.pageTo(lastVisibleElement.index)) {
if (lastVisibleElement && this.settingsTreeDataSource.pageTo(lastVisibleElement.index, false)) {
this.renderTree();
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/vs/workbench/parts/preferences/browser/settingsTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,18 @@ export class SettingsDataSource implements IDataSource {

export class SimplePagedDataSource implements IDataSource {
private static readonly SETTINGS_PER_PAGE = 30;
private static readonly BUFFER = 5;

private loadedToIndex: number;

constructor(private realDataSource: IDataSource) {
this.loadedToIndex = SimplePagedDataSource.SETTINGS_PER_PAGE * 2;
}

pageTo(index: number): boolean {
if (index > this.loadedToIndex - SimplePagedDataSource.SETTINGS_PER_PAGE) {
pageTo(index: number, top = true): boolean {
const buffer = top ? SimplePagedDataSource.SETTINGS_PER_PAGE : SimplePagedDataSource.BUFFER;

if (index > this.loadedToIndex - buffer) {
this.loadedToIndex = (Math.ceil(index / SimplePagedDataSource.SETTINGS_PER_PAGE) + 1) * SimplePagedDataSource.SETTINGS_PER_PAGE;
return true;
} else {
Expand Down

0 comments on commit ba7f67a

Please sign in to comment.