Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
32302709
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,发现更多精彩内容 >>
未验证
提交
32302709
编写于
10月 17, 2019
作者:
A
Alexandru Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes #43371: Add `selectBrackets` argument to 'Select to Bracket' action
上级
dc95a4ea
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
67 addition
and
30 deletion
+67
-30
src/vs/editor/contrib/bracketMatching/bracketMatching.ts
src/vs/editor/contrib/bracketMatching/bracketMatching.ts
+34
-22
src/vs/editor/contrib/bracketMatching/test/bracketMatching.test.ts
...itor/contrib/bracketMatching/test/bracketMatching.test.ts
+33
-8
未找到文件。
src/vs/editor/contrib/bracketMatching/bracketMatching.ts
浏览文件 @
32302709
...
...
@@ -56,16 +56,36 @@ class SelectToBracketAction extends EditorAction {
id
:
'
editor.action.selectToBracket
'
,
label
:
nls
.
localize
(
'
smartSelect.selectToBracket
'
,
"
Select to Bracket
"
),
alias
:
'
Select to Bracket
'
,
precondition
:
undefined
precondition
:
undefined
,
description
:
{
description
:
`Select to Bracket`
,
args
:
[{
name
:
'
args
'
,
schema
:
{
type
:
'
object
'
,
properties
:
{
'
selectBrackets
'
:
{
type
:
'
boolean
'
,
default
:
true
}
},
}
}]
}
});
}
public
run
(
accessor
:
ServicesAccessor
,
editor
:
ICodeEditor
):
void
{
le
t
controller
=
BracketMatchingController
.
get
(
editor
);
public
run
(
accessor
:
ServicesAccessor
,
editor
:
ICodeEditor
,
args
:
any
):
void
{
cons
t
controller
=
BracketMatchingController
.
get
(
editor
);
if
(
!
controller
)
{
return
;
}
controller
.
selectToBracket
();
let
selectBrackets
=
true
;
if
(
args
&&
args
.
selectBrackets
===
false
)
{
selectBrackets
=
false
;
}
controller
.
selectToBracket
(
selectBrackets
);
}
}
...
...
@@ -182,7 +202,7 @@ export class BracketMatchingController extends Disposable implements editorCommo
this
.
_editor
.
revealRange
(
newSelections
[
0
]);
}
public
selectToBracket
():
void
{
public
selectToBracket
(
selectBrackets
:
boolean
):
void
{
if
(
!
this
.
_editor
.
hasModel
())
{
return
;
}
...
...
@@ -194,9 +214,6 @@ export class BracketMatchingController extends Disposable implements editorCommo
const
position
=
selection
.
getStartPosition
();
let
brackets
=
model
.
matchBracket
(
position
);
let
openBracket
:
Position
|
null
=
null
;
let
closeBracket
:
Position
|
null
=
null
;
if
(
!
brackets
)
{
brackets
=
model
.
findEnclosingBrackets
(
position
);
if
(
!
brackets
)
{
...
...
@@ -207,26 +224,21 @@ export class BracketMatchingController extends Disposable implements editorCommo
}
}
let
selectFrom
:
Position
|
null
=
null
;
let
selectTo
:
Position
|
null
=
null
;
if
(
brackets
)
{
if
(
brackets
[
0
].
startLineNumber
===
brackets
[
1
].
startLineNumber
)
{
openBracket
=
brackets
[
1
].
startColumn
<
brackets
[
0
].
startColumn
?
brackets
[
1
].
getStartPosition
()
:
brackets
[
0
].
getStartPosition
();
closeBracket
=
brackets
[
1
].
startColumn
<
brackets
[
0
].
startColumn
?
brackets
[
0
].
getEndPosition
()
:
brackets
[
1
].
getEndPosition
();
}
else
{
openBracket
=
brackets
[
1
].
startLineNumber
<
brackets
[
0
].
startLineNumber
?
brackets
[
1
].
getStartPosition
()
:
brackets
[
0
].
getStartPosition
();
closeBracket
=
brackets
[
1
].
startLineNumber
<
brackets
[
0
].
startLineNumber
?
brackets
[
0
].
getEndPosition
()
:
brackets
[
1
].
getEndPosition
();
}
brackets
.
sort
(
Range
.
compareRangesUsingStarts
);
const
[
open
,
close
]
=
brackets
;
selectFrom
=
selectBrackets
?
open
.
getStartPosition
()
:
open
.
getEndPosition
();
selectTo
=
selectBrackets
?
close
.
getEndPosition
()
:
close
.
getStartPosition
();
}
if
(
openBracket
&&
closeBracket
)
{
newSelections
.
push
(
new
Selection
(
openBracket
.
lineNumber
,
openBracket
.
column
,
closeBracket
.
lineNumber
,
closeBracket
.
column
));
if
(
selectFrom
&&
selectTo
)
{
newSelections
.
push
(
new
Selection
(
selectFrom
.
lineNumber
,
selectFrom
.
column
,
selectTo
.
lineNumber
,
selectTo
.
column
));
}
});
if
(
newSelections
.
length
>
0
)
{
this
.
_editor
.
setSelections
(
newSelections
);
this
.
_editor
.
revealRange
(
newSelections
[
0
]);
...
...
src/vs/editor/contrib/bracketMatching/test/bracketMatching.test.ts
浏览文件 @
32302709
...
...
@@ -108,31 +108,31 @@ suite('bracket matching', () => {
// start position in open brackets
editor
.
setPosition
(
new
Position
(
1
,
9
));
bracketMatchingController
.
selectToBracket
();
bracketMatchingController
.
selectToBracket
(
true
);
assert
.
deepEqual
(
editor
.
getPosition
(),
new
Position
(
1
,
20
));
assert
.
deepEqual
(
editor
.
getSelection
(),
new
Selection
(
1
,
9
,
1
,
20
));
// start position in close brackets
editor
.
setPosition
(
new
Position
(
1
,
20
));
bracketMatchingController
.
selectToBracket
();
bracketMatchingController
.
selectToBracket
(
true
);
assert
.
deepEqual
(
editor
.
getPosition
(),
new
Position
(
1
,
20
));
assert
.
deepEqual
(
editor
.
getSelection
(),
new
Selection
(
1
,
9
,
1
,
20
));
// start position between brackets
editor
.
setPosition
(
new
Position
(
1
,
16
));
bracketMatchingController
.
selectToBracket
();
bracketMatchingController
.
selectToBracket
(
true
);
assert
.
deepEqual
(
editor
.
getPosition
(),
new
Position
(
1
,
19
));
assert
.
deepEqual
(
editor
.
getSelection
(),
new
Selection
(
1
,
14
,
1
,
19
));
// start position outside brackets
editor
.
setPosition
(
new
Position
(
1
,
21
));
bracketMatchingController
.
selectToBracket
();
bracketMatchingController
.
selectToBracket
(
true
);
assert
.
deepEqual
(
editor
.
getPosition
(),
new
Position
(
1
,
25
));
assert
.
deepEqual
(
editor
.
getSelection
(),
new
Selection
(
1
,
23
,
1
,
25
));
// do not break if no brackets are available
editor
.
setPosition
(
new
Position
(
1
,
26
));
bracketMatchingController
.
selectToBracket
();
bracketMatchingController
.
selectToBracket
(
true
);
assert
.
deepEqual
(
editor
.
getPosition
(),
new
Position
(
1
,
26
));
assert
.
deepEqual
(
editor
.
getSelection
(),
new
Selection
(
1
,
26
,
1
,
26
));
...
...
@@ -168,6 +168,31 @@ suite('bracket matching', () => {
mode
.
dispose
();
});
test
(
'
issue #43371: argument to not select brackets
'
,
()
=>
{
const
text
=
[
'
const x = {
'
,
'
something: [0, 1, 2],
'
,
'
another: true,
'
,
'
somethingmore: [0, 2, 4]
'
,
'
};
'
,
].
join
(
'
\n
'
);
const
mode
=
new
BracketMode
();
const
model
=
TextModel
.
createFromString
(
text
,
undefined
,
mode
.
getLanguageIdentifier
());
withTestCodeEditor
(
null
,
{
model
:
model
},
(
editor
,
cursor
)
=>
{
const
bracketMatchingController
=
editor
.
registerAndInstantiateContribution
<
BracketMatchingController
>
(
BracketMatchingController
.
ID
,
BracketMatchingController
);
editor
.
setPosition
(
new
Position
(
3
,
5
));
bracketMatchingController
.
selectToBracket
(
false
);
assert
.
deepEqual
(
editor
.
getSelection
(),
new
Selection
(
1
,
12
,
5
,
1
));
bracketMatchingController
.
dispose
();
});
model
.
dispose
();
mode
.
dispose
();
});
test
(
'
issue #45369: Select to Bracket with multicursor
'
,
()
=>
{
let
mode
=
new
BracketMode
();
let
model
=
TextModel
.
createFromString
(
'
{ } { } { }
'
,
undefined
,
mode
.
getLanguageIdentifier
());
...
...
@@ -181,7 +206,7 @@ suite('bracket matching', () => {
new
Selection
(
1
,
10
,
1
,
10
),
new
Selection
(
1
,
17
,
1
,
17
)
]);
bracketMatchingController
.
selectToBracket
();
bracketMatchingController
.
selectToBracket
(
true
);
assert
.
deepEqual
(
editor
.
getSelections
(),
[
new
Selection
(
1
,
1
,
1
,
5
),
new
Selection
(
1
,
8
,
1
,
13
),
...
...
@@ -194,7 +219,7 @@ suite('bracket matching', () => {
new
Selection
(
1
,
6
,
1
,
6
),
new
Selection
(
1
,
14
,
1
,
14
)
]);
bracketMatchingController
.
selectToBracket
();
bracketMatchingController
.
selectToBracket
(
true
);
assert
.
deepEqual
(
editor
.
getSelections
(),
[
new
Selection
(
1
,
1
,
1
,
5
),
new
Selection
(
1
,
8
,
1
,
13
),
...
...
@@ -207,7 +232,7 @@ suite('bracket matching', () => {
new
Selection
(
1
,
13
,
1
,
13
),
new
Selection
(
1
,
19
,
1
,
19
)
]);
bracketMatchingController
.
selectToBracket
();
bracketMatchingController
.
selectToBracket
(
true
);
assert
.
deepEqual
(
editor
.
getSelections
(),
[
new
Selection
(
1
,
1
,
1
,
5
),
new
Selection
(
1
,
8
,
1
,
13
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录