Allow calling updateElementHeight with undefined to prompt re-probing of dynamic height

See #128563
This commit is contained in:
Rob Lourens
2021-07-22 09:32:32 -07:00
parent 55a5583236
commit 24e8396dd6
6 changed files with 22 additions and 22 deletions
+11 -4
View File
@@ -389,12 +389,19 @@ export class ListView<T> implements ISpliceable<T>, IDisposable {
this.scrollableElement.triggerScrollFromMouseWheelEvent(browserEvent);
}
updateElementHeight(index: number, size: number, anchorIndex: number | null): void {
updateElementHeight(index: number, size: number | undefined, anchorIndex: number | null): void {
if (index < 0 || index >= this.items.length) {
return;
}
if (this.items[index].size === size) {
const originalSize = this.items[index].size;
if (typeof size === 'undefined') {
this.items[index].lastDynamicHeightWidth = undefined;
size = originalSize + this.probeDynamicHeight(index);
}
if (originalSize === size) {
return;
}
@@ -404,12 +411,12 @@ export class ListView<T> implements ISpliceable<T>, IDisposable {
if (index < lastRenderRange.start) {
// do not scroll the viewport if resized element is out of viewport
heightDiff = size - this.items[index].size;
heightDiff = size - originalSize;
} else {
if (anchorIndex !== null && anchorIndex > index && anchorIndex <= lastRenderRange.end) {
// anchor in viewport
// resized element in viewport and above the anchor
heightDiff = size - this.items[index].size;
heightDiff = size - originalSize;
} else {
heightDiff = 0;
}
@@ -87,7 +87,7 @@ function isCollapsibleStateUpdate(update: CollapseStateUpdate): update is Collap
}
export interface IList<T> extends ISpliceable<T> {
updateElementHeight(index: number, height: number): void;
updateElementHeight(index: number, height: number | undefined): void;
}
export class IndexTreeModel<T extends Exclude<any, undefined>, TFilterData = void> implements ITreeModel<T, TFilterData, number[]> {
@@ -328,7 +328,7 @@ export class IndexTreeModel<T extends Exclude<any, undefined>, TFilterData = voi
}
}
updateElementHeight(location: number[], height: number): void {
updateElementHeight(location: number[], height: number | undefined): void {
if (location.length === 0) {
throw new TreeError(this.user, 'Invalid tree location');
}
+1 -1
View File
@@ -65,7 +65,7 @@ export class ObjectTree<T extends NonNullable<any>, TFilterData = void> extends
this.model.rerender(element);
}
updateElementHeight(element: T, height: number): void {
updateElementHeight(element: T, height: number | undefined): void {
this.model.updateElementHeight(element, height);
}
@@ -14,7 +14,7 @@ export type ITreeNodeCallback<T, TFilterData> = (node: ITreeNode<T, TFilterData>
export interface IObjectTreeModel<T extends NonNullable<any>, TFilterData extends NonNullable<any> = void> extends ITreeModel<T | null, TFilterData, T | null> {
setChildren(element: T | null, children: Iterable<ITreeElement<T>> | undefined, options?: IObjectTreeModelSetChildrenOptions<T, TFilterData>): void;
resort(element?: T | null, recursive?: boolean): void;
updateElementHeight(element: T, height: number): void;
updateElementHeight(element: T, height: number | undefined): void;
}
export interface IObjectTreeModelSetChildrenOptions<T, TFilterData> extends IIndexTreeModelSpliceOptions<T, TFilterData> {
@@ -164,7 +164,7 @@ export class ObjectTreeModel<T extends NonNullable<any>, TFilterData extends Non
this.model.rerender(location);
}
updateElementHeight(element: T, height: number): void {
updateElementHeight(element: T, height: number | undefined): void {
const location = this.getElementLocation(element);
this.model.updateElementHeight(location, height);
}
@@ -747,9 +747,9 @@ export class SettingsEditor2 extends EditorPane {
this.searchWidget.setValue(element.targetKey);
}));
this._register(this.settingRenderers.onDidChangeSettingHeight((params: HeightChangeParams) => {
const { element, height } = params;
const { element } = params;
try {
this.settingsTree.updateElementHeight(element, height);
this.settingsTree.updateElementHeight(element, undefined);
} catch (e) {
// the element was not found
}
@@ -590,7 +590,6 @@ function addChildrenToTabOrder(node: Element): void {
export interface HeightChangeParams {
element: SettingsTreeElement;
height: number;
}
export abstract class AbstractSettingRenderer extends Disposable implements ITreeRenderer<SettingsTreeElement, never, any> {
@@ -1495,16 +1494,10 @@ export class SettingMultilineTextRenderer extends AbstractSettingTextRenderer im
};
super.renderValue(dataElement, template, onChangeOverride);
template.elementDisposables.add(
template.inputBox.onDidHeightChange(e => {
const height = template.containerElement.clientHeight;
// Don't fire event if height is reported as 0,
// which sometimes happens when clicking onto a new setting.
if (height) {
this._onDidChangeSettingHeight.fire({
element: dataElement,
height: template.containerElement.clientHeight
});
}
template.inputBox.onDidHeightChange(() => {
this._onDidChangeSettingHeight.fire({
element: dataElement,
});
})
);
template.inputBox.layout();