mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-28 09:35:38 -05:00
Better table implementation (#11781)
* wip * wip * weird splitview scrolling stuff * working table * remove spliceable table * handling resizing columns * get perf table integrated into grid * make more improvments to table view * testing * wip * wip * fix async data window; add more optimization to scrolling * work on scrolling * fix column resizing * start working on table widget * inital work to get table widget working with styles and mouse controls * fix unrendering selection; fix sizes of cells * support high perf table option; remove unused files; add cell borders to high perf * add accessibility tags * handle borders and row count * more styling changfes * fix strict null checks * adding inital keyboard navigation * center row count; add padding left to rows * inital drag selection * remove drag implementation; it can be done better utilizing the global mouse monitor object * range logic * create custom grid range * work with new range * remove unused code * fix how plus range works * add drag selection; change focus to set selection; fix problem with creating a range with inverse start and end * code cleanup * fix strict-null-checks * fix up perf table * fix layering * inital table service * finish table service * fix some compile errors * fix compile * fix compile * fix up for use * fix layering * remove console use * fix strict nulls
This commit is contained in:
97
src/sql/base/browser/ui/table/highPerf/cellCache.ts
Normal file
97
src/sql/base/browser/ui/table/highPerf/cellCache.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { ITableRenderer } from 'sql/base/browser/ui/table/highPerf/table';
|
||||
|
||||
import { $, removeClass } from 'vs/base/browser/dom';
|
||||
export interface ICell {
|
||||
domNode: HTMLElement | null;
|
||||
templateData: any;
|
||||
templateId: string;
|
||||
}
|
||||
|
||||
function removeFromParent(element: HTMLElement): void {
|
||||
try {
|
||||
if (element.parentElement) {
|
||||
element.parentElement.removeChild(element);
|
||||
}
|
||||
} catch (e) {
|
||||
// this will throw if this happens due to a blur event, nasty business
|
||||
}
|
||||
}
|
||||
|
||||
export class CellCache<T> implements IDisposable {
|
||||
|
||||
private cache = new Map<string, ICell[]>();
|
||||
|
||||
constructor(private renderers: Map<string, ITableRenderer<T, any>>) { }
|
||||
|
||||
alloc(templateId: string): ICell {
|
||||
let result = this.getTemplateCache(templateId).pop();
|
||||
|
||||
if (!result) {
|
||||
const domNode = $('.monaco-perftable-cell');
|
||||
const renderer = this.getRenderer(templateId);
|
||||
const templateData = renderer.renderTemplate(domNode);
|
||||
result = { domNode, templateId, templateData };
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private getTemplateCache(templateId: string): ICell[] {
|
||||
let result = this.cache.get(templateId);
|
||||
|
||||
if (!result) {
|
||||
result = [];
|
||||
this.cache.set(templateId, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private getRenderer(templateId: string): ITableRenderer<T, any> {
|
||||
const renderer = this.renderers.get(templateId);
|
||||
if (!renderer) {
|
||||
throw new Error(`No renderer found for ${templateId}`);
|
||||
}
|
||||
return renderer;
|
||||
}
|
||||
|
||||
release(cell: ICell) {
|
||||
const { domNode, templateId } = cell;
|
||||
if (domNode) {
|
||||
removeClass(domNode, 'scrolling');
|
||||
removeFromParent(domNode);
|
||||
}
|
||||
|
||||
const cache = this.getTemplateCache(templateId);
|
||||
cache.push(cell);
|
||||
}
|
||||
|
||||
private garbageCollect(): void {
|
||||
if (!this.renderers) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.cache.forEach((cachedRows, templateId) => {
|
||||
for (const cachedRow of cachedRows) {
|
||||
const renderer = this.getRenderer(templateId);
|
||||
renderer.disposeTemplate(cachedRow.templateData);
|
||||
cachedRow.domNode = null;
|
||||
cachedRow.templateData = null;
|
||||
}
|
||||
});
|
||||
|
||||
this.cache.clear();
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.garbageCollect();
|
||||
this.cache.clear();
|
||||
this.renderers = null!; // StrictNullOverride: nulling out ok in dispose
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user