Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
22fb3b4e
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,发现更多精彩内容 >>
提交
22fb3b4e
编写于
12月 10, 2018
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
smart select for comment, string, and regexp ranges
上级
12b6329a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
82 addition
and
1 deletion
+82
-1
src/vs/editor/contrib/smartSelect/wordSelections.ts
src/vs/editor/contrib/smartSelect/wordSelections.ts
+82
-1
未找到文件。
src/vs/editor/contrib/smartSelect/wordSelections.ts
浏览文件 @
22fb3b4e
...
...
@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
SelectionRangeProvider
}
from
'
vs/editor/common/modes
'
;
import
{
SelectionRangeProvider
,
StandardTokenType
}
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
'
;
...
...
@@ -13,6 +13,7 @@ export class WordSelectionRangeProvider implements SelectionRangeProvider {
provideSelectionRanges
(
model
:
ITextModel
,
position
:
Position
):
Range
[]
{
let
result
:
Range
[]
=
[];
this
.
_addWordRanges
(
result
,
model
,
position
);
this
.
_addTokenRange
(
result
,
model
,
position
);
this
.
_addLineRanges
(
result
,
model
,
position
);
return
result
;
}
...
...
@@ -24,6 +25,86 @@ export class WordSelectionRangeProvider implements SelectionRangeProvider {
}
}
private
_addTokenRange
(
bucket
:
Range
[],
model
:
ITextModel
,
pos
:
Position
):
void
{
const
tokens
=
model
.
getLineTokens
(
pos
.
lineNumber
);
const
index
=
tokens
.
findTokenIndexAtOffset
(
pos
.
column
-
1
);
const
type
=
tokens
.
getStandardTokenType
(
index
);
if
(
type
===
StandardTokenType
.
Other
)
{
return
;
}
// grow left
let
left
:
Position
|
undefined
;
{
let
leftIndex
=
index
;
let
leftTokens
=
tokens
;
let
leftLine
=
pos
.
lineNumber
;
while
(
!
left
)
{
let
newLeftIndex
=
leftIndex
-
1
;
if
(
newLeftIndex
<
0
)
{
if
(
leftLine
>
1
)
{
leftLine
-=
1
;
leftTokens
=
model
.
getLineTokens
(
leftLine
);
leftIndex
=
leftTokens
.
getCount
();
}
else
{
left
=
new
Position
(
1
,
1
);
}
}
else
{
if
(
leftTokens
.
getStandardTokenType
(
newLeftIndex
)
===
type
)
{
leftIndex
=
newLeftIndex
;
}
else
{
if
(
newLeftIndex
===
leftTokens
.
getCount
()
-
1
)
{
// we got here but there was nothing
left
=
new
Position
(
leftLine
+
1
,
1
);
}
else
{
left
=
new
Position
(
leftLine
,
leftTokens
.
getStartOffset
(
leftIndex
)
+
1
);
}
}
}
}
}
// grow right
let
right
:
Position
|
undefined
;
{
let
rightIndex
=
index
;
let
rightTokens
=
tokens
;
let
rightLine
=
pos
.
lineNumber
;
while
(
!
right
)
{
let
newRightIndex
=
rightIndex
+
1
;
if
(
newRightIndex
>=
rightTokens
.
getCount
())
{
if
(
rightLine
<
model
.
getLineCount
())
{
rightLine
+=
1
;
rightTokens
=
model
.
getLineTokens
(
rightLine
);
rightIndex
=
-
1
;
}
else
{
right
=
new
Position
(
model
.
getLineCount
(),
model
.
getLineMaxColumn
(
model
.
getLineCount
()));
}
}
else
{
if
(
rightTokens
.
getStandardTokenType
(
newRightIndex
)
===
type
)
{
rightIndex
=
newRightIndex
;
}
else
{
if
(
newRightIndex
===
0
)
{
// we got here but there was nothing
right
=
new
Position
(
rightLine
-
1
,
model
.
getLineMaxColumn
(
rightLine
-
1
));
}
else
{
right
=
new
Position
(
rightLine
,
rightTokens
.
getEndOffset
(
rightIndex
)
+
1
);
}
}
}
}
}
if
(
type
===
StandardTokenType
.
String
)
{
// just assume that quotation marks are length=1
bucket
.
push
(
Range
.
fromPositions
(
left
.
delta
(
0
,
1
),
right
.
delta
(
0
,
-
1
)));
bucket
.
push
(
Range
.
fromPositions
(
left
,
right
));
}
else
{
bucket
.
push
(
Range
.
fromPositions
(
left
,
right
));
}
}
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录