Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
d1e4efdc
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,发现更多精彩内容 >>
提交
d1e4efdc
编写于
6月 29, 2018
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tree: do not rerender on collapse state change
上级
ba46974d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
57 addition
and
17 deletion
+57
-17
src/vs/base/browser/ui/tree/tree.ts
src/vs/base/browser/ui/tree/tree.ts
+41
-9
src/vs/base/browser/ui/tree/treeModel.ts
src/vs/base/browser/ui/tree/treeModel.ts
+16
-8
未找到文件。
src/vs/base/browser/ui/tree/tree.ts
浏览文件 @
d1e4efdc
...
...
@@ -4,12 +4,13 @@
*--------------------------------------------------------------------------------------------*/
import
'
vs/css!./tree
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
IDisposable
,
dispose
,
empty
as
EmptyDisposable
,
toDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IListOptions
,
List
,
IIdentityProvider
,
IMultipleSelectionController
}
from
'
vs/base/browser/ui/list/listWidget
'
;
import
{
TreeModel
,
ITreeNode
,
ITreeElement
}
from
'
vs/base/browser/ui/tree/treeModel
'
;
import
{
IIterator
,
empty
}
from
'
vs/base/common/iterator
'
;
import
{
IDelegate
,
IRenderer
,
IListMouseEvent
}
from
'
vs/base/browser/ui/list/list
'
;
import
{
append
,
$
}
from
'
vs/base/browser/dom
'
;
import
{
Event
,
Relay
}
from
'
vs/base/common/event
'
;
function
toTreeListOptions
<
T
>
(
options
?:
IListOptions
<
T
>
):
IListOptions
<
ITreeNode
<
T
>>
{
if
(
!
options
)
{
...
...
@@ -56,15 +57,22 @@ class TreeDelegate<T> implements IDelegate<ITreeNode<T>> {
interface
ITreeListTemplateData
<
T
>
{
twistie
:
HTMLElement
;
elementDisposable
:
IDisposable
;
templateData
:
T
;
}
class
TreeRenderer
<
T
,
TTemplateData
>
implements
IRenderer
<
ITreeNode
<
T
>
,
ITreeListTemplateData
<
TTemplateData
>>
{
readonly
templateId
:
string
;
private
renderedNodes
=
new
Map
<
ITreeNode
<
T
>
,
ITreeListTemplateData
<
TTemplateData
>>
();
private
disposables
:
IDisposable
[]
=
[];
constructor
(
private
renderer
:
IRenderer
<
T
,
TTemplateData
>
)
{
constructor
(
private
renderer
:
IRenderer
<
T
,
TTemplateData
>
,
onDidChangeCollapseState
:
Event
<
ITreeNode
<
T
>>
)
{
this
.
templateId
=
renderer
.
templateId
;
onDidChangeCollapseState
(
this
.
onDidChangeCollapseState
,
this
,
this
.
disposables
);
}
renderTemplate
(
container
:
HTMLElement
):
ITreeListTemplateData
<
TTemplateData
>
{
...
...
@@ -73,20 +81,39 @@ class TreeRenderer<T, TTemplateData> implements IRenderer<ITreeNode<T>, ITreeLis
const
contents
=
append
(
el
,
$
(
'
.tl-contents
'
));
const
templateData
=
this
.
renderer
.
renderTemplate
(
contents
);
return
{
twistie
,
templateData
};
return
{
twistie
,
elementDisposable
:
EmptyDisposable
,
templateData
};
}
renderElement
(
element
:
ITreeNode
<
T
>
,
index
:
number
,
templateData
:
ITreeListTemplateData
<
TTemplateData
>
):
void
{
const
{
twistie
}
=
templateData
;
twistie
.
innerText
=
element
.
children
.
length
===
0
?
''
:
(
element
.
collapsed
?
'
▹
'
:
'
◢
'
);
twistie
.
style
.
width
=
`
${
10
+
element
.
depth
*
10
}
px`
;
renderElement
(
node
:
ITreeNode
<
T
>
,
index
:
number
,
templateData
:
ITreeListTemplateData
<
TTemplateData
>
):
void
{
templateData
.
elementDisposable
.
dispose
();
this
.
renderedNodes
.
set
(
node
,
templateData
);
templateData
.
elementDisposable
=
toDisposable
(()
=>
this
.
renderedNodes
.
delete
(
node
));
this
.
renderer
.
renderElement
(
element
.
element
,
index
,
templateData
.
templateData
);
templateData
.
twistie
.
innerText
=
node
.
children
.
length
===
0
?
''
:
(
node
.
collapsed
?
'
▹
'
:
'
◢
'
);
templateData
.
twistie
.
style
.
width
=
`
${
10
+
node
.
depth
*
10
}
px`
;
this
.
renderer
.
renderElement
(
node
.
element
,
index
,
templateData
.
templateData
);
}
disposeTemplate
(
templateData
:
ITreeListTemplateData
<
TTemplateData
>
):
void
{
this
.
renderer
.
disposeTemplate
(
templateData
.
templateData
);
}
private
onDidChangeCollapseState
(
node
:
ITreeNode
<
T
>
):
void
{
const
templateData
=
this
.
renderedNodes
.
get
(
node
);
if
(
!
templateData
)
{
return
;
}
templateData
.
twistie
.
innerText
=
node
.
children
.
length
===
0
?
''
:
(
node
.
collapsed
?
'
▹
'
:
'
◢
'
);
}
dispose
():
void
{
this
.
renderedNodes
.
clear
();
this
.
disposables
=
dispose
(
this
.
disposables
);
}
}
function
getLocation
<
T
>
(
node
:
ITreeNode
<
T
>
):
number
[]
{
...
...
@@ -113,11 +140,16 @@ export class Tree<T> implements IDisposable {
options
?:
IListOptions
<
T
>
)
{
const
treeDelegate
=
new
TreeDelegate
(
delegate
);
const
treeRenderers
=
renderers
.
map
(
r
=>
new
TreeRenderer
(
r
));
const
onDidChangeCollapseStateRelay
=
new
Relay
<
ITreeNode
<
T
>>
();
const
treeRenderers
=
renderers
.
map
(
r
=>
new
TreeRenderer
(
r
,
onDidChangeCollapseStateRelay
.
event
));
this
.
disposables
.
push
(...
treeRenderers
);
const
treeOptions
=
toTreeListOptions
(
options
);
this
.
view
=
new
List
(
container
,
treeDelegate
,
treeRenderers
,
treeOptions
);
this
.
model
=
new
TreeModel
<
T
>
(
this
.
view
);
onDidChangeCollapseStateRelay
.
input
=
this
.
model
.
onDidChangeCollapseState
;
this
.
view
.
onMouseClick
(
this
.
onMouseClick
,
this
,
this
.
disposables
);
}
...
...
src/vs/base/browser/ui/tree/treeModel.ts
浏览文件 @
d1e4efdc
...
...
@@ -8,6 +8,7 @@
import
{
ISpliceable
}
from
'
vs/base/common/sequence
'
;
import
{
IIterator
,
map
,
collect
,
iter
,
empty
}
from
'
vs/base/common/iterator
'
;
import
{
last
}
from
'
vs/base/common/arrays
'
;
import
{
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
export
interface
ITreeElement
<
T
>
{
readonly
element
:
T
;
...
...
@@ -93,6 +94,9 @@ export class TreeModel<T> {
visibleCount
:
1
};
private
_onDidChangeCollapseState
=
new
Emitter
<
ITreeNode
<
T
>>
();
readonly
onDidChangeCollapseState
:
Event
<
ITreeNode
<
T
>>
=
this
.
_onDidChangeCollapseState
.
event
;
constructor
(
private
list
:
ISpliceable
<
ITreeNode
<
T
>>
)
{
}
splice
(
location
:
number
[],
deleteCount
:
number
,
toInsert
?:
IIterator
<
ITreeElement
<
T
>>
|
ITreeElement
<
T
>
[]):
IIterator
<
ITreeElement
<
T
>>
{
...
...
@@ -125,7 +129,7 @@ export class TreeModel<T> {
}
private
_setCollapsed
(
location
:
number
[],
collapsed
?:
boolean
|
undefined
):
void
{
le
t
{
node
,
listIndex
,
visible
}
=
this
.
findNode
(
location
);
cons
t
{
node
,
listIndex
,
visible
}
=
this
.
findNode
(
location
);
if
(
typeof
collapsed
===
'
undefined
'
)
{
collapsed
=
!
node
.
collapsed
;
...
...
@@ -143,19 +147,23 @@ export class TreeModel<T> {
if
(
collapsed
)
{
const
deleteCount
=
getVisibleCount
(
node
.
children
);
this
.
list
.
splice
(
listIndex
,
1
+
deleteCount
,
[
node
]);
this
.
list
.
splice
(
listIndex
+
1
,
deleteCount
,
[
]);
visibleCountDiff
=
-
deleteCount
;
}
else
{
const
toInsert
=
[
node
,
...
getVisibleNodes
(
node
.
children
)]
;
const
toInsert
=
getVisibleNodes
(
node
.
children
)
;
this
.
list
.
splice
(
listIndex
,
1
,
toInsert
);
visibleCountDiff
=
toInsert
.
length
-
1
;
this
.
list
.
splice
(
listIndex
+
1
,
0
,
toInsert
);
visibleCountDiff
=
toInsert
.
length
;
}
while
(
node
)
{
node
.
visibleCount
+=
visibleCountDiff
;
node
=
node
.
parent
;
let
mutableNode
=
node
;
while
(
mutableNode
)
{
mutableNode
.
visibleCount
+=
visibleCountDiff
;
mutableNode
=
mutableNode
.
parent
;
}
this
.
_onDidChangeCollapseState
.
fire
(
node
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录