Fix find highlight for multiple find occurrences (#9518)

This commit is contained in:
Chris LaFreniere
2020-03-10 10:23:16 -07:00
committed by GitHub
parent 96935f2f87
commit 80ed6131ce
2 changed files with 40 additions and 1 deletions

View File

@@ -574,7 +574,11 @@ export class NotebookFindModel extends Disposable implements INotebookFindModel
break;
}
} else {
start = searchText.indexOf(exp) + index + 1;
start = searchText.indexOf(exp) + index;
// Editors aren't 0-based; the first character position in an editor is 1, so adding 1 to the first found index
if (index === 0) {
start++;
}
}
findResults.push(start);
index = start + exp.length;

View File

@@ -200,6 +200,41 @@ suite('Notebook Find Model', function (): void {
assert.equal(notebookFindModel.findMatches.length, 3, 'Find failed');
});
test('Should match find results for multiple results on same line', async function (): Promise<void> {
let codeContent: nb.INotebookContents = {
cells: [{
cell_type: CellTypes.Code,
source: ['abc abc abc abc abc abcabc ab a b c'],
metadata: { language: 'python' },
execution_count: 1
}],
metadata: {
kernelspec: {
name: 'python',
language: 'python'
}
},
nbformat: 4,
nbformat_minor: 5
};
await initNotebookModel(codeContent);
//initialize find
let notebookFindModel = new NotebookFindModel(model);
// Intentionally not using max_find_count here, as 7 items should be found
await notebookFindModel.find('abc', false, false, 10);
assert.equal(notebookFindModel.findMatches.length, 7, 'Find failed to find number of matches correctly');
assert.deepEqual(notebookFindModel.findMatches[0].range, new NotebookRange(model.cells[0], 1, 1, 1, 4));
assert.deepEqual(notebookFindModel.findMatches[1].range, new NotebookRange(model.cells[0], 1, 5, 1, 8));
assert.deepEqual(notebookFindModel.findMatches[2].range, new NotebookRange(model.cells[0], 1, 9, 1, 12));
assert.deepEqual(notebookFindModel.findMatches[3].range, new NotebookRange(model.cells[0], 1, 13, 1, 16));
assert.deepEqual(notebookFindModel.findMatches[4].range, new NotebookRange(model.cells[0], 1, 17, 1, 20));
assert.deepEqual(notebookFindModel.findMatches[5].range, new NotebookRange(model.cells[0], 1, 21, 1, 24));
assert.deepEqual(notebookFindModel.findMatches[6].range, new NotebookRange(model.cells[0], 1, 24, 1, 27));
});
test('Should find results correctly with & without matching case selection', async function (): Promise<void> {
// Need to set rendered text content for 2nd cell
setRenderedTextContent(1);