Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
b60b3903
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,发现更多精彩内容 >>
提交
b60b3903
编写于
7月 05, 2018
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
less nervous breadcrumbs model
上级
a53ae59c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
72 addition
and
39 deletion
+72
-39
src/vs/workbench/browser/parts/editor/editorBreadcrumbsModel.ts
.../workbench/browser/parts/editor/editorBreadcrumbsModel.ts
+72
-39
未找到文件。
src/vs/workbench/browser/parts/editor/editorBreadcrumbsModel.ts
浏览文件 @
b60b3903
...
@@ -5,18 +5,21 @@
...
@@ -5,18 +5,21 @@
'
use strict
'
;
'
use strict
'
;
import
{
OutlineModel
,
OutlineGroup
,
OutlineElement
}
from
'
vs/editor/contrib/documentSymbols/outlineModel
'
;
import
{
equals
}
from
'
vs/base/common/arrays
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
TimeoutTimer
}
from
'
vs/base/common/async
'
;
import
{
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
CancellationTokenSource
}
from
'
vs/base/common/cancellation
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
size
}
from
'
vs/base/common/collections
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
debounceEvent
,
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
import
{
dispose
,
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
*
as
paths
from
'
vs/base/common/paths
'
;
import
*
as
paths
from
'
vs/base/common/paths
'
;
import
{
isEqual
}
from
'
vs/base/common/resources
'
;
import
{
isEqual
}
from
'
vs/base/common/resources
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
IPosition
}
from
'
vs/editor/common/core/position
'
;
import
{
DocumentSymbolProviderRegistry
}
from
'
vs/editor/common/modes
'
;
import
{
DocumentSymbolProviderRegistry
}
from
'
vs/editor/common/modes
'
;
import
{
CancellationTokenSource
}
from
'
vs/base/common/cancellation
'
;
import
{
OutlineElement
,
OutlineGroup
,
OutlineModel
}
from
'
vs/editor/contrib/documentSymbols/outlineModel
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
debounceEvent
,
Event
,
Emitter
}
from
'
vs/base/common/event
'
;
import
{
size
}
from
'
vs/base/common/collections
'
;
export
class
FileElement
{
export
class
FileElement
{
constructor
(
constructor
(
...
@@ -31,8 +34,9 @@ export class EditorBreadcrumbsModel {
...
@@ -31,8 +34,9 @@ export class EditorBreadcrumbsModel {
private
readonly
_disposables
:
IDisposable
[]
=
[];
private
readonly
_disposables
:
IDisposable
[]
=
[];
private
readonly
_fileElements
:
FileElement
[]
=
[];
private
readonly
_fileElements
:
FileElement
[]
=
[];
private
_outlineElements
:
(
OutlineGroup
|
OutlineElement
)[]
=
[];
private
_outlineDisposables
:
IDisposable
[]
=
[];
private
_outlineDisposables
:
IDisposable
[]
=
[];
private
_outlineModel
:
OutlineModel
;
private
_onDidUpdate
=
new
Emitter
<
this
>
();
private
_onDidUpdate
=
new
Emitter
<
this
>
();
readonly
onDidUpdate
:
Event
<
this
>
=
this
.
_onDidUpdate
.
event
;
readonly
onDidUpdate
:
Event
<
this
>
=
this
.
_onDidUpdate
.
event
;
...
@@ -52,25 +56,7 @@ export class EditorBreadcrumbsModel {
...
@@ -52,25 +56,7 @@ export class EditorBreadcrumbsModel {
}
}
getElements
():
ReadonlyArray
<
BreadcrumbElement
>
{
getElements
():
ReadonlyArray
<
BreadcrumbElement
>
{
if
(
!
this
.
_editor
||
!
this
.
_outlineModel
)
{
return
[].
concat
(
this
.
_fileElements
,
this
.
_outlineElements
);
return
this
.
_fileElements
;
}
let
item
:
OutlineGroup
|
OutlineElement
=
this
.
_outlineModel
.
getItemEnclosingPosition
(
this
.
_editor
.
getPosition
());
let
items
:
(
OutlineGroup
|
OutlineElement
)[]
=
[];
while
(
item
)
{
items
.
push
(
item
);
let
parent
=
item
.
parent
;
if
(
parent
instanceof
OutlineModel
)
{
break
;
}
if
(
parent
instanceof
OutlineGroup
&&
size
(
parent
.
parent
.
children
)
===
1
)
{
break
;
}
item
=
parent
;
}
return
(
this
.
_fileElements
as
BreadcrumbElement
[]).
concat
(
items
.
reverse
());
}
}
private
static
_getFileElements
(
uri
:
URI
,
workspaceService
:
IWorkspaceContextService
):
FileElement
[]
{
private
static
_getFileElements
(
uri
:
URI
,
workspaceService
:
IWorkspaceContextService
):
FileElement
[]
{
...
@@ -96,15 +82,18 @@ export class EditorBreadcrumbsModel {
...
@@ -96,15 +82,18 @@ export class EditorBreadcrumbsModel {
this
.
_disposables
.
push
(
DocumentSymbolProviderRegistry
.
onDidChange
(
_
=>
this
.
_updateOutline
()));
this
.
_disposables
.
push
(
DocumentSymbolProviderRegistry
.
onDidChange
(
_
=>
this
.
_updateOutline
()));
this
.
_disposables
.
push
(
this
.
_editor
.
onDidChangeModel
(
_
=>
this
.
_updateOutline
()));
this
.
_disposables
.
push
(
this
.
_editor
.
onDidChangeModel
(
_
=>
this
.
_updateOutline
()));
this
.
_disposables
.
push
(
this
.
_editor
.
onDidChangeModelLanguage
(
_
=>
this
.
_updateOutline
()));
this
.
_disposables
.
push
(
this
.
_editor
.
onDidChangeModelLanguage
(
_
=>
this
.
_updateOutline
()));
this
.
_disposables
.
push
(
debounceEvent
(
this
.
_editor
.
onDidChangeModelContent
,
_
=>
_
,
350
)(
_
=>
this
.
_updateOutline
()));
this
.
_disposables
.
push
(
debounceEvent
(
this
.
_editor
.
onDidChangeModelContent
,
_
=>
_
,
350
)(
_
=>
this
.
_updateOutline
(
true
)));
}
}
private
_updateOutline
():
void
{
private
_updateOutline
(
didChangeContent
?:
boolean
):
void
{
this
.
_outlineDisposables
=
dispose
(
this
.
_outlineDisposables
);
this
.
_outlineDisposables
=
dispose
(
this
.
_outlineDisposables
);
if
(
!
didChangeContent
)
{
this
.
_updateOutlineElements
([]);
}
const
model
=
this
.
_editor
.
getModel
();
const
buffer
=
this
.
_editor
.
getModel
();
if
(
!
model
||
!
DocumentSymbolProviderRegistry
.
has
(
model
)
||
!
isEqual
(
model
.
uri
,
this
.
_uri
))
{
if
(
!
buffer
||
!
DocumentSymbolProviderRegistry
.
has
(
buffer
)
||
!
isEqual
(
buffer
.
uri
,
this
.
_uri
))
{
return
;
return
;
}
}
...
@@ -116,14 +105,58 @@ export class EditorBreadcrumbsModel {
...
@@ -116,14 +105,58 @@ export class EditorBreadcrumbsModel {
source
.
dispose
();
source
.
dispose
();
}
}
});
});
OutlineModel
.
create
(
model
,
source
.
token
).
then
(
model
=>
{
OutlineModel
.
create
(
buffer
,
source
.
token
).
then
(
model
=>
{
this
.
_outlineModel
=
model
;
this
.
_updateOutlineElements
(
this
.
_getOutlineElements
(
model
,
this
.
_editor
.
getPosition
()));
this
.
_onDidUpdate
.
fire
(
this
);
const
timeout
=
new
TimeoutTimer
();
this
.
_outlineDisposables
.
push
(
debounceEvent
(
this
.
_editor
.
onDidChangeCursorPosition
,
_
=>
_
,
250
)(
_
=>
this
.
_onDidUpdate
.
fire
(
this
)));
const
lastVersionId
=
buffer
.
getVersionId
();
this
.
_outlineDisposables
.
push
(
this
.
_editor
.
onDidChangeCursorPosition
(
_
=>
{
timeout
.
cancelAndSet
(()
=>
{
if
(
lastVersionId
===
buffer
.
getVersionId
())
{
this
.
_updateOutlineElements
(
this
.
_getOutlineElements
(
model
,
this
.
_editor
.
getPosition
()));
}
},
150
);
}));
this
.
_outlineDisposables
.
push
(
timeout
);
}).
catch
(
err
=>
{
}).
catch
(
err
=>
{
this
.
_outlineModel
=
undefined
;
this
.
_updateOutlineElements
([]);
this
.
_onDidUpdate
.
fire
(
this
);
onUnexpectedError
(
err
);
onUnexpectedError
(
err
);
});
});
}
}
private
_getOutlineElements
(
model
:
OutlineModel
,
position
:
IPosition
):
(
OutlineGroup
|
OutlineElement
)[]
{
if
(
!
model
)
{
return
[];
}
let
item
:
OutlineGroup
|
OutlineElement
=
model
.
getItemEnclosingPosition
(
position
);
let
chain
:
(
OutlineGroup
|
OutlineElement
)[]
=
[];
while
(
item
)
{
chain
.
push
(
item
);
let
parent
=
item
.
parent
;
if
(
parent
instanceof
OutlineModel
)
{
break
;
}
if
(
parent
instanceof
OutlineGroup
&&
size
(
parent
.
parent
.
children
)
===
1
)
{
break
;
}
item
=
parent
;
}
return
chain
;
}
private
_updateOutlineElements
(
elements
:
(
OutlineGroup
|
OutlineElement
)[]):
void
{
if
(
!
equals
(
elements
,
this
.
_outlineElements
,
EditorBreadcrumbsModel
.
outlineElementEquals
))
{
this
.
_outlineElements
=
elements
;
this
.
_onDidUpdate
.
fire
(
this
);
}
}
private
static
outlineElementEquals
(
a
:
OutlineGroup
|
OutlineElement
,
b
:
OutlineGroup
|
OutlineElement
):
boolean
{
if
(
a
===
b
)
{
return
true
;
}
else
if
(
!
a
||
!
b
)
{
return
false
;
}
else
{
return
a
.
id
===
b
.
id
;
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录