Fixes #20651: Honor matchCase flag in multi cursor Ctrl+D check

This commit is contained in:
Alex Dima
2017-02-22 21:16:51 +01:00
parent 45b6708cf3
commit e5d15f9c14
2 changed files with 99 additions and 12 deletions
@@ -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;
@@ -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>(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),
]);
});
});
});