mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
extract CachedListVirtualDelegate
This commit is contained in:
parent
4225aa8a9a
commit
dff18ede6c
|
@ -115,3 +115,19 @@ export class ListError extends Error {
|
||||||
super(`ListError [${user}] ${message}`);
|
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 { IAccessibilityProvider } from 'vs/base/browser/ui/list/listWidget';
|
||||||
import { Variable } from 'vs/workbench/contrib/debug/common/debugModel';
|
import { Variable } from 'vs/workbench/contrib/debug/common/debugModel';
|
||||||
import { SimpleReplElement, RawObjectReplElement, ReplEvaluationInput, ReplEvaluationResult } from 'vs/workbench/contrib/debug/common/replModel';
|
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 { ITreeRenderer, ITreeNode, ITreeContextMenuEvent, IAsyncDataSource } from 'vs/base/browser/ui/tree/tree';
|
||||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||||
import { renderExpressionValue, AbstractExpressionsRenderer, IExpressionTemplateData, renderVariable, IInputBoxOptions } from 'vs/workbench/contrib/debug/browser/baseDebugView';
|
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) {
|
||||||
|
super();
|
||||||
constructor(private configurationService: IConfigurationService) { }
|
}
|
||||||
|
|
||||||
getHeight(element: IReplElement): number {
|
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 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';
|
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
|
// Calculate a rough overestimation for the height
|
||||||
// For every 30 characters increase the number of lines needed
|
// For every 30 characters increase the number of lines needed
|
||||||
if (hasValue(element)) {
|
if (hasValue(element)) {
|
||||||
|
@ -852,10 +851,6 @@ class ReplDelegate implements IListVirtualDelegate<IReplElement> {
|
||||||
// Empty elements should not have dynamic height since they will be invisible
|
// Empty elements should not have dynamic height since they will be invisible
|
||||||
return element.toString().length > 0;
|
return element.toString().length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
setDynamicHeight(element: IReplElement, height: number): void {
|
|
||||||
this.heightCache.set(element, height);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function isDebugSession(obj: any): obj is IDebugSession {
|
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 { Button } from 'vs/base/browser/ui/button/button';
|
||||||
import { Checkbox } from 'vs/base/browser/ui/checkbox/checkbox';
|
import { Checkbox } from 'vs/base/browser/ui/checkbox/checkbox';
|
||||||
import { InputBox } from 'vs/base/browser/ui/inputbox/inputBox';
|
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 { DefaultStyleController } from 'vs/base/browser/ui/list/listWidget';
|
||||||
import { ISelectOptionItem, SelectBox } from 'vs/base/browser/ui/selectBox/selectBox';
|
import { ISelectOptionItem, SelectBox } from 'vs/base/browser/ui/selectBox/selectBox';
|
||||||
import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
|
import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
|
||||||
|
@ -1379,29 +1379,7 @@ export class SettingsTreeFilter implements ITreeFilter<SettingsTreeElement> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SettingsTreeDelegate implements IListVirtualDelegate<SettingsTreeGroupChild> {
|
class SettingsTreeDelegate extends CachedListVirtualDelegate<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;
|
|
||||||
}
|
|
||||||
|
|
||||||
getTemplateId(element: SettingsTreeGroupElement | SettingsTreeSettingElement | SettingsTreeNewExtensionsElement): string {
|
getTemplateId(element: SettingsTreeGroupElement | SettingsTreeSettingElement | SettingsTreeNewExtensionsElement): string {
|
||||||
if (element instanceof SettingsTreeGroupElement) {
|
if (element instanceof SettingsTreeGroupElement) {
|
||||||
|
@ -1447,8 +1425,16 @@ class SettingsTreeDelegate implements IListVirtualDelegate<SettingsTreeGroupChil
|
||||||
return !(element instanceof SettingsTreeGroupElement);
|
return !(element instanceof SettingsTreeGroupElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
setDynamicHeight(element: SettingsTreeGroupChild, height: number): void {
|
protected estimateHeight(element: SettingsTreeGroupChild): number {
|
||||||
this.heightCache.set(element, height);
|
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