diff --git a/src/vs/editor/common/commands/shiftCommand.ts b/src/vs/editor/common/commands/shiftCommand.ts index e8cbe85680331f0c449aab23e79ae77a5a5124f2..957f9bc999b6bf7bed49d939944fd90c0578a267 100644 --- a/src/vs/editor/common/commands/shiftCommand.ts +++ b/src/vs/editor/common/commands/shiftCommand.ts @@ -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; diff --git a/src/vs/editor/test/common/commands/shiftCommand.test.ts b/src/vs/editor/test/common/commands/shiftCommand.test.ts index df580880cf6d43f9897be3a65a90753dbf1ea4b3..1eb460be73ad4b8bc5eef6716336ba8fcdf47be3 100644 --- a/src/vs/editor/test/common/commands/shiftCommand.test.ts +++ b/src/vs/editor/test/common/commands/shiftCommand.test.ts @@ -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(