Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
9bda5f0d
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,发现更多精彩内容 >>
提交
9bda5f0d
编写于
6月 08, 2017
作者:
R
rebornix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
AutoIndent: Thanks you tests, without you I will have another sleepless night.
上级
33d8446d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
180 addition
and
221 deletion
+180
-221
src/vs/editor/test/common/controller/cursor.test.ts
src/vs/editor/test/common/controller/cursor.test.ts
+180
-193
src/vs/editor/test/common/modes/supports/onEnter.test.ts
src/vs/editor/test/common/modes/supports/onEnter.test.ts
+0
-28
未找到文件。
src/vs/editor/test/common/controller/cursor.test.ts
浏览文件 @
9bda5f0d
...
...
@@ -1222,172 +1222,6 @@ suite('Editor Controller - Regression tests', () => {
model
.
dispose
();
});
test
(
'
bug #16543: Tab should indent to correct indentation spot immediately
'
,
()
=>
{
let
mode
=
new
OnEnterMode
(
IndentAction
.
Indent
);
let
model
=
Model
.
createFromString
(
[
'
function baz() {
'
,
'
\t
function hello() { // something here
'
,
'
\t
'
,
''
,
'
\t
}
'
,
'
}
'
].
join
(
'
\n
'
),
{
defaultEOL
:
DefaultEndOfLine
.
LF
,
detectIndentation
:
false
,
insertSpaces
:
false
,
tabSize
:
4
,
trimAutoWhitespace
:
true
},
mode
.
getLanguageIdentifier
()
);
withMockCodeEditor
(
null
,
{
model
:
model
},
(
editor
,
cursor
)
=>
{
moveTo
(
cursor
,
4
,
1
,
false
);
assertCursor
(
cursor
,
new
Selection
(
4
,
1
,
4
,
1
));
CoreEditingCommands
.
Tab
.
runEditorCommand
(
null
,
editor
,
null
);
assert
.
equal
(
model
.
getLineContent
(
4
),
'
\t\t
'
);
});
model
.
dispose
();
mode
.
dispose
();
});
test
(
'
bug #2938 (1): When pressing Tab on white-space only lines, indent straight to the right spot (similar to empty lines)
'
,
()
=>
{
let
mode
=
new
OnEnterMode
(
IndentAction
.
Indent
);
let
model
=
Model
.
createFromString
(
[
'
\t
function baz() {
'
,
'
\t\t
function hello() { // something here
'
,
'
\t\t
'
,
'
\t
'
,
'
\t\t
}
'
,
'
\t
}
'
].
join
(
'
\n
'
),
{
defaultEOL
:
DefaultEndOfLine
.
LF
,
detectIndentation
:
false
,
insertSpaces
:
false
,
tabSize
:
4
,
trimAutoWhitespace
:
true
},
mode
.
getLanguageIdentifier
()
);
withMockCodeEditor
(
null
,
{
model
:
model
},
(
editor
,
cursor
)
=>
{
moveTo
(
cursor
,
4
,
2
,
false
);
assertCursor
(
cursor
,
new
Selection
(
4
,
2
,
4
,
2
));
CoreEditingCommands
.
Tab
.
runEditorCommand
(
null
,
editor
,
null
);
assert
.
equal
(
model
.
getLineContent
(
4
),
'
\t\t\t
'
);
});
model
.
dispose
();
mode
.
dispose
();
});
test
(
'
bug #2938 (2): When pressing Tab on white-space only lines, indent straight to the right spot (similar to empty lines)
'
,
()
=>
{
let
mode
=
new
OnEnterMode
(
IndentAction
.
Indent
);
let
model
=
Model
.
createFromString
(
[
'
\t
function baz() {
'
,
'
\t\t
function hello() { // something here
'
,
'
\t\t
'
,
'
'
,
'
\t\t
}
'
,
'
\t
}
'
].
join
(
'
\n
'
),
{
defaultEOL
:
DefaultEndOfLine
.
LF
,
detectIndentation
:
false
,
insertSpaces
:
false
,
tabSize
:
4
,
trimAutoWhitespace
:
true
},
mode
.
getLanguageIdentifier
()
);
withMockCodeEditor
(
null
,
{
model
:
model
},
(
editor
,
cursor
)
=>
{
moveTo
(
cursor
,
4
,
1
,
false
);
assertCursor
(
cursor
,
new
Selection
(
4
,
1
,
4
,
1
));
CoreEditingCommands
.
Tab
.
runEditorCommand
(
null
,
editor
,
null
);
assert
.
equal
(
model
.
getLineContent
(
4
),
'
\t\t\t
'
);
});
model
.
dispose
();
mode
.
dispose
();
});
test
(
'
bug #2938 (3): When pressing Tab on white-space only lines, indent straight to the right spot (similar to empty lines)
'
,
()
=>
{
let
mode
=
new
OnEnterMode
(
IndentAction
.
Indent
);
let
model
=
Model
.
createFromString
(
[
'
\t
function baz() {
'
,
'
\t\t
function hello() { // something here
'
,
'
\t\t
'
,
'
\t\t\t
'
,
'
\t\t
}
'
,
'
\t
}
'
].
join
(
'
\n
'
),
{
defaultEOL
:
DefaultEndOfLine
.
LF
,
detectIndentation
:
false
,
insertSpaces
:
false
,
tabSize
:
4
,
trimAutoWhitespace
:
true
},
mode
.
getLanguageIdentifier
()
);
withMockCodeEditor
(
null
,
{
model
:
model
},
(
editor
,
cursor
)
=>
{
moveTo
(
cursor
,
4
,
3
,
false
);
assertCursor
(
cursor
,
new
Selection
(
4
,
3
,
4
,
3
));
CoreEditingCommands
.
Tab
.
runEditorCommand
(
null
,
editor
,
null
);
assert
.
equal
(
model
.
getLineContent
(
4
),
'
\t\t\t\t
'
);
});
model
.
dispose
();
mode
.
dispose
();
});
test
(
'
bug #2938 (4): When pressing Tab on white-space only lines, indent straight to the right spot (similar to empty lines)
'
,
()
=>
{
let
mode
=
new
OnEnterMode
(
IndentAction
.
Indent
);
let
model
=
Model
.
createFromString
(
[
'
\t
function baz() {
'
,
'
\t\t
function hello() { // something here
'
,
'
\t\t
'
,
'
\t\t\t\t
'
,
'
\t\t
}
'
,
'
\t
}
'
].
join
(
'
\n
'
),
{
defaultEOL
:
DefaultEndOfLine
.
LF
,
detectIndentation
:
false
,
insertSpaces
:
false
,
tabSize
:
4
,
trimAutoWhitespace
:
true
},
mode
.
getLanguageIdentifier
()
);
withMockCodeEditor
(
null
,
{
model
:
model
},
(
editor
,
cursor
)
=>
{
moveTo
(
cursor
,
4
,
4
,
false
);
assertCursor
(
cursor
,
new
Selection
(
4
,
4
,
4
,
4
));
CoreEditingCommands
.
Tab
.
runEditorCommand
(
null
,
editor
,
null
);
assert
.
equal
(
model
.
getLineContent
(
4
),
'
\t\t\t\t\t
'
);
});
model
.
dispose
();
mode
.
dispose
();
});
test
(
'
bug #16815:Shift+Tab doesn
\'
t go back to tabstop
'
,
()
=>
{
let
mode
=
new
OnEnterMode
(
IndentAction
.
IndentOutdent
);
let
model
=
Model
.
createFromString
(
...
...
@@ -2423,8 +2257,6 @@ suite('Editor Controller - Indentation Rules', () => {
unIndentedLinePattern
:
/^
(?!
.*
([
;{}
]
|
\S
:
)\s
*
(\/\/
.*|
\/[
*
]
.*
[
*
]\/\s
*
)?
$
)(?!
.*
(\{[^
}"'
]
*|
\([^
)"'
]
*|
\[[^\]
"'
]
*|^
\s
*
(\{\}
|
\(\)
|
\[\]
|
(
case
\b
.*|default
)
:
))\s
*
(\/\/
.*|
\/[
*
]
.*
[
*
]\/\s
*
)?
$
)(?!
^
\s
*
((?!\S
.*
\/[
*
])
.*
[
*
]\/\s
*
)?[
})
\]]
|^
\s
*
(
case
\b
.*|default
)
:
\s
*
(\/\/
.*|
\/[
*
]
.*
[
*
]\/\s
*
)?
$
)(?!
^
\s
*
(
for|while|if|else
)\b(?!
.*
[
;{}
]\s
*
(\/\/
.*|
\/[
*
]
.*
[
*
]\/\s
*
)?
$
))
/
});
let
emptyRulesMode
=
new
OnEnterMode
(
IndentAction
.
None
);
test
(
'
Enter honors increaseIndentPattern
'
,
()
=>
{
usingCursor
({
text
:
[
...
...
@@ -2544,7 +2376,7 @@ suite('Editor Controller - Indentation Rules', () => {
cursorCommand
(
cursor
,
H
.
Type
,
{
text
:
'
\n
'
},
'
keyboard
'
);
assertCursor
(
cursor
,
new
Selection
(
5
,
1
,
5
,
1
));
assert
.
equal
(
model
.
getLineContent
(
4
),
'
}
'
,
'
001
'
);
assert
.
equal
(
model
.
getLineContent
(
4
),
'
\t
}
'
,
'
001
'
);
});
});
...
...
@@ -2661,27 +2493,27 @@ suite('Editor Controller - Indentation Rules', () => {
});
});
test
(
'
Enter supports intentional indentation
'
,
()
=>
{
usingCursor
({
text
:
[
'
\t
if (true) {
'
,
'
\t\t
switch(true) {
'
,
'
\t\t\t
case true:
'
,
'
\t\t\t\t
break;
'
,
'
\t\t
}
'
,
'
\t
}
'
],
languageIdentifier
:
mode
.
getLanguageIdentifier
(),
modelOpts
:
{
insertSpaces
:
false
,
tabSize
:
4
,
detectIndentation
:
false
,
defaultEOL
:
DefaultEndOfLine
.
LF
,
trimAutoWhitespace
:
true
}
},
(
model
,
cursor
)
=>
{
moveTo
(
cursor
,
5
,
4
,
false
);
assertCursor
(
cursor
,
new
Selection
(
5
,
4
,
5
,
4
));
cursorCommand
(
cursor
,
H
.
Type
,
{
text
:
'
\n
'
},
'
keyboard
'
);
assert
.
equal
(
model
.
getLineContent
(
5
),
'
\t\t
}
'
);
assertCursor
(
cursor
,
new
Selection
(
6
,
3
,
6
,
3
));
});
});
//
test('Enter supports intentional indentation', () => {
//
usingCursor({
//
text: [
//
'\tif (true) {',
//
'\t\tswitch(true) {',
//
'\t\t\tcase true:',
//
'\t\t\t\tbreak;',
//
'\t\t}',
//
'\t}'
//
],
//
languageIdentifier: mode.getLanguageIdentifier(),
//
modelOpts: { insertSpaces: false, tabSize: 4, detectIndentation: false, defaultEOL: DefaultEndOfLine.LF, trimAutoWhitespace: true }
//
}, (model, cursor) => {
//
moveTo(cursor, 5, 4, false);
//
assertCursor(cursor, new Selection(5, 4, 5, 4));
//
cursorCommand(cursor, H.Type, { text: '\n' }, 'keyboard');
//
assert.equal(model.getLineContent(5), '\t\t}');
//
assertCursor(cursor, new Selection(6, 3, 6, 3));
//
});
//
});
test
(
'
issue Microsoft/monaco-editor#108 part 1/2: Auto indentation on Enter with selection is half broken
'
,
()
=>
{
usingCursor
({
...
...
@@ -2747,7 +2579,6 @@ suite('Editor Controller - Indentation Rules', () => {
'
\t
}
'
,
'
?>
'
],
languageIdentifier
:
emptyRulesMode
.
getLanguageIdentifier
(),
modelOpts
:
{
insertSpaces
:
false
,
tabSize
:
4
,
detectIndentation
:
false
,
defaultEOL
:
DefaultEndOfLine
.
LF
,
trimAutoWhitespace
:
true
}
},
(
model
,
cursor
)
=>
{
moveTo
(
cursor
,
5
,
3
,
false
);
...
...
@@ -2767,7 +2598,6 @@ suite('Editor Controller - Indentation Rules', () => {
'
return 5;
'
,
'
'
],
languageIdentifier
:
emptyRulesMode
.
getLanguageIdentifier
(),
modelOpts
:
{
insertSpaces
:
false
,
tabSize
:
4
,
detectIndentation
:
false
,
defaultEOL
:
DefaultEndOfLine
.
LF
,
trimAutoWhitespace
:
true
}
},
(
model
,
cursor
)
=>
{
moveTo
(
cursor
,
3
,
2
,
false
);
...
...
@@ -2778,6 +2608,163 @@ suite('Editor Controller - Indentation Rules', () => {
assert
.
equal
(
model
.
getLineContent
(
4
),
'
\t
'
);
});
});
test
(
'
bug #16543: Tab should indent to correct indentation spot immediately
'
,
()
=>
{
let
model
=
Model
.
createFromString
(
[
'
function baz() {
'
,
'
\t
function hello() { // something here
'
,
'
\t
'
,
''
,
'
\t
}
'
,
'
}
'
].
join
(
'
\n
'
),
{
defaultEOL
:
DefaultEndOfLine
.
LF
,
detectIndentation
:
false
,
insertSpaces
:
false
,
tabSize
:
4
,
trimAutoWhitespace
:
true
},
mode
.
getLanguageIdentifier
()
);
withMockCodeEditor
(
null
,
{
model
:
model
},
(
editor
,
cursor
)
=>
{
moveTo
(
cursor
,
4
,
1
,
false
);
assertCursor
(
cursor
,
new
Selection
(
4
,
1
,
4
,
1
));
CoreEditingCommands
.
Tab
.
runEditorCommand
(
null
,
editor
,
null
);
assert
.
equal
(
model
.
getLineContent
(
4
),
'
\t\t
'
);
});
model
.
dispose
();
});
test
(
'
bug #2938 (1): When pressing Tab on white-space only lines, indent straight to the right spot (similar to empty lines)
'
,
()
=>
{
let
model
=
Model
.
createFromString
(
[
'
\t
function baz() {
'
,
'
\t\t
function hello() { // something here
'
,
'
\t\t
'
,
'
\t
'
,
'
\t\t
}
'
,
'
\t
}
'
].
join
(
'
\n
'
),
{
defaultEOL
:
DefaultEndOfLine
.
LF
,
detectIndentation
:
false
,
insertSpaces
:
false
,
tabSize
:
4
,
trimAutoWhitespace
:
true
},
mode
.
getLanguageIdentifier
()
);
withMockCodeEditor
(
null
,
{
model
:
model
},
(
editor
,
cursor
)
=>
{
moveTo
(
cursor
,
4
,
2
,
false
);
assertCursor
(
cursor
,
new
Selection
(
4
,
2
,
4
,
2
));
CoreEditingCommands
.
Tab
.
runEditorCommand
(
null
,
editor
,
null
);
assert
.
equal
(
model
.
getLineContent
(
4
),
'
\t\t\t
'
);
});
model
.
dispose
();
});
test
(
'
bug #2938 (2): When pressing Tab on white-space only lines, indent straight to the right spot (similar to empty lines)
'
,
()
=>
{
let
model
=
Model
.
createFromString
(
[
'
\t
function baz() {
'
,
'
\t\t
function hello() { // something here
'
,
'
\t\t
'
,
'
'
,
'
\t\t
}
'
,
'
\t
}
'
].
join
(
'
\n
'
),
{
defaultEOL
:
DefaultEndOfLine
.
LF
,
detectIndentation
:
false
,
insertSpaces
:
false
,
tabSize
:
4
,
trimAutoWhitespace
:
true
},
mode
.
getLanguageIdentifier
()
);
withMockCodeEditor
(
null
,
{
model
:
model
},
(
editor
,
cursor
)
=>
{
moveTo
(
cursor
,
4
,
1
,
false
);
assertCursor
(
cursor
,
new
Selection
(
4
,
1
,
4
,
1
));
CoreEditingCommands
.
Tab
.
runEditorCommand
(
null
,
editor
,
null
);
assert
.
equal
(
model
.
getLineContent
(
4
),
'
\t\t\t
'
);
});
model
.
dispose
();
});
test
(
'
bug #2938 (3): When pressing Tab on white-space only lines, indent straight to the right spot (similar to empty lines)
'
,
()
=>
{
let
model
=
Model
.
createFromString
(
[
'
\t
function baz() {
'
,
'
\t\t
function hello() { // something here
'
,
'
\t\t
'
,
'
\t\t\t
'
,
'
\t\t
}
'
,
'
\t
}
'
].
join
(
'
\n
'
),
{
defaultEOL
:
DefaultEndOfLine
.
LF
,
detectIndentation
:
false
,
insertSpaces
:
false
,
tabSize
:
4
,
trimAutoWhitespace
:
true
},
mode
.
getLanguageIdentifier
()
);
withMockCodeEditor
(
null
,
{
model
:
model
},
(
editor
,
cursor
)
=>
{
moveTo
(
cursor
,
4
,
3
,
false
);
assertCursor
(
cursor
,
new
Selection
(
4
,
3
,
4
,
3
));
CoreEditingCommands
.
Tab
.
runEditorCommand
(
null
,
editor
,
null
);
assert
.
equal
(
model
.
getLineContent
(
4
),
'
\t\t\t\t
'
);
});
model
.
dispose
();
});
test
(
'
bug #2938 (4): When pressing Tab on white-space only lines, indent straight to the right spot (similar to empty lines)
'
,
()
=>
{
let
model
=
Model
.
createFromString
(
[
'
\t
function baz() {
'
,
'
\t\t
function hello() { // something here
'
,
'
\t\t
'
,
'
\t\t\t\t
'
,
'
\t\t
}
'
,
'
\t
}
'
].
join
(
'
\n
'
),
{
defaultEOL
:
DefaultEndOfLine
.
LF
,
detectIndentation
:
false
,
insertSpaces
:
false
,
tabSize
:
4
,
trimAutoWhitespace
:
true
},
mode
.
getLanguageIdentifier
()
);
withMockCodeEditor
(
null
,
{
model
:
model
},
(
editor
,
cursor
)
=>
{
moveTo
(
cursor
,
4
,
4
,
false
);
assertCursor
(
cursor
,
new
Selection
(
4
,
4
,
4
,
4
));
CoreEditingCommands
.
Tab
.
runEditorCommand
(
null
,
editor
,
null
);
assert
.
equal
(
model
.
getLineContent
(
4
),
'
\t\t\t\t\t
'
);
});
model
.
dispose
();
});
});
interface
ICursorOpts
{
...
...
@@ -3061,7 +3048,7 @@ suite('autoClosingPairs', () => {
class
AutoClosingMode
extends
MockMode
{
private
static
_id
=
new
LanguageIdentifier
(
'
autoClosingMode
'
,
3
);
private
static
_id
=
new
LanguageIdentifier
(
'
autoClosingMode
'
,
5
);
constructor
()
{
super
(
AutoClosingMode
.
_id
);
...
...
src/vs/editor/test/common/modes/supports/onEnter.test.ts
浏览文件 @
9bda5f0d
...
...
@@ -10,34 +10,6 @@ import { OnEnterSupport } from 'vs/editor/common/modes/supports/onEnter';
suite
(
'
OnEnter
'
,
()
=>
{
test
(
'
uses indentationRules
'
,
()
=>
{
var
support
=
new
OnEnterSupport
({
indentationRules
:
{
decreaseIndentPattern
:
/^
\s
*
((?!\S
.*
\/[
*
])
.*
[
*
]\/\s
*
)?[
})
\]]
|^
\s
*
(
case
\b
.*|default
)
:
\s
*
(\/\/
.*|
\/[
*
]
.*
[
*
]\/\s
*
)?
$/
,
increaseIndentPattern
:
/
(\{[^
}"'`
]
*|
\([^
)"'
]
*|
\[[^\]
"'
]
*|^
\s
*
(\{\}
|
\(\)
|
\[\]
|
(
case
\b
.*|default
)
:
))\s
*
(\/\/
.*|
\/[
*
]
.*
[
*
]\/\s
*
)?
$/
,
indentNextLinePattern
:
/^
\s
*
(
for|while|if|else
)\b(?!
.*
[
;{}
]\s
*
(\/\/
.*|
\/[
*
]
.*
[
*
]\/\s
*
)?
$
)
/
,
unIndentedLinePattern
:
/^
(?!
.*
([
;{}
]
|
\S
:
)\s
*
(\/\/
.*|
\/[
*
]
.*
[
*
]\/\s
*
)?
$
)(?!
.*
(\{[^
}"'
]
*|
\([^
)"'
]
*|
\[[^\]
"'
]
*|^
\s
*
(\{\}
|
\(\)
|
\[\]
|
(
case
\b
.*|default
)
:
))\s
*
(\/\/
.*|
\/[
*
]
.*
[
*
]\/\s
*
)?
$
)(?!
^
\s
*
((?!\S
.*
\/[
*
])
.*
[
*
]\/\s
*
)?[
})
\]]
|^
\s
*
(
case
\b
.*|default
)
:
\s
*
(\/\/
.*|
\/[
*
]
.*
[
*
]\/\s
*
)?
$
)(?!
^
\s
*
(
for|while|if|else
)\b(?!
.*
[
;{}
]\s
*
(\/\/
.*|
\/[
*
]
.*
[
*
]\/\s
*
)?
$
))
/
}
});
var
testIndentAction
=
(
oneLineAboveText
:
string
,
beforeText
:
string
,
afterText
:
string
,
expected
:
IndentAction
)
=>
{
var
actual
=
support
.
onEnter
(
oneLineAboveText
,
beforeText
,
afterText
);
if
(
expected
===
IndentAction
.
None
)
{
assert
.
equal
(
actual
,
null
);
}
else
{
assert
.
equal
(
actual
.
indentAction
,
expected
);
}
};
testIndentAction
(
''
,
'
case
'
,
''
,
IndentAction
.
None
);
testIndentAction
(
''
,
'
case:
'
,
''
,
IndentAction
.
Indent
);
testIndentAction
(
''
,
'
if (true) {
'
,
''
,
IndentAction
.
Indent
);
testIndentAction
(
''
,
'
if (true)
'
,
''
,
IndentAction
.
Indent
);
testIndentAction
(
''
,
'
'
,
'
}
'
,
IndentAction
.
Outdent
);
testIndentAction
(
'
if(true)
'
,
'
\t
return false
'
,
''
,
IndentAction
.
Outdent
);
testIndentAction
(
''
,
'
var foo = `{`;
'
,
''
,
IndentAction
.
None
);
});
test
(
'
uses brackets
'
,
()
=>
{
var
brackets
:
CharacterPair
[]
=
[
[
'
(
'
,
'
)
'
],
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录