diff --git a/src/sql/workbench/contrib/notebook/browser/notebookEditor.ts b/src/sql/workbench/contrib/notebook/browser/notebookEditor.ts index a00e9f305b..cba6495bf7 100644 --- a/src/sql/workbench/contrib/notebook/browser/notebookEditor.ts +++ b/src/sql/workbench/contrib/notebook/browser/notebookEditor.ts @@ -283,58 +283,56 @@ export class NotebookEditor extends BaseEditor implements IFindNotebookControlle } else { this._finder.getDomNode().style.visibility = 'hidden'; this._findDecorations.clearDecorations(); + return; } } else { if (!this._findState.isRevealed) { this._finder.getDomNode().style.visibility = 'hidden'; this._findDecorations.clearDecorations(); + return; } } if (e.searchString || e.matchCase || e.wholeWord) { this._findDecorations.clearDecorations(); // if the search scope changes remove the prev - if (this._notebookModel) { - if (this._findState.searchString) { - let findScope = this._findDecorations.getFindScope(); - if (this._findState.searchString === this.notebookFindModel.findExpression && findScope !== null && !e.matchCase && !e.wholeWord && !e.searchScope) { - if (findScope) { - this._updateFinderMatchState(); - this._findState.changeMatchInfo( - this.notebookFindModel.getFindIndex(), - this._findDecorations.getCount(), - this._currentMatch - ); - this._setCurrentFindMatch(findScope); - } - } else { - this.notebookInput.notebookFindModel.clearDecorations(); - this.notebookFindModel.findExpression = this._findState.searchString; - this.notebookInput.notebookFindModel.find(this._findState.searchString, this._findState.matchCase, this._findState.wholeWord, NOTEBOOK_MAX_MATCHES).then(findRange => { - if (findRange) { - this.updatePosition(findRange); - } else if (this.notebookFindModel.findMatches.length > 0) { - this.updatePosition(this.notebookFindModel.findMatches[0].range); - } else { - this.notebookInput.notebookFindModel.clearFind(); - this._updateFinderMatchState(); - this._finder.focusFindInput(); - return; - } + if (this._notebookModel && this._findState.searchString) { + let findScope = this._findDecorations.getFindScope(); + if (this._findState.searchString === this.notebookFindModel.findExpression && findScope && !e.matchCase && !e.wholeWord && !e.searchScope) { + this._updateFinderMatchState(); + this._findState.changeMatchInfo( + this.notebookFindModel.getFindIndex(), + this._findDecorations.getCount(), + this._currentMatch + ); + this._setCurrentFindMatch(findScope); + } else { + this.notebookInput.notebookFindModel.clearDecorations(); + this.notebookFindModel.findExpression = this._findState.searchString; + this.notebookInput.notebookFindModel.find(this._findState.searchString, this._findState.matchCase, this._findState.wholeWord, NOTEBOOK_MAX_MATCHES).then(findRange => { + if (findRange) { + this.updatePosition(findRange); + } else if (this.notebookFindModel.findMatches.length > 0) { + this.updatePosition(this.notebookFindModel.findMatches[0].range); + } else { + this.notebookInput.notebookFindModel.clearFind(); this._updateFinderMatchState(); this._finder.focusFindInput(); - this._findDecorations.set(this.notebookFindModel.findMatches, this._currentMatch); - this._findState.changeMatchInfo( - this.notebookFindModel.getFindIndex(), - this._findDecorations.getCount(), - this._currentMatch - ); - this._setCurrentFindMatch(this._currentMatch); - }); - } - } else { - this.notebookFindModel.clearFind(); + return; + } + this._updateFinderMatchState(); + this._finder.focusFindInput(); + this._findDecorations.set(this.notebookFindModel.findMatches, this._currentMatch); + this._findState.changeMatchInfo( + this.notebookFindModel.getFindIndex(), + this._findDecorations.getCount(), + this._currentMatch + ); + this._setCurrentFindMatch(this._currentMatch); + }); } + } else { + this.notebookFindModel.clearFind(); } } if (e.searchScope) { @@ -377,6 +375,11 @@ export class NotebookEditor extends BaseEditor implements IFindNotebookControlle this._register(this._notebookModel.contentChanged(e => { 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 {