Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
a1a86361
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
a1a86361
编写于
6月 14, 2019
作者:
J
João Moreno
提交者:
GitHub
6月 14, 2019
浏览文件
操作
浏览文件
下载
差异文件
object tree: preverve collapse state by id (#74462)
上级
6a054572
3ae07645
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
8 deletion
+32
-8
src/vs/base/browser/ui/tree/objectTreeModel.ts
src/vs/base/browser/ui/tree/objectTreeModel.ts
+29
-2
src/vs/workbench/contrib/preferences/browser/tocTree.ts
src/vs/workbench/contrib/preferences/browser/tocTree.ts
+3
-6
未找到文件。
src/vs/base/browser/ui/tree/objectTreeModel.ts
浏览文件 @
a1a86361
...
...
@@ -8,9 +8,11 @@ import { Iterator, ISequence, getSequenceIterator } from 'vs/base/common/iterato
import
{
IndexTreeModel
,
IIndexTreeModelOptions
}
from
'
vs/base/browser/ui/tree/indexTreeModel
'
;
import
{
Event
}
from
'
vs/base/common/event
'
;
import
{
ITreeModel
,
ITreeNode
,
ITreeElement
,
ITreeSorter
,
ICollapseStateChangeEvent
,
ITreeModelSpliceEvent
}
from
'
vs/base/browser/ui/tree/tree
'
;
import
{
IIdentityProvider
}
from
'
vs/base/browser/ui/list/list
'
;
export
interface
IObjectTreeModelOptions
<
T
,
TFilterData
>
extends
IIndexTreeModelOptions
<
T
,
TFilterData
>
{
readonly
sorter
?:
ITreeSorter
<
T
>
;
readonly
identityProvider
?:
IIdentityProvider
<
T
>
;
}
export
class
ObjectTreeModel
<
T
extends
NonNullable
<
any
>
,
TFilterData
extends
NonNullable
<
any
>
=
void
>
implements
ITreeModel
<
T
|
null
,
TFilterData
,
T
|
null
>
{
...
...
@@ -19,6 +21,8 @@ export class ObjectTreeModel<T extends NonNullable<any>, TFilterData extends Non
private
model
:
IndexTreeModel
<
T
|
null
,
TFilterData
>
;
private
nodes
=
new
Map
<
T
|
null
,
ITreeNode
<
T
,
TFilterData
>>
();
private
readonly
nodesByIdentity
=
new
Map
<
string
,
ITreeNode
<
T
,
TFilterData
>>
();
private
readonly
identityProvider
?:
IIdentityProvider
<
T
>
;
private
sorter
?:
ITreeSorter
<
{
element
:
T
;
}
>
;
readonly
onDidSplice
:
Event
<
ITreeModelSpliceEvent
<
T
|
null
,
TFilterData
>>
;
...
...
@@ -40,6 +44,8 @@ export class ObjectTreeModel<T extends NonNullable<any>, TFilterData extends Non
}
};
}
this
.
identityProvider
=
options
.
identityProvider
;
}
setChildren
(
...
...
@@ -59,11 +65,18 @@ export class ObjectTreeModel<T extends NonNullable<any>, TFilterData extends Non
onDidDeleteNode
?:
(
node
:
ITreeNode
<
T
,
TFilterData
>
)
=>
void
):
Iterator
<
ITreeElement
<
T
|
null
>>
{
const
insertedElements
=
new
Set
<
T
|
null
>
();
const
insertedElementIds
=
new
Set
<
string
>
();
const
_onDidCreateNode
=
(
node
:
ITreeNode
<
T
,
TFilterData
>
)
=>
{
insertedElements
.
add
(
node
.
element
);
this
.
nodes
.
set
(
node
.
element
,
node
);
if
(
this
.
identityProvider
)
{
const
id
=
this
.
identityProvider
.
getId
(
node
.
element
).
toString
();
insertedElementIds
.
add
(
id
);
this
.
nodesByIdentity
.
set
(
id
,
node
);
}
if
(
onDidCreateNode
)
{
onDidCreateNode
(
node
);
}
...
...
@@ -74,18 +87,27 @@ export class ObjectTreeModel<T extends NonNullable<any>, TFilterData extends Non
this
.
nodes
.
delete
(
node
.
element
);
}
if
(
this
.
identityProvider
)
{
const
id
=
this
.
identityProvider
.
getId
(
node
.
element
).
toString
();
if
(
!
insertedElementIds
.
has
(
id
))
{
this
.
nodesByIdentity
.
delete
(
id
);
}
}
if
(
onDidDeleteNode
)
{
onDidDeleteNode
(
node
);
}
};
return
this
.
model
.
splice
(
const
result
=
this
.
model
.
splice
(
[...
location
,
0
],
Number
.
MAX_VALUE
,
children
,
_onDidCreateNode
,
_onDidDeleteNode
);
return
result
;
}
private
preserveCollapseState
(
elements
:
ISequence
<
ITreeElement
<
T
>>
|
undefined
):
ISequence
<
ITreeElement
<
T
>>
{
...
...
@@ -96,7 +118,12 @@ export class ObjectTreeModel<T extends NonNullable<any>, TFilterData extends Non
}
return
Iterator
.
map
(
iterator
,
treeElement
=>
{
const
node
=
this
.
nodes
.
get
(
treeElement
.
element
);
let
node
=
this
.
nodes
.
get
(
treeElement
.
element
);
if
(
!
node
&&
this
.
identityProvider
)
{
const
id
=
this
.
identityProvider
.
getId
(
treeElement
.
element
).
toString
();
node
=
this
.
nodesByIdentity
.
get
(
id
);
}
if
(
!
node
)
{
return
{
...
...
src/vs/workbench/contrib/preferences/browser/tocTree.ts
浏览文件 @
a1a86361
...
...
@@ -141,16 +141,12 @@ export function createTOCIterator(model: TOCTreeModel | SettingsTreeGroupElement
const
groupChildren
=
<
SettingsTreeGroupElement
[]
>
model
.
children
.
filter
(
c
=>
c
instanceof
SettingsTreeGroupElement
);
const
groupsIt
=
Iterator
.
fromArray
(
groupChildren
);
return
Iterator
.
map
(
groupsIt
,
g
=>
{
let
nodeExists
=
true
;
try
{
tree
.
getNode
(
g
);
}
catch
(
e
)
{
nodeExists
=
false
;
}
const
hasGroupChildren
=
g
.
children
.
some
(
c
=>
c
instanceof
SettingsTreeGroupElement
);
return
{
element
:
g
,
collapsed
:
nodeExists
?
undefined
:
true
,
collapsed
:
undefined
,
collapsible
:
hasGroupChildren
,
children
:
g
instanceof
SettingsTreeGroupElement
?
createTOCIterator
(
g
,
tree
)
:
...
...
@@ -203,7 +199,8 @@ export class TOCTree extends ObjectTree<SettingsTreeGroupElement> {
}
},
styleController
:
new
DefaultStyleController
(
DOM
.
createStyleSheet
(
container
),
treeClass
),
accessibilityProvider
:
instantiationService
.
createInstance
(
SettingsAccessibilityProvider
)
accessibilityProvider
:
instantiationService
.
createInstance
(
SettingsAccessibilityProvider
),
collapseByDefault
:
true
};
super
(
container
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录