fix #127198.
This commit is contained in:
parent
302af5ff63
commit
14de627cf2
2 changed files with 42 additions and 1 deletions
|
@ -143,6 +143,11 @@ export class FindModel extends Disposable {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (findMatches.length === 0) {
|
||||||
|
this.set([], false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this._currentMatch === -1) {
|
if (this._currentMatch === -1) {
|
||||||
// no active current match
|
// no active current match
|
||||||
this.set(findMatches, false);
|
this.set(findMatches, false);
|
||||||
|
@ -186,7 +191,7 @@ export class FindModel extends Disposable {
|
||||||
?? this._findMatches[oldCurrIndex.index].matches[oldCurrIndex.remainder].range;
|
?? this._findMatches[oldCurrIndex.index].matches[oldCurrIndex.remainder].range;
|
||||||
|
|
||||||
// not attached, just use the range
|
// not attached, just use the range
|
||||||
const matchAfterSelection = findFirstInSorted(findMatches, match => match.index >= oldCurrMatchCellIndex);
|
const matchAfterSelection = findFirstInSorted(findMatches, match => match.index >= oldCurrMatchCellIndex) % findMatches.length;
|
||||||
if (findMatches[matchAfterSelection].index > oldCurrMatchCellIndex) {
|
if (findMatches[matchAfterSelection].index > oldCurrMatchCellIndex) {
|
||||||
// there is no search result in curr cell anymore
|
// there is no search result in curr cell anymore
|
||||||
this._updateCurrentMatch(findMatches, this._matchesCountBeforeIndex(findMatches, matchAfterSelection));
|
this._updateCurrentMatch(findMatches, this._matchesCountBeforeIndex(findMatches, matchAfterSelection));
|
||||||
|
@ -215,6 +220,12 @@ export class FindModel extends Disposable {
|
||||||
this.constructFindMatchesStarts();
|
this.constructFindMatchesStarts();
|
||||||
this._currentMatch = -1;
|
this._currentMatch = -1;
|
||||||
this.clearCurrentFindMatchDecoration();
|
this.clearCurrentFindMatchDecoration();
|
||||||
|
|
||||||
|
this._state.changeMatchInfo(
|
||||||
|
this._currentMatch,
|
||||||
|
this._findMatches.reduce((p, c) => p + c.matches.length, 0),
|
||||||
|
undefined
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -192,4 +192,34 @@ suite('Notebook Find', () => {
|
||||||
assert.strictEqual(model.currentMatch, 1);
|
assert.strictEqual(model.currentMatch, 1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Reset when match not found, #127198', async function () {
|
||||||
|
await withTestNotebook(
|
||||||
|
[
|
||||||
|
['# header 1', 'markdown', CellKind.Markup, [], {}],
|
||||||
|
['paragraph 1', 'markdown', CellKind.Markup, [], {}],
|
||||||
|
['paragraph 2', 'markdown', CellKind.Markup, [], {}],
|
||||||
|
],
|
||||||
|
async (editor, viewModel, accessor) => {
|
||||||
|
accessor.stub(IConfigurationService, configurationService);
|
||||||
|
const state = new FindReplaceState();
|
||||||
|
const model = new FindModel(editor, state, accessor.get(IConfigurationService));
|
||||||
|
state.change({ isRevealed: true }, true);
|
||||||
|
state.change({ searchString: '1' }, true);
|
||||||
|
assert.strictEqual(model.findMatches.length, 2);
|
||||||
|
assert.strictEqual(model.currentMatch, -1);
|
||||||
|
model.find(false);
|
||||||
|
assert.strictEqual(model.currentMatch, 0);
|
||||||
|
model.find(false);
|
||||||
|
assert.strictEqual(model.currentMatch, 1);
|
||||||
|
model.find(false);
|
||||||
|
assert.strictEqual(model.currentMatch, 0);
|
||||||
|
|
||||||
|
assert.strictEqual(editor.textModel.length, 3);
|
||||||
|
|
||||||
|
state.change({ searchString: '3' }, true);
|
||||||
|
assert.strictEqual(model.currentMatch, -1);
|
||||||
|
assert.strictEqual(model.findMatches.length, 0);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue