提交 05960dc4 编写于 作者: A Alex Dima

Fixes #1120: Indenting should not indent empty lines

上级 2b2d8133
......@@ -61,7 +61,8 @@ export class ShiftCommand implements EditorCommon.ICommand {
let lineNumber:number,
tabSize = this._opts.tabSize,
oneIndent = this._opts.oneIndent;
oneIndent = this._opts.oneIndent,
shouldIndentEmptyLines = (startLine === endLine);
// indents[i] represents i * oneIndent
let indents: string[] = ['', oneIndent];
......@@ -85,6 +86,11 @@ export class ShiftCommand implements EditorCommon.ICommand {
continue;
}
if (!shouldIndentEmptyLines && !this._opts.isUnshift && lineText.length === 0) {
// do not indent empty lines => nothing to do
continue;
}
if (indentationEndIndex === -1) {
// the entire line is whitespace
indentationEndIndex = lineText.length;
......
......@@ -277,10 +277,50 @@ suite('Editor Commands - ShiftCommand', () => {
'My First Line',
'\t\tMy Second Line',
' Third Line',
'\t',
'',
'\t123'
],
new Selection(4, 1, 5, 3)
);
});
test('issue #1120 TAB should not indent empty lines in a multi-line selection', () => {
testShiftCommand(
[
'My First Line',
'\t\tMy Second Line',
' Third Line',
'',
'123'
],
new Selection(1, 1, 5, 2),
[
'\tMy First Line',
'\t\t\tMy Second Line',
'\t\tThird Line',
'',
'\t123'
],
new Selection(4, 2, 5, 3)
new Selection(1, 2, 5, 3)
);
testShiftCommand(
[
'My First Line',
'\t\tMy Second Line',
' Third Line',
'',
'123'
],
new Selection(4, 1, 5, 1),
[
'My First Line',
'\t\tMy Second Line',
' Third Line',
'\t',
'123'
],
new Selection(4, 2, 5, 1)
);
});
......@@ -464,7 +504,7 @@ suite('Editor Commands - ShiftCommand', () => {
'\tMy First Line',
'\tMy Second Line',
'\tThird Line',
'\t',
'',
'\t123'
],
new Selection(1, 2, 5, 5)
......@@ -503,13 +543,13 @@ suite('Editor Commands - ShiftCommand', () => {
],
new Selection(1,1,5,20),
[
'\t',
'',
'\t/**',
'\t * a doc comment',
'\t */',
'\tfunction hello() {}'
],
new Selection(1,2,5,21)
new Selection(1,1,5,21)
);
testUnshiftCommandInDocBlockCommentMode(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册