diff --git a/src/vs/editor/contrib/find/common/findController.ts b/src/vs/editor/contrib/find/common/findController.ts index f4f914d1031..61bf37e96a7 100644 --- a/src/vs/editor/contrib/find/common/findController.ts +++ b/src/vs/editor/contrib/find/common/findController.ts @@ -617,10 +617,19 @@ export class AddSelectionToNextFindMatchAction extends SelectNextFindMatchAction // If there are mulitple cursors, handle the case where they do not all select the same text. if (allSelections.length > 1) { const model = editor.getModel(); + const controller = CommonFindController.get(editor); + if (!controller) { + return; + } + const findState = controller.getState(); + const caseSensitive = findState.matchCase; let selectionsContainSameText = true; let selectedText = model.getValueInRange(allSelections[0]); + if (!caseSensitive) { + selectedText = selectedText.toLowerCase(); + } for (let i = 1, len = allSelections.length; i < len; i++) { let selection = allSelections[i]; if (selection.isEmpty()) { @@ -629,6 +638,9 @@ export class AddSelectionToNextFindMatchAction extends SelectNextFindMatchAction } let thisSelectedText = model.getValueInRange(selection); + if (!caseSensitive) { + thisSelectedText = thisSelectedText.toLowerCase(); + } if (selectedText !== thisSelectedText) { selectionsContainSameText = false; break; diff --git a/src/vs/editor/contrib/find/test/common/findController.test.ts b/src/vs/editor/contrib/find/test/common/findController.test.ts index 71e5fec73f0..b77f57d68a7 100644 --- a/src/vs/editor/contrib/find/test/common/findController.test.ts +++ b/src/vs/editor/contrib/find/test/common/findController.test.ts @@ -386,25 +386,26 @@ suite('FindController', () => { return result; } - function testAddSelectionToNextFindMatchAction(callback: (editor: MockCodeEditor, action: AddSelectionToNextFindMatchAction) => void): void { - withMockCodeEditor([ - 'abc pizza', - 'abc house', - 'abc bar' - ], {}, (editor, cursor) => { + function testAddSelectionToNextFindMatchAction(text: string[], callback: (editor: MockCodeEditor, action: AddSelectionToNextFindMatchAction, findController: TestFindController) => void): void { + withMockCodeEditor(text, {}, (editor, cursor) => { let findController = editor.registerAndInstantiateContribution(TestFindController); let action = new AddSelectionToNextFindMatchAction(); - callback(editor, action); + callback(editor, action, findController); findController.dispose(); }); } test('AddSelectionToNextFindMatchAction starting with single collapsed selection', () => { - testAddSelectionToNextFindMatchAction((editor, action) => { + const text = [ + 'abc pizza', + 'abc house', + 'abc bar' + ]; + testAddSelectionToNextFindMatchAction(text, (editor, action, findController) => { editor.setSelections([ new Selection(1, 2, 1, 2), ]); @@ -437,7 +438,12 @@ suite('FindController', () => { }); test('AddSelectionToNextFindMatchAction starting with two selections, one being collapsed 1)', () => { - testAddSelectionToNextFindMatchAction((editor, action) => { + const text = [ + 'abc pizza', + 'abc house', + 'abc bar' + ]; + testAddSelectionToNextFindMatchAction(text, (editor, action, findController) => { editor.setSelections([ new Selection(1, 1, 1, 4), new Selection(2, 2, 2, 2), @@ -466,7 +472,12 @@ suite('FindController', () => { }); test('AddSelectionToNextFindMatchAction starting with two selections, one being collapsed 2)', () => { - testAddSelectionToNextFindMatchAction((editor, action) => { + const text = [ + 'abc pizza', + 'abc house', + 'abc bar' + ]; + testAddSelectionToNextFindMatchAction(text, (editor, action, findController) => { editor.setSelections([ new Selection(1, 2, 1, 2), new Selection(2, 1, 2, 4), @@ -495,7 +506,12 @@ suite('FindController', () => { }); test('AddSelectionToNextFindMatchAction starting with all collapsed selections', () => { - testAddSelectionToNextFindMatchAction((editor, action) => { + const text = [ + 'abc pizza', + 'abc house', + 'abc bar' + ]; + testAddSelectionToNextFindMatchAction(text, (editor, action, findController) => { editor.setSelections([ new Selection(1, 2, 1, 2), new Selection(2, 2, 2, 2), @@ -519,7 +535,12 @@ suite('FindController', () => { }); test('AddSelectionToNextFindMatchAction starting with all collapsed selections on different words', () => { - testAddSelectionToNextFindMatchAction((editor, action) => { + const text = [ + 'abc pizza', + 'abc house', + 'abc bar' + ]; + testAddSelectionToNextFindMatchAction(text, (editor, action, findController) => { editor.setSelections([ new Selection(1, 6, 1, 6), new Selection(2, 6, 2, 6), @@ -541,4 +562,58 @@ suite('FindController', () => { ]); }); }); + + test('issue #20651: AddSelectionToNextFindMatchAction case insensitive', () => { + const text = [ + 'test', + 'testte', + 'Test', + 'testte', + 'test' + ]; + testAddSelectionToNextFindMatchAction(text, (editor, action, findController) => { + editor.setSelections([ + new Selection(1, 1, 1, 5), + ]); + + action.run(null, editor); + assert.deepEqual(editor.getSelections(), [ + new Selection(1, 1, 1, 5), + new Selection(2, 1, 2, 5), + ]); + + action.run(null, editor); + assert.deepEqual(editor.getSelections(), [ + new Selection(1, 1, 1, 5), + new Selection(2, 1, 2, 5), + new Selection(3, 1, 3, 5), + ]); + + action.run(null, editor); + assert.deepEqual(editor.getSelections(), [ + new Selection(1, 1, 1, 5), + new Selection(2, 1, 2, 5), + new Selection(3, 1, 3, 5), + new Selection(4, 1, 4, 5), + ]); + + action.run(null, editor); + assert.deepEqual(editor.getSelections(), [ + new Selection(1, 1, 1, 5), + new Selection(2, 1, 2, 5), + new Selection(3, 1, 3, 5), + new Selection(4, 1, 4, 5), + new Selection(5, 1, 5, 5), + ]); + + action.run(null, editor); + assert.deepEqual(editor.getSelections(), [ + new Selection(1, 1, 1, 5), + new Selection(2, 1, 2, 5), + new Selection(3, 1, 3, 5), + new Selection(4, 1, 4, 5), + new Selection(5, 1, 5, 5), + ]); + }); + }); });