Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
4b7614ff
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,发现更多精彩内容 >>
提交
4b7614ff
编写于
11月 30, 2018
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add word based provider #64004, add multi-provider merge logic #63935
上级
aa3ea85b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
90 addition
and
6 deletion
+90
-6
src/tsconfig.strictNullChecks.json
src/tsconfig.strictNullChecks.json
+2
-1
src/vs/editor/contrib/smartSelect/smartSelect.ts
src/vs/editor/contrib/smartSelect/smartSelect.ts
+57
-5
src/vs/editor/contrib/smartSelect/wordSelections.ts
src/vs/editor/contrib/smartSelect/wordSelections.ts
+31
-0
未找到文件。
src/tsconfig.strictNullChecks.json
浏览文件 @
4b7614ff
...
...
@@ -336,6 +336,7 @@
"./vs/editor/contrib/rename/rename.ts"
,
"./vs/editor/contrib/rename/renameInputField.ts"
,
"./vs/editor/contrib/smartSelect/smartSelect.ts"
,
"./vs/editor/contrib/smartSelect/wordSelections.ts"
,
"./vs/editor/contrib/smartSelect/tokenTree.ts"
,
"./vs/editor/contrib/snippet/snippetParser.ts"
,
"./vs/editor/contrib/snippet/snippetVariables.ts"
,
...
...
@@ -731,4 +732,4 @@
"exclude"
:
[
"./typings/require-monaco.d.ts"
]
}
\ No newline at end of file
}
src/vs/editor/contrib/smartSelect/smartSelect.ts
浏览文件 @
4b7614ff
...
...
@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import
*
as
arrays
from
'
vs/base/common/arrays
'
;
import
{
asThenable
,
first
}
from
'
vs/base/common/async
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
KeyCode
,
KeyMod
}
from
'
vs/base/common/keyCodes
'
;
import
{
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
...
...
@@ -20,6 +19,7 @@ import { MenuId } from 'vs/platform/actions/common/actions';
import
{
KeybindingWeight
}
from
'
vs/platform/keybinding/common/keybindingsRegistry
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
TokenTreeSelectionRangeProvider
}
from
'
vs/editor/contrib/smartSelect/tokenTree
'
;
import
{
WordSelectionRangeProvider
}
from
'
vs/editor/contrib/smartSelect/wordSelections
'
;
class
SelectionRanges
{
...
...
@@ -200,9 +200,61 @@ registerEditorContribution(SmartSelectController);
registerEditorAction
(
GrowSelectionAction
);
registerEditorAction
(
ShrinkSelectionAction
);
modes
.
SelectionRangeRegistry
.
register
(
'
*
'
,
new
WordSelectionRangeProvider
());
modes
.
SelectionRangeRegistry
.
register
(
'
*
'
,
new
TokenTreeSelectionRangeProvider
());
export
function
provideSelectionRanges
(
model
:
ITextModel
,
position
:
Position
,
token
:
CancellationToken
):
Promise
<
Range
[]
|
undefined
|
null
>
{
const
provider
=
modes
.
SelectionRangeRegistry
.
ordered
(
model
);
return
first
(
provider
.
map
(
pro
=>
()
=>
asThenable
(()
=>
pro
.
provideSelectionRanges
(
model
,
position
,
token
))),
arrays
.
isNonEmptyArray
);
}
modes
.
SelectionRangeRegistry
.
register
(
'
*
'
,
new
TokenTreeSelectionRangeProvider
());
const
provider
=
modes
.
SelectionRangeRegistry
.
orderedGroups
(
model
);
interface
RankedRange
{
rank
:
number
;
range
:
Range
;
}
let
work
:
Promise
<
any
>
[]
=
[];
let
ranges
:
RankedRange
[]
=
[];
let
rank
=
0
;
for
(
const
group
of
provider
)
{
rank
+=
1
;
for
(
const
prov
of
group
)
{
work
.
push
(
Promise
.
resolve
(
prov
.
provideSelectionRanges
(
model
,
position
,
token
)).
then
(
res
=>
{
if
(
arrays
.
isNonEmptyArray
(
res
))
{
for
(
const
range
of
res
)
{
if
(
Range
.
isIRange
(
range
)
&&
Range
.
containsPosition
(
range
,
position
))
{
ranges
.
push
({
range
,
rank
});
}
}
}
}));
}
}
return
Promise
.
all
(
work
).
then
(()
=>
{
ranges
.
sort
((
a
,
b
)
=>
{
if
(
Position
.
isBefore
(
a
.
range
.
getStartPosition
(),
b
.
range
.
getStartPosition
()))
{
return
1
;
}
else
if
(
Position
.
isBefore
(
b
.
range
.
getStartPosition
(),
a
.
range
.
getStartPosition
()))
{
return
-
1
;
}
else
if
(
Position
.
isBefore
(
a
.
range
.
getEndPosition
(),
b
.
range
.
getEndPosition
()))
{
return
-
1
;
}
else
if
(
Position
.
isBefore
(
b
.
range
.
getEndPosition
(),
a
.
range
.
getEndPosition
()))
{
return
1
;
}
else
{
return
b
.
rank
-
a
.
rank
;
}
});
// ranges.sort((a, b) => Range.compareRangesUsingStarts(b.range, a.range));
let
result
:
Range
[]
=
[];
let
last
:
Range
|
undefined
;
for
(
const
{
range
}
of
ranges
)
{
if
(
!
last
||
Range
.
containsRange
(
range
,
last
))
{
result
.
push
(
range
);
last
=
range
;
}
}
return
result
;
});
}
src/vs/editor/contrib/smartSelect/wordSelections.ts
0 → 100644
浏览文件 @
4b7614ff
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
SelectionRangeProvider
}
from
'
vs/editor/common/modes
'
;
import
{
ITextModel
}
from
'
vs/editor/common/model
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
export
class
WordSelectionRangeProvider
implements
SelectionRangeProvider
{
provideSelectionRanges
(
model
:
ITextModel
,
position
:
Position
):
Range
[]
{
let
result
:
Range
[]
=
[];
this
.
_addWordRanges
(
result
,
model
,
position
);
this
.
_addLineRanges
(
result
,
model
,
position
);
return
result
;
}
private
_addWordRanges
(
bucket
:
Range
[],
model
:
ITextModel
,
pos
:
Position
):
void
{
const
word
=
model
.
getWordAtPosition
(
pos
);
if
(
word
)
{
bucket
.
push
(
new
Range
(
pos
.
lineNumber
,
word
.
startColumn
,
pos
.
lineNumber
,
word
.
endColumn
));
}
}
private
_addLineRanges
(
bucket
:
Range
[],
model
:
ITextModel
,
pos
:
Position
):
void
{
bucket
.
push
(
new
Range
(
pos
.
lineNumber
,
model
.
getLineFirstNonWhitespaceColumn
(
pos
.
lineNumber
),
pos
.
lineNumber
,
model
.
getLineLastNonWhitespaceColumn
(
pos
.
lineNumber
)));
bucket
.
push
(
new
Range
(
pos
.
lineNumber
,
model
.
getLineMinColumn
(
pos
.
lineNumber
),
pos
.
lineNumber
,
model
.
getLineMaxColumn
(
pos
.
lineNumber
)));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录