提交 508dead0 编写于 作者: R rebornix

list view resize: anchored element will keep its visual position

上级 6cc118c0
......@@ -279,14 +279,20 @@ export class ListView<T> implements ISpliceable<T>, IDisposable {
this.scrollableElement.triggerScrollFromMouseWheelEvent(browserEvent);
}
updateElementHeight(index: number, size: number): void {
updateElementHeight(index: number, size: number, anchorIndex: number | null): void {
if (this.items[index].size === size) {
return;
}
const lastRenderRange = this.getRenderRange(this.lastRenderTop, this.lastRenderHeight);
const heightDiff = index < lastRenderRange.start ? size - this.items[index].size : 0;
const heightDiff =
(anchorIndex !== null && anchorIndex > index && anchorIndex <= lastRenderRange.end)
? size - this.items[index].size // Element at anchor index will keep its visual position
: index < lastRenderRange.start
? size - this.items[index].size
: 0;
this.rangeMap.splice(index, 1, [{ size: size }]);
this.items[index].size = size;
......
......@@ -1314,7 +1314,7 @@ export class List<T> implements ISpliceable<T>, IDisposable {
}
updateElementHeight(index: number, size: number): void {
this.view.updateElementHeight(index, size);
this.view.updateElementHeight(index, size, null);
}
rerender(): void {
......
......@@ -6,7 +6,7 @@
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { MenuRegistry, MenuId, Action2, registerAction2 } from 'vs/platform/actions/common/actions';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { InputFocusedContext, InputFocusedContextKey } from 'vs/platform/contextkey/common/contextkeys';
import { InputFocusedContext, InputFocusedContextKey, IsDevelopmentContext } from 'vs/platform/contextkey/common/contextkeys';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { INotebookService } from 'vs/workbench/contrib/notebook/browser/notebookService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
......@@ -470,3 +470,38 @@ registerAction2(class extends Action2 {
editor.focusNotebookCell(newCell, true);
}
});
registerAction2(class extends Action2 {
constructor() {
super({
id: 'workbench.action.notebook.testResize',
title: 'Notebook Test Cell Resize',
keybinding: {
when: IsDevelopmentContext,
primary: undefined,
weight: KeybindingWeight.WorkbenchContrib
},
f1: true
});
}
async run(accessor: ServicesAccessor): Promise<void> {
const editorService = accessor.get(IEditorService);
const resource = editorService.activeEditor?.resource;
if (!resource) {
return;
}
const editor = getActiveNotebookEditor(editorService);
if (!editor) {
return;
}
const cells = editor.viewModel?.viewCells;
if (cells && cells.length) {
const firstCell = cells[0];
editor.layoutNotebookCell(firstCell, 400);
}
}
});
......@@ -118,7 +118,8 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> implements ID
}
updateElementHeight(index: number, size: number): void {
this.view.updateElementHeight(index, size);
const focused = this.getFocus();
this.view.updateElementHeight(index, size, focused.length ? focused[0] : null);
}
// override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册