mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
Merge pull request #82981 from microsoft/joao/cached-list-virtual-delegate
Extract CachedListVirtualDelegate
This commit is contained in:
commit
ad9e2707fb
|
@ -115,3 +115,19 @@ export class ListError extends Error {
|
|||
super(`ListError [${user}] ${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class CachedListVirtualDelegate<T extends object> implements IListVirtualDelegate<T> {
|
||||
|
||||
private cache = new WeakMap<T, number>();
|
||||
|
||||
getHeight(element: T): number {
|
||||
return this.cache.get(element) ?? this.estimateHeight(element);
|
||||
}
|
||||
|
||||
protected abstract estimateHeight(element: T): number;
|
||||
abstract getTemplateId(element: T): string;
|
||||
|
||||
setDynamicHeight(element: T, height: number): void {
|
||||
this.cache.set(element, height);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
|
|||
import { IAccessibilityProvider } from 'vs/base/browser/ui/list/listWidget';
|
||||
import { Variable } from 'vs/workbench/contrib/debug/common/debugModel';
|
||||
import { SimpleReplElement, RawObjectReplElement, ReplEvaluationInput, ReplEvaluationResult } from 'vs/workbench/contrib/debug/common/replModel';
|
||||
import { IListVirtualDelegate } from 'vs/base/browser/ui/list/list';
|
||||
import { CachedListVirtualDelegate } from 'vs/base/browser/ui/list/list';
|
||||
import { ITreeRenderer, ITreeNode, ITreeContextMenuEvent, IAsyncDataSource } from 'vs/base/browser/ui/tree/tree';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { renderExpressionValue, AbstractExpressionsRenderer, IExpressionTemplateData, renderVariable, IInputBoxOptions } from 'vs/workbench/contrib/debug/browser/baseDebugView';
|
||||
|
@ -795,29 +795,28 @@ class ReplRawObjectsRenderer implements ITreeRenderer<RawObjectReplElement, Fuzz
|
|||
}
|
||||
}
|
||||
|
||||
class ReplDelegate implements IListVirtualDelegate<IReplElement> {
|
||||
class ReplDelegate extends CachedListVirtualDelegate<IReplElement> {
|
||||
|
||||
private heightCache = new WeakMap<IReplElement, number>();
|
||||
|
||||
constructor(private configurationService: IConfigurationService) { }
|
||||
constructor(private configurationService: IConfigurationService) {
|
||||
super();
|
||||
}
|
||||
|
||||
getHeight(element: IReplElement): number {
|
||||
const config = this.configurationService.getValue<IDebugConfiguration>('debug');
|
||||
|
||||
if (!config.console.wordWrap) {
|
||||
return Math.ceil(1.4 * config.console.fontSize);
|
||||
}
|
||||
|
||||
return super.getHeight(element);
|
||||
}
|
||||
|
||||
protected estimateHeight(element: IReplElement): number {
|
||||
const config = this.configurationService.getValue<IDebugConfiguration>('debug');
|
||||
const rowHeight = Math.ceil(1.4 * config.console.fontSize);
|
||||
const countNumberOfLines = (str: string) => Math.max(1, (str && str.match(/\r\n|\n/g) || []).length);
|
||||
const hasValue = (e: any): e is { value: string } => typeof e.value === 'string';
|
||||
|
||||
// Give approximate heights. Repl has dynamic height so the tree will measure the actual height on its own.
|
||||
const config = this.configurationService.getValue<IDebugConfiguration>('debug');
|
||||
const { fontSize, wordWrap } = config.console;
|
||||
const rowHeight = Math.ceil(1.4 * fontSize);
|
||||
if (!wordWrap) {
|
||||
return rowHeight;
|
||||
}
|
||||
|
||||
const cachedHeight = this.heightCache.get(element);
|
||||
if (typeof cachedHeight === 'number') {
|
||||
return cachedHeight;
|
||||
}
|
||||
|
||||
// Calculate a rough overestimation for the height
|
||||
// For every 30 characters increase the number of lines needed
|
||||
if (hasValue(element)) {
|
||||
|
@ -852,10 +851,6 @@ class ReplDelegate implements IListVirtualDelegate<IReplElement> {
|
|||
// Empty elements should not have dynamic height since they will be invisible
|
||||
return element.toString().length > 0;
|
||||
}
|
||||
|
||||
setDynamicHeight(element: IReplElement, height: number): void {
|
||||
this.heightCache.set(element, height);
|
||||
}
|
||||
}
|
||||
|
||||
function isDebugSession(obj: any): obj is IDebugSession {
|
||||
|
|
|
@ -12,7 +12,7 @@ import { alert as ariaAlert } from 'vs/base/browser/ui/aria/aria';
|
|||
import { Button } from 'vs/base/browser/ui/button/button';
|
||||
import { Checkbox } from 'vs/base/browser/ui/checkbox/checkbox';
|
||||
import { InputBox } from 'vs/base/browser/ui/inputbox/inputBox';
|
||||
import { IListVirtualDelegate, ListAriaRootRole } from 'vs/base/browser/ui/list/list';
|
||||
import { ListAriaRootRole, CachedListVirtualDelegate } from 'vs/base/browser/ui/list/list';
|
||||
import { DefaultStyleController } from 'vs/base/browser/ui/list/listWidget';
|
||||
import { ISelectOptionItem, SelectBox } from 'vs/base/browser/ui/selectBox/selectBox';
|
||||
import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
|
||||
|
@ -1379,29 +1379,7 @@ export class SettingsTreeFilter implements ITreeFilter<SettingsTreeElement> {
|
|||
}
|
||||
}
|
||||
|
||||
class SettingsTreeDelegate implements IListVirtualDelegate<SettingsTreeGroupChild> {
|
||||
|
||||
private heightCache = new WeakMap<SettingsTreeGroupChild, number>();
|
||||
|
||||
getHeight(element: SettingsTreeGroupChild): number {
|
||||
const cachedHeight = this.heightCache.get(element);
|
||||
|
||||
if (typeof cachedHeight === 'number') {
|
||||
return cachedHeight;
|
||||
}
|
||||
|
||||
if (element instanceof SettingsTreeGroupElement) {
|
||||
if (element.isFirstGroup) {
|
||||
return 31;
|
||||
}
|
||||
|
||||
return 40 + (7 * element.level);
|
||||
}
|
||||
|
||||
return element instanceof SettingsTreeSettingElement && element.valueType === SettingValueType.Boolean ?
|
||||
78 :
|
||||
104;
|
||||
}
|
||||
class SettingsTreeDelegate extends CachedListVirtualDelegate<SettingsTreeGroupChild> {
|
||||
|
||||
getTemplateId(element: SettingsTreeGroupElement | SettingsTreeSettingElement | SettingsTreeNewExtensionsElement): string {
|
||||
if (element instanceof SettingsTreeGroupElement) {
|
||||
|
@ -1447,8 +1425,16 @@ class SettingsTreeDelegate implements IListVirtualDelegate<SettingsTreeGroupChil
|
|||
return !(element instanceof SettingsTreeGroupElement);
|
||||
}
|
||||
|
||||
setDynamicHeight(element: SettingsTreeGroupChild, height: number): void {
|
||||
this.heightCache.set(element, height);
|
||||
protected estimateHeight(element: SettingsTreeGroupChild): number {
|
||||
if (element instanceof SettingsTreeGroupElement) {
|
||||
if (element.isFirstGroup) {
|
||||
return 31;
|
||||
}
|
||||
|
||||
return 40 + (7 * element.level);
|
||||
}
|
||||
|
||||
return element instanceof SettingsTreeSettingElement && element.valueType === SettingValueType.Boolean ? 78 : 104;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue