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

Fixes #1120: Indenting should not indent empty lines

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