未验证 提交 30e7a527 编写于 作者: J Joao Moreno

add tree.hasElement()

related to #86201
上级 a172a75b
......@@ -205,6 +205,10 @@ export class CompressedObjectTreeModel<T extends NonNullable<any>, TFilterData e
this.model.setChildren(node, children, _onDidCreateNode, _onDidDeleteNode);
}
has(element: T | null): boolean {
return this.nodes.has(element);
}
getListIndex(location: T | null): number {
const node = this.getCompressedNode(location);
return this.model.getListIndex(node);
......@@ -421,6 +425,10 @@ export class CompressibleObjectTreeModel<T extends NonNullable<any>, TFilterData
this.model.setCompressionEnabled(enabled);
}
has(location: T | null): boolean {
return this.model.has(location);
}
getListIndex(location: T | null): number {
return this.model.getListIndex(location);
}
......
......@@ -199,6 +199,10 @@ export class IndexTreeModel<T extends Exclude<any, undefined>, TFilterData = voi
}
}
has(location: number[]): boolean {
return this.hasTreeNode(location);
}
getListIndex(location: number[]): number {
const { listIndex, visible, revealed } = this.getTreeNodeWithListIndex(location);
return visible && revealed ? listIndex : -1;
......@@ -516,6 +520,21 @@ export class IndexTreeModel<T extends Exclude<any, undefined>, TFilterData = voi
}
}
// cheap
private hasTreeNode(location: number[], node: IIndexTreeNode<T, TFilterData> = this.root): boolean {
if (!location || location.length === 0) {
return true;
}
const [index, ...rest] = location;
if (index < 0 || index > node.children.length) {
return false;
}
return this.hasTreeNode(rest, node.children[index]);
}
// cheap
private getTreeNode(location: number[], node: IIndexTreeNode<T, TFilterData> = this.root): IIndexTreeNode<T, TFilterData> {
if (!location || location.length === 0) {
......
......@@ -50,6 +50,10 @@ export class ObjectTree<T extends NonNullable<any>, TFilterData = void> extends
this.model.resort(element, recursive);
}
hasElement(element: T): boolean {
return this.model.has(element);
}
protected createModel(user: string, view: ISpliceable<ITreeNode<T, TFilterData>>, options: IObjectTreeOptions<T, TFilterData>): ITreeModel<T | null, TFilterData, T | null> {
return new ObjectTreeModel(user, view, options);
}
......
......@@ -195,6 +195,10 @@ export class ObjectTreeModel<T extends NonNullable<any>, TFilterData extends Non
return this.model.getLastElementAncestor(location);
}
has(element: T | null): boolean {
return this.nodes.has(element);
}
getListIndex(element: T | null): number {
const location = this.getElementLocation(element);
return this.model.getListIndex(location);
......
......@@ -108,6 +108,8 @@ export interface ITreeModel<T, TFilterData, TRef> {
readonly onDidChangeCollapseState: Event<ICollapseStateChangeEvent<T, TFilterData>>;
readonly onDidChangeRenderNodeCount: Event<ITreeNode<T, TFilterData>>;
has(location: TRef): boolean;
getListIndex(location: TRef): number;
getListRenderCount(location: TRef): number;
getNode(location?: TRef): ITreeNode<T, any>;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册