Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
27e7423a
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,发现更多精彩内容 >>
提交
27e7423a
编写于
10月 11, 2017
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[folding] breaks when a particular sequence of text is entered. Fixes #35981
上级
1fb36186
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
164 addition
and
133 deletion
+164
-133
src/vs/editor/common/model/indentRanges.ts
src/vs/editor/common/model/indentRanges.ts
+28
-22
src/vs/editor/test/common/model/indentRanges.test.ts
src/vs/editor/test/common/model/indentRanges.test.ts
+136
-111
未找到文件。
src/vs/editor/common/model/indentRanges.ts
浏览文件 @
27e7423a
...
@@ -61,41 +61,47 @@ export function computeRanges(model: ITextModel, offSide: boolean, markers?: Fol
...
@@ -61,41 +61,47 @@ export function computeRanges(model: ITextModel, offSide: boolean, markers?: Fol
// folding pattern match
// folding pattern match
if
(
m
[
1
])
{
// start pattern match
if
(
m
[
1
])
{
// start pattern match
// discard all regions until the folding pattern
// discard all regions until the folding pattern
while
(
previous
.
indent
>=
0
&&
!
previous
.
marker
)
{
let
i
=
previousRegions
.
length
-
1
;
previousRegions
.
pop
();
while
(
i
>
0
&&
!
previousRegions
[
i
].
marker
)
{
previous
=
previousRegions
[
previousRegions
.
length
-
1
]
;
i
--
;
}
}
if
(
previous
.
marker
)
{
if
(
i
>
0
)
{
previousRegions
.
length
=
i
+
1
;
previous
=
previousRegions
[
i
];
// new folding range from pattern, includes the end line
// new folding range from pattern, includes the end line
result
.
push
(
new
IndentRange
(
line
,
previous
.
line
,
indent
,
true
));
result
.
push
(
new
IndentRange
(
line
,
previous
.
line
,
indent
,
true
));
previous
.
marker
=
false
;
previous
.
marker
=
false
;
previous
.
indent
=
indent
;
previous
.
indent
=
indent
;
previous
.
line
=
line
;
previous
.
line
=
line
;
continue
;
}
else
{
// no end marker found, treat line as a regular line
}
}
}
else
{
// end pattern match
}
else
{
// end pattern match
previousRegions
.
push
({
indent
:
-
2
,
line
,
marker
:
true
});
previousRegions
.
push
({
indent
:
-
2
,
line
,
marker
:
true
});
continue
;
}
}
}
else
{
}
if
(
previous
.
indent
>
indent
)
{
if
(
previous
.
indent
>
indent
)
{
// discard all regions with larger indent
// discard all regions with larger indent
do
{
do
{
previousRegions
.
pop
();
previousRegions
.
pop
();
previous
=
previousRegions
[
previousRegions
.
length
-
1
];
previous
=
previousRegions
[
previousRegions
.
length
-
1
];
}
while
(
previous
.
indent
>
indent
);
}
while
(
previous
.
indent
>
indent
);
// new folding range
// new folding range
let
endLineNumber
=
previous
.
line
-
1
;
let
endLineNumber
=
previous
.
line
-
1
;
if
(
endLineNumber
-
line
>=
minimumRangeSize
)
{
if
(
endLineNumber
-
line
>=
minimumRangeSize
)
{
result
.
push
(
new
IndentRange
(
line
,
endLineNumber
,
indent
));
result
.
push
(
new
IndentRange
(
line
,
endLineNumber
,
indent
));
}
}
if
(
previous
.
indent
===
indent
)
{
previous
.
line
=
line
;
}
else
{
// previous.indent < indent
// new region with a bigger indent
previousRegions
.
push
({
indent
,
line
,
marker
:
false
});
}
}
}
}
if
(
previous
.
indent
===
indent
)
{
previous
.
line
=
line
;
}
else
{
// previous.indent < indent
// new region with a bigger indent
previousRegions
.
push
({
indent
,
line
,
marker
:
false
});
}
}
}
return
result
.
reverse
();
return
result
.
reverse
();
...
...
src/vs/editor/test/common/model/indentRanges.test.ts
浏览文件 @
27e7423a
...
@@ -29,125 +29,125 @@ function r(startLineNumber: number, endLineNumber: number, indent: number, marke
...
@@ -29,125 +29,125 @@ function r(startLineNumber: number, endLineNumber: number, indent: number, marke
return
{
startLineNumber
,
endLineNumber
,
indent
,
marker
};
return
{
startLineNumber
,
endLineNumber
,
indent
,
marker
};
}
}
//
suite('Indentation Folding', () => {
suite
(
'
Indentation Folding
'
,
()
=>
{
//
test('Fold one level', () => {
test
(
'
Fold one level
'
,
()
=>
{
//
let range = [
let
range
=
[
//
'A',
'
A
'
,
//
' A',
'
A
'
,
//
' A',
'
A
'
,
//
' A'
'
A
'
//
];
];
//
assertRanges(range, [r(1, 4, 0)], true);
assertRanges
(
range
,
[
r
(
1
,
4
,
0
)],
true
);
//
assertRanges(range, [r(1, 4, 0)], false);
assertRanges
(
range
,
[
r
(
1
,
4
,
0
)],
false
);
//
});
});
//
test('Fold two levels', () => {
test
(
'
Fold two levels
'
,
()
=>
{
//
let range = [
let
range
=
[
//
'A',
'
A
'
,
//
' A',
'
A
'
,
//
' A',
'
A
'
,
//
' A',
'
A
'
,
//
' A'
'
A
'
//
];
];
//
assertRanges(range, [r(1, 5, 0), r(3, 5, 2)], true);
assertRanges
(
range
,
[
r
(
1
,
5
,
0
),
r
(
3
,
5
,
2
)],
true
);
//
assertRanges(range, [r(1, 5, 0), r(3, 5, 2)], false);
assertRanges
(
range
,
[
r
(
1
,
5
,
0
),
r
(
3
,
5
,
2
)],
false
);
//
});
});
//
test('Fold three levels', () => {
test
(
'
Fold three levels
'
,
()
=>
{
//
let range = [
let
range
=
[
//
'A',
'
A
'
,
//
' A',
'
A
'
,
//
' A',
'
A
'
,
//
' A',
'
A
'
,
//
'A'
'
A
'
//
];
];
//
assertRanges(range, [r(1, 4, 0), r(2, 4, 2), r(3, 4, 4)], true);
assertRanges
(
range
,
[
r
(
1
,
4
,
0
),
r
(
2
,
4
,
2
),
r
(
3
,
4
,
4
)],
true
);
//
assertRanges(range, [r(1, 4, 0), r(2, 4, 2), r(3, 4, 4)], false);
assertRanges
(
range
,
[
r
(
1
,
4
,
0
),
r
(
2
,
4
,
2
),
r
(
3
,
4
,
4
)],
false
);
//
});
});
//
test('Fold decreasing indent', () => {
test
(
'
Fold decreasing indent
'
,
()
=>
{
//
let range = [
let
range
=
[
//
' A',
'
A
'
,
//
' A',
'
A
'
,
//
'A'
'
A
'
//
];
];
//
assertRanges(range, [], true);
assertRanges
(
range
,
[],
true
);
//
assertRanges(range, [], false);
assertRanges
(
range
,
[],
false
);
//
});
});
//
test('Fold Java', () => {
test
(
'
Fold Java
'
,
()
=>
{
//
assertRanges([
assertRanges
([
//
/* 1*/ 'class A {',
/* 1*/
'
class A {
'
,
//
/* 2*/ ' void foo() {',
/* 2*/
'
void foo() {
'
,
//
/* 3*/ ' console.log();',
/* 3*/
'
console.log();
'
,
//
/* 4*/ ' console.log();',
/* 4*/
'
console.log();
'
,
//
/* 5*/ ' }',
/* 5*/
'
}
'
,
//
/* 6*/ '',
/* 6*/
''
,
//
/* 7*/ ' void bar() {',
/* 7*/
'
void bar() {
'
,
//
/* 8*/ ' console.log();',
/* 8*/
'
console.log();
'
,
//
/* 9*/ ' }',
/* 9*/
'
}
'
,
//
/*10*/ '}',
/*10*/
'
}
'
,
//
/*11*/ 'interface B {',
/*11*/
'
interface B {
'
,
//
/*12*/ ' void bar();',
/*12*/
'
void bar();
'
,
//
/*13*/ '}',
/*13*/
'
}
'
,
//
], [r(1, 9, 0), r(2, 4, 2), r(7, 8, 2), r(11, 12, 0)], false);
],
[
r
(
1
,
9
,
0
),
r
(
2
,
4
,
2
),
r
(
7
,
8
,
2
),
r
(
11
,
12
,
0
)],
false
);
//
});
});
//
test('Fold Javadoc', () => {
test
(
'
Fold Javadoc
'
,
()
=>
{
//
assertRanges([
assertRanges
([
//
/* 1*/ '/**',
/* 1*/
'
/**
'
,
//
/* 2*/ ' * Comment',
/* 2*/
'
* Comment
'
,
//
/* 3*/ ' */',
/* 3*/
'
*/
'
,
//
/* 4*/ 'class A {',
/* 4*/
'
class A {
'
,
//
/* 5*/ ' void foo() {',
/* 5*/
'
void foo() {
'
,
//
/* 6*/ ' }',
/* 6*/
'
}
'
,
//
/* 7*/ '}',
/* 7*/
'
}
'
,
//
], [r(1, 3, 0), r(4, 6, 0)], false);
],
[
r
(
1
,
3
,
0
),
r
(
4
,
6
,
0
)],
false
);
//
});
});
//
test('Fold Whitespace Java', () => {
test
(
'
Fold Whitespace Java
'
,
()
=>
{
//
assertRanges([
assertRanges
([
//
/* 1*/ 'class A {',
/* 1*/
'
class A {
'
,
//
/* 2*/ '',
/* 2*/
''
,
//
/* 3*/ ' void foo() {',
/* 3*/
'
void foo() {
'
,
//
/* 4*/ ' ',
/* 4*/
'
'
,
//
/* 5*/ ' return 0;',
/* 5*/
'
return 0;
'
,
//
/* 6*/ ' }',
/* 6*/
'
}
'
,
//
/* 7*/ ' ',
/* 7*/
'
'
,
//
/* 8*/ '}',
/* 8*/
'
}
'
,
//
], [r(1, 7, 0), r(3, 5, 2)], false);
],
[
r
(
1
,
7
,
0
),
r
(
3
,
5
,
2
)],
false
);
//
});
});
//
test('Fold Whitespace Python', () => {
test
(
'
Fold Whitespace Python
'
,
()
=>
{
//
assertRanges([
assertRanges
([
//
/* 1*/ 'def a:',
/* 1*/
'
def a:
'
,
//
/* 2*/ ' pass',
/* 2*/
'
pass
'
,
//
/* 3*/ ' ',
/* 3*/
'
'
,
//
/* 4*/ ' def b:',
/* 4*/
'
def b:
'
,
//
/* 5*/ ' pass',
/* 5*/
'
pass
'
,
//
/* 6*/ ' ',
/* 6*/
'
'
,
//
/* 7*/ ' ',
/* 7*/
'
'
,
//
/* 8*/ 'def c: # since there was a deintent here'
/* 8*/
'
def c: # since there was a deintent here
'
//
], [r(1, 5, 0), r(4, 5, 2)], true);
],
[
r
(
1
,
5
,
0
),
r
(
4
,
5
,
2
)],
true
);
//
});
});
//
test('Fold Tabs', () => {
test
(
'
Fold Tabs
'
,
()
=>
{
//
assertRanges([
assertRanges
([
//
/* 1*/ 'class A {',
/* 1*/
'
class A {
'
,
//
/* 2*/ '\t\t',
/* 2*/
'
\t\t
'
,
//
/* 3*/ '\tvoid foo() {',
/* 3*/
'
\t
void foo() {
'
,
//
/* 4*/ '\t \t//hello',
/* 4*/
'
\t
\t
//hello
'
,
//
/* 5*/ '\t return 0;',
/* 5*/
'
\t
return 0;
'
,
//
/* 6*/ ' \t}',
/* 6*/
'
\t
}
'
,
//
/* 7*/ ' ',
/* 7*/
'
'
,
//
/* 8*/ '}',
/* 8*/
'
}
'
,
//
], [r(1, 7, 0), r(3, 5, 4)], false);
],
[
r
(
1
,
7
,
0
),
r
(
3
,
5
,
4
)],
false
);
//
});
});
//
});
});
let
markers
:
FoldingMarkers
=
{
let
markers
:
FoldingMarkers
=
{
start
:
/^
\s
*#region/
,
start
:
/^
\s
*#region
\b
/
,
end
:
/^
\s
*#endregion/
end
:
/^
\s
*#endregion
\b
/
};
};
suite
(
'
Folding with regions
'
,
()
=>
{
suite
(
'
Folding with regions
'
,
()
=>
{
...
@@ -216,9 +216,9 @@ suite('Folding with regions', () => {
...
@@ -216,9 +216,9 @@ suite('Folding with regions', () => {
/* 2*/
'
#region
'
,
/* 2*/
'
#region
'
,
/* 3*/
'
// comment
'
,
/* 3*/
'
// comment
'
,
/* 4*/
'
}
'
,
/* 4*/
'
}
'
,
],
[],
false
,
markers
);
],
[
r
(
2
,
3
,
0
)
],
false
,
markers
);
});
});
test
(
'
Incomplete Regions
'
,
()
=>
{
test
(
'
Incomplete Regions
2
'
,
()
=>
{
assertRanges
([
assertRanges
([
/* 1*/
''
,
/* 1*/
''
,
/* 2*/
'
#region
'
,
/* 2*/
'
#region
'
,
...
@@ -291,4 +291,29 @@ suite('Folding with regions', () => {
...
@@ -291,4 +291,29 @@ suite('Folding with regions', () => {
/* 8*/
''
,
/* 8*/
''
,
],
[
r
(
1
,
7
,
0
,
true
),
r
(
3
,
5
,
0
,
true
)],
true
,
markers
);
],
[
r
(
1
,
7
,
0
,
true
),
r
(
3
,
5
,
0
,
true
)],
true
,
markers
);
});
});
test
(
'
Issue 35981
'
,
()
=>
{
assertRanges
([
/* 1*/
'
function thisFoldsToEndOfPage() {
'
,
/* 2*/
'
const variable = []
'
,
/* 3*/
'
// #region
'
,
/* 4*/
'
.reduce((a, b) => a,[]);
'
,
/* 5*/
'
}
'
,
/* 6*/
''
,
/* 7*/
'
function thisFoldsProperly() {
'
,
/* 8*/
'
const foo = "bar"
'
,
/* 9*/
'
}
'
,
],
[
r
(
1
,
4
,
0
),
r
(
2
,
4
,
2
),
r
(
7
,
8
,
0
)],
false
,
markers
);
});
test
(
'
Misspelled Markers
'
,
()
=>
{
assertRanges
([
/* 1*/
'
#Region
'
,
/* 2*/
'
#endregion
'
,
/* 3*/
'
#regionsandmore
'
,
/* 4*/
'
#endregion
'
,
/* 5*/
'
#region
'
,
/* 6*/
'
#end region
'
,
/* 7*/
'
#region
'
,
/* 8*/
'
#endregionff
'
,
],
[],
true
,
markers
);
});
});
});
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录