Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
ba26877c
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,体验更适合开发者的 AI 搜索 >>
提交
ba26877c
编写于
11月 11, 2019
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add controller, add navigation functions, add commands
上级
5207eade
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
135 addition
and
0 deletion
+135
-0
src/vs/editor/contrib/documentSymbols/outlineModel.ts
src/vs/editor/contrib/documentSymbols/outlineModel.ts
+20
-0
src/vs/editor/contrib/documentSymbols/outlineNavigation.ts
src/vs/editor/contrib/documentSymbols/outlineNavigation.ts
+114
-0
src/vs/editor/editor.all.ts
src/vs/editor/editor.all.ts
+1
-0
未找到文件。
src/vs/editor/contrib/documentSymbols/outlineModel.ts
浏览文件 @
ba26877c
...
...
@@ -29,6 +29,26 @@ export abstract class TreeElement {
}
}
// todo@joh sort by position!
firstChild
():
TreeElement
|
undefined
{
const
[
first
]
=
Object
.
keys
(
this
.
children
);
return
this
.
children
[
first
];
}
lastChild
():
TreeElement
|
undefined
{
const
[
last
]
=
Object
.
keys
(
this
.
children
).
slice
(
-
1
);
return
this
.
children
[
last
];
}
sibling
(
next
:
boolean
):
TreeElement
|
undefined
{
if
(
!
this
.
parent
)
{
return
undefined
;
}
const
all
=
Object
.
keys
(
this
.
parent
.
children
);
const
index
=
all
.
indexOf
(
this
.
id
)
+
(
next
?
+
1
:
-
1
);
return
this
.
parent
.
children
[
all
[
index
]];
}
static
findId
(
candidate
:
DocumentSymbol
|
string
,
container
:
TreeElement
):
string
{
// complex id-computation which contains the origin/extension,
// the parent path, and some dedupe logic when names collide
...
...
src/vs/editor/contrib/documentSymbols/outlineNavigation.ts
0 → 100644
浏览文件 @
ba26877c
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
'
vs/css!./media/outlineTree
'
;
import
'
vs/css!./media/symbol-icons
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
OutlineElement
,
OutlineModel
}
from
'
vs/editor/contrib/documentSymbols/outlineModel
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
{
IEditorContribution
}
from
'
vs/editor/common/editorCommon
'
;
import
{
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
CancellationTokenSource
}
from
'
vs/base/common/cancellation
'
;
import
{
EditorStateCancellationTokenSource
,
CodeEditorStateFlag
}
from
'
vs/editor/browser/core/editorState
'
;
import
{
EditorAction
,
registerEditorAction
,
registerEditorContribution
}
from
'
vs/editor/browser/editorExtensions
'
;
import
{
ServicesAccessor
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
EditorContextKeys
}
from
'
vs/editor/common/editorContextKeys
'
;
export
class
OutlineNavigation
implements
IEditorContribution
{
public
static
readonly
ID
=
'
editor.contrib.OutlineNavigation
'
;
public
static
get
(
editor
:
ICodeEditor
):
OutlineNavigation
{
return
editor
.
getContribution
<
OutlineNavigation
>
(
OutlineNavigation
.
ID
);
}
private
readonly
_editor
:
ICodeEditor
;
private
_cts
?:
CancellationTokenSource
;
constructor
(
editor
:
ICodeEditor
,
)
{
this
.
_editor
=
editor
;
}
dispose
():
void
{
if
(
this
.
_cts
)
{
this
.
_cts
.
dispose
(
true
);
}
}
async
goto
(
next
:
boolean
)
{
if
(
this
.
_cts
)
{
this
.
_cts
.
cancel
();
}
if
(
!
this
.
_editor
.
hasModel
())
{
return
;
}
const
textModel
=
this
.
_editor
.
getModel
();
const
position
=
this
.
_editor
.
getPosition
();
this
.
_cts
=
new
EditorStateCancellationTokenSource
(
this
.
_editor
,
CodeEditorStateFlag
.
Position
|
CodeEditorStateFlag
.
Value
|
CodeEditorStateFlag
.
Scroll
);
const
outlineModel
=
await
OutlineModel
.
create
(
textModel
,
this
.
_cts
.
token
);
const
element
=
outlineModel
.
getItemEnclosingPosition
(
position
);
if
(
!
element
)
{
return
;
}
let
nextElement
=
element
.
sibling
(
next
);
if
(
!
nextElement
&&
element
.
parent
)
{
let
nextParent
=
element
.
parent
.
sibling
(
next
);
if
(
nextParent
)
{
nextElement
=
next
?
nextParent
.
firstChild
()
:
nextParent
.
lastChild
();
}
}
if
(
!
(
nextElement
instanceof
OutlineElement
))
{
return
;
}
this
.
_editor
.
setPosition
(
Range
.
lift
(
nextElement
.
symbol
.
selectionRange
).
getStartPosition
());
}
}
registerEditorContribution
(
OutlineNavigation
.
ID
,
OutlineNavigation
);
registerEditorAction
(
class
extends
EditorAction
{
constructor
()
{
super
({
id
:
'
editor.action.gotoNextSymbol
'
,
label
:
localize
(
'
label.next
'
,
"
Go to Next Symbol
"
),
alias
:
'
Go to Next Symbol
'
,
precondition
:
EditorContextKeys
.
hasDocumentSymbolProvider
,
});
}
run
(
_accessor
:
ServicesAccessor
,
editor
:
ICodeEditor
):
void
|
Promise
<
void
>
{
OutlineNavigation
.
get
(
editor
).
goto
(
true
);
}
});
registerEditorAction
(
class
extends
EditorAction
{
constructor
()
{
super
({
id
:
'
editor.action.gotoPrevSymbol
'
,
label
:
localize
(
'
label.prev
'
,
"
Go to Previous Symbol
"
),
alias
:
'
Go to Previous Symbol
'
,
precondition
:
EditorContextKeys
.
hasDocumentSymbolProvider
,
});
}
run
(
_accessor
:
ServicesAccessor
,
editor
:
ICodeEditor
):
void
|
Promise
<
void
>
{
OutlineNavigation
.
get
(
editor
).
goto
(
false
);
}
});
src/vs/editor/editor.all.ts
浏览文件 @
ba26877c
...
...
@@ -18,6 +18,7 @@ import 'vs/editor/contrib/comment/comment';
import
'
vs/editor/contrib/contextmenu/contextmenu
'
;
import
'
vs/editor/contrib/cursorUndo/cursorUndo
'
;
import
'
vs/editor/contrib/dnd/dnd
'
;
import
'
vs/editor/contrib/documentSymbols/outlineNavigation
'
;
import
'
vs/editor/contrib/find/findController
'
;
import
'
vs/editor/contrib/folding/folding
'
;
import
'
vs/editor/contrib/fontZoom/fontZoom
'
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录