Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
377c4737
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
377c4737
编写于
7月 22, 2019
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
LinearCompressedObjectTreeModel
上级
ea36e04b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
132 addition
and
0 deletion
+132
-0
src/vs/base/browser/ui/tree/compressedObjectTreeModel.ts
src/vs/base/browser/ui/tree/compressedObjectTreeModel.ts
+132
-0
未找到文件。
src/vs/base/browser/ui/tree/compressedObjectTreeModel.ts
浏览文件 @
377c4737
...
...
@@ -270,3 +270,135 @@ export class CompressedObjectTreeModel<T extends NonNullable<any>, TFilterData e
return
node
;
}
}
export
type
ElementMapper
<
T
>
=
(
elements
:
T
[])
=>
T
;
export
const
DefaultElementMapper
:
ElementMapper
<
any
>
=
elements
=>
elements
[
elements
.
length
-
1
];
export
type
NodeMapper
<
T
,
TFilterData
>
=
(
node
:
ITreeNode
<
ICompressedTreeNode
<
T
>
|
null
,
TFilterData
>
)
=>
ITreeNode
<
T
|
null
,
TFilterData
>
;
function
mapNode
<
T
,
TFilterData
>
(
elementMapper
:
ElementMapper
<
T
>
,
node
:
ITreeNode
<
ICompressedTreeNode
<
T
>
|
null
,
TFilterData
>
):
ITreeNode
<
T
|
null
,
TFilterData
>
{
return
{
...
node
,
element
:
node
.
element
===
null
?
null
:
elementMapper
(
node
.
element
.
elements
),
children
:
node
.
children
.
map
(
child
=>
mapNode
(
elementMapper
,
child
)),
parent
:
typeof
node
.
parent
===
'
undefined
'
?
node
.
parent
:
mapNode
(
elementMapper
,
node
.
parent
)
};
}
function
createNodeMapper
<
T
,
TFilterData
>
(
elementMapper
:
ElementMapper
<
T
>
):
NodeMapper
<
T
,
TFilterData
>
{
return
node
=>
mapNode
(
elementMapper
,
node
);
}
export
interface
ILinearCompressedObjectTreeModelOptions
<
T
,
TFilterData
>
extends
ICompressedObjectTreeModelOptions
<
T
,
TFilterData
>
{
readonly
elementMapper
?:
ElementMapper
<
T
>
;
}
export
class
LinearCompressedObjectTreeModel
<
T
extends
NonNullable
<
any
>
,
TFilterData
extends
NonNullable
<
any
>
=
void
>
implements
ITreeModel
<
T
|
null
,
TFilterData
,
T
|
null
>
{
readonly
rootRef
=
null
;
get
onDidSplice
():
Event
<
ITreeModelSpliceEvent
<
T
|
null
,
TFilterData
>>
{
return
Event
.
map
(
this
.
model
.
onDidSplice
,
({
insertedNodes
,
deletedNodes
})
=>
({
insertedNodes
:
insertedNodes
.
map
(
this
.
mapNode
),
deletedNodes
:
deletedNodes
.
map
(
this
.
mapNode
),
}));
}
get
onDidChangeCollapseState
():
Event
<
ICollapseStateChangeEvent
<
T
|
null
,
TFilterData
>>
{
return
Event
.
map
(
this
.
model
.
onDidChangeCollapseState
,
({
node
,
deep
})
=>
({
node
:
this
.
mapNode
(
node
),
deep
}));
}
get
onDidChangeRenderNodeCount
():
Event
<
ITreeNode
<
T
|
null
,
TFilterData
>>
{
return
Event
.
map
(
this
.
model
.
onDidChangeRenderNodeCount
,
this
.
mapNode
);
}
private
mapElement
:
ElementMapper
<
T
|
null
>
;
private
mapNode
:
NodeMapper
<
T
|
null
,
TFilterData
>
;
private
model
:
CompressedObjectTreeModel
<
T
,
TFilterData
>
;
constructor
(
list
:
ISpliceable
<
ITreeNode
<
ICompressedTreeNode
<
T
>
,
TFilterData
>>
,
options
:
ILinearCompressedObjectTreeModelOptions
<
T
,
TFilterData
>
=
{}
)
{
this
.
mapElement
=
options
.
elementMapper
||
DefaultElementMapper
;
this
.
mapNode
=
createNodeMapper
(
this
.
mapElement
);
this
.
model
=
new
CompressedObjectTreeModel
(
list
,
options
);
}
getListIndex
(
location
:
T
|
null
):
number
{
return
this
.
model
.
getListIndex
(
location
);
}
getListRenderCount
(
location
:
T
|
null
):
number
{
return
this
.
model
.
getListRenderCount
(
location
);
}
getNode
(
location
?:
T
|
null
|
undefined
):
ITreeNode
<
T
|
null
,
any
>
{
return
this
.
mapNode
(
this
.
model
.
getNode
(
location
));
}
getNodeLocation
(
node
:
ITreeNode
<
T
|
null
,
any
>
):
T
|
null
{
return
node
.
element
;
}
getParentNodeLocation
(
location
:
T
|
null
):
T
|
null
{
return
this
.
model
.
getParentNodeLocation
(
location
);
}
getParentElement
(
location
:
T
|
null
):
T
|
null
{
const
result
=
this
.
model
.
getParentElement
(
location
);
if
(
result
===
null
)
{
return
result
;
}
return
this
.
mapElement
(
result
.
elements
);
}
getFirstElementChild
(
location
:
T
|
null
):
T
|
null
|
undefined
{
const
result
=
this
.
model
.
getFirstElementChild
(
location
);
if
(
result
===
null
||
typeof
result
===
'
undefined
'
)
{
return
result
;
}
return
this
.
mapElement
(
result
.
elements
);
}
getLastElementAncestor
(
location
?:
T
|
null
|
undefined
):
T
|
null
|
undefined
{
const
result
=
this
.
model
.
getLastElementAncestor
(
location
);
if
(
result
===
null
||
typeof
result
===
'
undefined
'
)
{
return
result
;
}
return
this
.
mapElement
(
result
.
elements
);
}
isCollapsible
(
location
:
T
|
null
):
boolean
{
return
this
.
model
.
isCollapsible
(
location
);
}
isCollapsed
(
location
:
T
|
null
):
boolean
{
return
this
.
model
.
isCollapsed
(
location
);
}
setCollapsed
(
location
:
T
|
null
,
collapsed
?:
boolean
|
undefined
,
recursive
?:
boolean
|
undefined
):
boolean
{
return
this
.
model
.
setCollapsed
(
location
,
collapsed
,
recursive
);
}
expandTo
(
location
:
T
|
null
):
void
{
return
this
.
model
.
expandTo
(
location
);
}
rerender
(
location
:
T
|
null
):
void
{
return
this
.
model
.
rerender
(
location
);
}
refilter
():
void
{
return
this
.
model
.
refilter
();
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录