Fix/find context correction (#9949)

* trigger input change on new notebooks

* return to avoid further executions

* remove unnecessary check
This commit is contained in:
Maddy
2020-04-14 12:24:44 -07:00
committed by GitHub
parent fb1292426b
commit 0cdda5ed1b

View File

@@ -283,58 +283,56 @@ export class NotebookEditor extends BaseEditor implements IFindNotebookControlle
} else { } else {
this._finder.getDomNode().style.visibility = 'hidden'; this._finder.getDomNode().style.visibility = 'hidden';
this._findDecorations.clearDecorations(); this._findDecorations.clearDecorations();
return;
} }
} else { } else {
if (!this._findState.isRevealed) { if (!this._findState.isRevealed) {
this._finder.getDomNode().style.visibility = 'hidden'; this._finder.getDomNode().style.visibility = 'hidden';
this._findDecorations.clearDecorations(); this._findDecorations.clearDecorations();
return;
} }
} }
if (e.searchString || e.matchCase || e.wholeWord) { if (e.searchString || e.matchCase || e.wholeWord) {
this._findDecorations.clearDecorations(); this._findDecorations.clearDecorations();
// if the search scope changes remove the prev // if the search scope changes remove the prev
if (this._notebookModel) { if (this._notebookModel && this._findState.searchString) {
if (this._findState.searchString) { let findScope = this._findDecorations.getFindScope();
let findScope = this._findDecorations.getFindScope(); if (this._findState.searchString === this.notebookFindModel.findExpression && findScope && !e.matchCase && !e.wholeWord && !e.searchScope) {
if (this._findState.searchString === this.notebookFindModel.findExpression && findScope !== null && !e.matchCase && !e.wholeWord && !e.searchScope) { this._updateFinderMatchState();
if (findScope) { this._findState.changeMatchInfo(
this._updateFinderMatchState(); this.notebookFindModel.getFindIndex(),
this._findState.changeMatchInfo( this._findDecorations.getCount(),
this.notebookFindModel.getFindIndex(), this._currentMatch
this._findDecorations.getCount(), );
this._currentMatch this._setCurrentFindMatch(findScope);
); } else {
this._setCurrentFindMatch(findScope); this.notebookInput.notebookFindModel.clearDecorations();
} this.notebookFindModel.findExpression = this._findState.searchString;
} else { this.notebookInput.notebookFindModel.find(this._findState.searchString, this._findState.matchCase, this._findState.wholeWord, NOTEBOOK_MAX_MATCHES).then(findRange => {
this.notebookInput.notebookFindModel.clearDecorations(); if (findRange) {
this.notebookFindModel.findExpression = this._findState.searchString; this.updatePosition(findRange);
this.notebookInput.notebookFindModel.find(this._findState.searchString, this._findState.matchCase, this._findState.wholeWord, NOTEBOOK_MAX_MATCHES).then(findRange => { } else if (this.notebookFindModel.findMatches.length > 0) {
if (findRange) { this.updatePosition(this.notebookFindModel.findMatches[0].range);
this.updatePosition(findRange); } else {
} else if (this.notebookFindModel.findMatches.length > 0) { this.notebookInput.notebookFindModel.clearFind();
this.updatePosition(this.notebookFindModel.findMatches[0].range);
} else {
this.notebookInput.notebookFindModel.clearFind();
this._updateFinderMatchState();
this._finder.focusFindInput();
return;
}
this._updateFinderMatchState(); this._updateFinderMatchState();
this._finder.focusFindInput(); this._finder.focusFindInput();
this._findDecorations.set(this.notebookFindModel.findMatches, this._currentMatch); return;
this._findState.changeMatchInfo( }
this.notebookFindModel.getFindIndex(), this._updateFinderMatchState();
this._findDecorations.getCount(), this._finder.focusFindInput();
this._currentMatch this._findDecorations.set(this.notebookFindModel.findMatches, this._currentMatch);
); this._findState.changeMatchInfo(
this._setCurrentFindMatch(this._currentMatch); this.notebookFindModel.getFindIndex(),
}); this._findDecorations.getCount(),
} this._currentMatch
} else { );
this.notebookFindModel.clearFind(); this._setCurrentFindMatch(this._currentMatch);
});
} }
} else {
this.notebookFindModel.clearFind();
} }
} }
if (e.searchScope) { if (e.searchScope) {
@@ -377,6 +375,11 @@ export class NotebookEditor extends BaseEditor implements IFindNotebookControlle
this._register(this._notebookModel.contentChanged(e => { this._register(this._notebookModel.contentChanged(e => {
this._onFindStateChange(changeEvent).catch(onUnexpectedError); this._onFindStateChange(changeEvent).catch(onUnexpectedError);
})); }));
this._register(this._notebookService.onNotebookEditorAdd(async (e) => {
// wait for the model to be ready and trigger input change
await e.modelReady;
this._triggerInputChange();
}));
} }
public setSelection(range: NotebookRange): void { public setSelection(range: NotebookRange): void {