From dd460f29af313afa3d4f4c02a07ecbf780f5664b Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 5 Apr 2018 10:18:45 +0200 Subject: [PATCH] Fixes #47004: Toggle comments shouldn't move cursor --- .../contrib/comment/lineCommentCommand.ts | 8 ++-- .../comment/test/lineCommentCommand.test.ts | 47 ++++++++++++------- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/vs/editor/contrib/comment/lineCommentCommand.ts b/src/vs/editor/contrib/comment/lineCommentCommand.ts index 4a31a0424b7..fd3c9a3912a 100644 --- a/src/vs/editor/contrib/comment/lineCommentCommand.ts +++ b/src/vs/editor/contrib/comment/lineCommentCommand.ts @@ -336,10 +336,10 @@ export class LineCommentCommand implements editorCommon.ICommand { } return new Selection( - result.startLineNumber, - result.startColumn + this._deltaColumn, - result.endLineNumber, - result.endColumn + this._deltaColumn + result.selectionStartLineNumber, + result.selectionStartColumn + this._deltaColumn, + result.positionLineNumber, + result.positionColumn + this._deltaColumn ); } diff --git a/src/vs/editor/contrib/comment/test/lineCommentCommand.test.ts b/src/vs/editor/contrib/comment/test/lineCommentCommand.test.ts index 57cd4ccde56..932e73bde2e 100644 --- a/src/vs/editor/contrib/comment/test/lineCommentCommand.test.ts +++ b/src/vs/editor/contrib/comment/test/lineCommentCommand.test.ts @@ -256,7 +256,7 @@ suite('Editor Contrib - Line Comment Command', () => { '\t!@# some text', '\t!@# some more text' ], - new Selection(1, 1, 2, 2) + new Selection(2, 2, 1, 1) ); }); @@ -271,7 +271,7 @@ suite('Editor Contrib - Line Comment Command', () => { '\t!@# some text', ' !@# some more text' ], - new Selection(1, 1, 2, 2) + new Selection(2, 2, 1, 1) ); }); @@ -290,7 +290,7 @@ suite('Editor Contrib - Line Comment Command', () => { '', '\t!@# some more text' ], - new Selection(1, 1, 4, 2) + new Selection(4, 2, 1, 1) ); }); @@ -307,7 +307,7 @@ suite('Editor Contrib - Line Comment Command', () => { '\t ', '\t\tsome more text' ], - new Selection(1, 1, 3, 2) + new Selection(3, 2, 1, 1) ); }); @@ -324,7 +324,7 @@ suite('Editor Contrib - Line Comment Command', () => { '\t!@# ', '\t\tsome more text' ], - new Selection(1, 1, 3, 1) + new Selection(3, 1, 1, 1) ); }); @@ -369,7 +369,7 @@ suite('Editor Contrib - Line Comment Command', () => { 'first!@#', '\t!@# second line' ], - new Selection(2, 1, 2, 7) + new Selection(2, 7, 2, 1) ); }); @@ -390,7 +390,7 @@ suite('Editor Contrib - Line Comment Command', () => { 'fourth line', 'fifth' ], - new Selection(1, 5, 2, 1) + new Selection(2, 1, 1, 5) ); }); @@ -411,7 +411,7 @@ suite('Editor Contrib - Line Comment Command', () => { 'fourth line', 'fifth' ], - new Selection(1, 5, 2, 8) + new Selection(2, 8, 1, 5) ); }); @@ -432,7 +432,7 @@ suite('Editor Contrib - Line Comment Command', () => { '!@# fourth line', 'fifth' ], - new Selection(3, 5, 4, 8) + new Selection(4, 8, 3, 5) ); }); @@ -493,7 +493,7 @@ suite('Editor Contrib - Line Comment Command', () => { 'fourth line', 'fifth' ], - new Selection(1, 5, 2, 8) + new Selection(2, 8, 1, 5) ); testLineCommentCommand( @@ -512,7 +512,7 @@ suite('Editor Contrib - Line Comment Command', () => { 'fourth line', 'fifth' ], - new Selection(1, 1, 2, 3) + new Selection(2, 3, 1, 1) ); }); @@ -607,6 +607,21 @@ suite('Editor Contrib - Line Comment Command', () => { new Selection(1, 1, 8, 60) ); }); + + test('issue #47004: Toggle comments shouldn\'t move cursor', () => { + testAddLineCommentCommand( + [ + ' A line', + ' Another line' + ], + new Selection(2, 7, 1, 1), + [ + ' !@# A line', + ' !@# Another line' + ], + new Selection(2, 11, 1, 1) + ); + }); }); suite('Editor Contrib - Line Comment As Block Comment', () => { @@ -655,7 +670,7 @@ suite('Editor Contrib - Line Comment As Block Comment', () => { 'fourth line', 'fifth' ], - new Selection(1, 1, 1, 6) + new Selection(1, 6, 1, 1) ); }); @@ -697,7 +712,7 @@ suite('Editor Contrib - Line Comment As Block Comment', () => { 'fourth line', 'fifth' ], - new Selection(1, 5, 3, 2) + new Selection(3, 2, 1, 5) ); testLineCommentCommand( @@ -716,7 +731,7 @@ suite('Editor Contrib - Line Comment As Block Comment', () => { 'fourth line', 'fifth' ], - new Selection(1, 1, 3, 11) + new Selection(3, 11, 1, 1) ); }); }); @@ -842,7 +857,7 @@ suite('Editor Contrib - Line Comment As Block Comment 2', () => { 'fourth line', '\t\tfifth\t\t' ], - new Selection(5, 3, 5, 8) + new Selection(5, 8, 5, 3) ); testLineCommentCommand( @@ -861,7 +876,7 @@ suite('Editor Contrib - Line Comment As Block Comment 2', () => { 'fourth line', '\t\tfifth\t\t' ], - new Selection(5, 3, 5, 8) + new Selection(5, 8, 5, 3) ); testLineCommentCommand(