mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 17:19:48 +01:00
Merge pull request #150299 from microsoft/rebornix/fix-list-pageup-down
Fix list pageup down
This commit is contained in:
@@ -1598,9 +1598,10 @@ export class List<T> implements ISpliceable<T>, IThemable, IDisposable {
|
||||
let lastPageIndex = this.view.indexAt(this.view.getScrollTop() + this.view.renderHeight);
|
||||
lastPageIndex = lastPageIndex === 0 ? 0 : lastPageIndex - 1;
|
||||
const lastPageElement = this.view.element(lastPageIndex);
|
||||
const currentlyFocusedElement = this.getFocusedElements()[0];
|
||||
const currentlyFocusedElementIndex = this.getFocus()[0];
|
||||
const currentlyFocusedElement = this.view.element(currentlyFocusedElementIndex);
|
||||
|
||||
if (currentlyFocusedElement !== lastPageElement) {
|
||||
if (currentlyFocusedElement !== lastPageElement && lastPageIndex > currentlyFocusedElementIndex) {
|
||||
const lastGoodPageIndex = this.findPreviousIndex(lastPageIndex, false, filter);
|
||||
|
||||
if (lastGoodPageIndex > -1 && currentlyFocusedElement !== this.view.element(lastGoodPageIndex)) {
|
||||
@@ -1610,7 +1611,13 @@ export class List<T> implements ISpliceable<T>, IThemable, IDisposable {
|
||||
}
|
||||
} else {
|
||||
const previousScrollTop = this.view.getScrollTop();
|
||||
this.view.setScrollTop(previousScrollTop + this.view.renderHeight - this.view.elementHeight(lastPageIndex));
|
||||
let nextpageScrollTop = previousScrollTop + this.view.renderHeight;
|
||||
if (lastPageIndex > currentlyFocusedElementIndex) {
|
||||
// scroll last page element to the top only if the last page element is below the focused element
|
||||
nextpageScrollTop -= this.view.elementHeight(lastPageIndex);
|
||||
}
|
||||
|
||||
this.view.setScrollTop(nextpageScrollTop);
|
||||
|
||||
if (this.view.getScrollTop() !== previousScrollTop) {
|
||||
this.setFocus([]);
|
||||
@@ -1633,9 +1640,10 @@ export class List<T> implements ISpliceable<T>, IThemable, IDisposable {
|
||||
}
|
||||
|
||||
const firstPageElement = this.view.element(firstPageIndex);
|
||||
const currentlyFocusedElement = this.getFocusedElements()[0];
|
||||
const currentlyFocusedElementIndex = this.getFocus()[0];
|
||||
const currentlyFocusedElement = this.view.element(currentlyFocusedElementIndex);
|
||||
|
||||
if (currentlyFocusedElement !== firstPageElement) {
|
||||
if (currentlyFocusedElement !== firstPageElement && currentlyFocusedElementIndex >= firstPageIndex) {
|
||||
const firstGoodPageIndex = this.findNextIndex(firstPageIndex, false, filter);
|
||||
|
||||
if (firstGoodPageIndex > -1 && currentlyFocusedElement !== this.view.element(firstGoodPageIndex)) {
|
||||
|
||||
@@ -7,9 +7,10 @@ import { Disposable, DisposableStore, dispose, IDisposable } from 'vs/base/commo
|
||||
import { Action2, registerAction2 } from 'vs/platform/actions/common/actions';
|
||||
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { CATEGORIES } from 'vs/workbench/common/actions';
|
||||
import { getNotebookEditorFromEditorPane, ICellViewModel, ICommonCellViewModelLayoutChangeInfo, INotebookEditor, INotebookEditorContribution } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { getNotebookEditorFromEditorPane, ICellViewModel, ICommonCellViewModelLayoutChangeInfo, INotebookDeltaCellStatusBarItems, INotebookEditor, INotebookEditorContribution } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { registerNotebookContribution } from 'vs/workbench/contrib/notebook/browser/notebookEditorExtensions';
|
||||
import { NotebookEditorWidget } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidget';
|
||||
import { CellStatusbarAlignment, INotebookCellStatusBarItem } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
|
||||
@@ -18,31 +19,37 @@ export class TroubleshootController extends Disposable implements INotebookEdito
|
||||
|
||||
private readonly _localStore = this._register(new DisposableStore());
|
||||
private _cellStateListeners: IDisposable[] = [];
|
||||
private _logging: boolean = false;
|
||||
private _enabled: boolean = false;
|
||||
private _cellStatusItems: string[] = [];
|
||||
|
||||
constructor(private readonly _notebookEditor: INotebookEditor) {
|
||||
super();
|
||||
|
||||
this._register(this._notebookEditor.onDidChangeModel(() => {
|
||||
this._localStore.clear();
|
||||
this._cellStateListeners.forEach(listener => listener.dispose());
|
||||
|
||||
if (!this._notebookEditor.hasModel()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._updateListener();
|
||||
this._update();
|
||||
}));
|
||||
|
||||
this._update();
|
||||
}
|
||||
|
||||
toggle(): void {
|
||||
this._enabled = !this._enabled;
|
||||
this._update();
|
||||
}
|
||||
|
||||
private _update() {
|
||||
this._localStore.clear();
|
||||
this._cellStateListeners.forEach(listener => listener.dispose());
|
||||
|
||||
if (!this._notebookEditor.hasModel()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._updateListener();
|
||||
}
|
||||
|
||||
toggleLogging(): void {
|
||||
this._logging = !this._logging;
|
||||
}
|
||||
|
||||
private _log(cell: ICellViewModel, e: any) {
|
||||
if (this._logging) {
|
||||
if (this._enabled) {
|
||||
const oldHeight = (this._notebookEditor as NotebookEditorWidget).getViewHeight(cell);
|
||||
console.log(`cell#${cell.handle}`, e, `${oldHeight} -> ${cell.layoutInfo.totalHeight}`);
|
||||
}
|
||||
@@ -73,6 +80,33 @@ export class TroubleshootController extends Disposable implements INotebookEdito
|
||||
dispose(deletedCells);
|
||||
});
|
||||
}));
|
||||
|
||||
const vm = this._notebookEditor._getViewModel();
|
||||
let items: INotebookDeltaCellStatusBarItems[] = [];
|
||||
|
||||
if (this._enabled) {
|
||||
items = this._getItemsForCells();
|
||||
}
|
||||
|
||||
this._cellStatusItems = vm.deltaCellStatusBarItems(this._cellStatusItems, items);
|
||||
}
|
||||
|
||||
private _getItemsForCells(): INotebookDeltaCellStatusBarItems[] {
|
||||
const items: INotebookDeltaCellStatusBarItems[] = [];
|
||||
for (let i = 0; i < this._notebookEditor.getLength(); i++) {
|
||||
items.push({
|
||||
handle: i,
|
||||
items: [
|
||||
<INotebookCellStatusBarItem>{
|
||||
text: `index: ${i}`,
|
||||
alignment: CellStatusbarAlignment.Left,
|
||||
priority: Number.MAX_SAFE_INTEGER
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
override dispose() {
|
||||
@@ -102,7 +136,7 @@ registerAction2(class extends Action2 {
|
||||
}
|
||||
|
||||
const controller = editor.getContribution<TroubleshootController>(TroubleshootController.id);
|
||||
controller?.toggleLogging();
|
||||
controller?.toggle();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user