diff --git a/src/vs/editor/common/commands/shiftCommand.ts b/src/vs/editor/common/commands/shiftCommand.ts index b4cbf83971796ea4809e39e13757c7e754b2d29a..78a23889a2fb4d6a11e8e2173397a2aae3d49927 100644 --- a/src/vs/editor/common/commands/shiftCommand.ts +++ b/src/vs/editor/common/commands/shiftCommand.ts @@ -179,7 +179,7 @@ export class ShiftCommand implements ICommand { } this._addEditOperation(builder, new Range(lineNumber, 1, lineNumber, indentationEndIndex + 1), desiredIndent); - if (lineNumber === startLine) { + if (lineNumber === startLine && !this._selection.isEmpty()) { // Force the startColumn to stay put because we're inserting after it this._selectionStartColumnStaysPut = (this._selection.startColumn <= indentationEndIndex + 1); } @@ -226,7 +226,7 @@ export class ShiftCommand implements ICommand { this._addEditOperation(builder, new Range(lineNumber, 1, lineNumber, indentationEndIndex + 1), ''); } else { this._addEditOperation(builder, new Range(lineNumber, 1, lineNumber, 1), oneIndent); - if (lineNumber === startLine) { + if (lineNumber === startLine && !this._selection.isEmpty()) { // Force the startColumn to stay put because we're inserting after it this._selectionStartColumnStaysPut = (this._selection.startColumn === 1); } diff --git a/src/vs/editor/contrib/linesOperations/test/linesOperations.test.ts b/src/vs/editor/contrib/linesOperations/test/linesOperations.test.ts index e9479c0f6d4c16b82a131d102877c335b9f44bcd..586632150888cc0ab686c6bb95fe868dcf275e83 100644 --- a/src/vs/editor/contrib/linesOperations/test/linesOperations.test.ts +++ b/src/vs/editor/contrib/linesOperations/test/linesOperations.test.ts @@ -928,6 +928,28 @@ suite('Editor Contrib - Line Operations', () => { model.dispose(); }); + test('issue #80736: Indenting while the cursor is at the start of a line of text causes the added spaces or tab to be selected', () => { + const model = createTextModel( + [ + 'Some text' + ].join('\n'), + { + insertSpaces: false, + } + ); + + withTestCodeEditor(null, { model: model }, (editor) => { + const indentLinesAction = new IndentLinesAction(); + editor.setPosition(new Position(1, 1)); + + indentLinesAction.run(null!, editor); + assert.equal(model.getLineContent(1), '\tSome text'); + assert.deepEqual(editor.getSelection(), new Selection(1, 2, 1, 2)); + }); + + model.dispose(); + }); + test('issue #62112: Delete line does not work properly when multiple cursors are on line', () => { const TEXT = [ 'a', diff --git a/src/vs/editor/test/browser/commands/shiftCommand.test.ts b/src/vs/editor/test/browser/commands/shiftCommand.test.ts index a2fb70ae69ba03cbb453fe594f3dfd96006e92a4..10fa4d4b469b8a4790a366324246eec2be02a0a2 100644 --- a/src/vs/editor/test/browser/commands/shiftCommand.test.ts +++ b/src/vs/editor/test/browser/commands/shiftCommand.test.ts @@ -92,7 +92,7 @@ suite('Editor Commands - ShiftCommand', () => { '', '123' ], - new Selection(1, 1, 1, 2) + new Selection(1, 2, 1, 2) ); });