diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/find/findModel.ts b/src/vs/workbench/contrib/notebook/browser/contrib/find/findModel.ts index 7858fef22dc..072ba66abf4 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/find/findModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/find/findModel.ts @@ -220,8 +220,8 @@ export class FindModel extends Disposable { const matchesBefore = findMatchIndex === 0 ? 0 : (this._findMatchesStarts?.getPrefixSum(findMatchIndex - 1) ?? 0); this._currentMatch = matchesBefore + index; - this.highlightCurrentFindMatchDecoration(findMatchIndex, index).then(offset => { - this.revealCellRange(findMatchIndex, index, offset); + this.highlightCurrentFindMatchDecoration(findMatchIndex, index).then(async offset => { + await this.revealCellRange(findMatchIndex, index, offset); this._state.changeMatchInfo( this._currentMatch, @@ -259,8 +259,8 @@ export class FindModel extends Disposable { const nextIndex = this._findMatchesStarts!.getIndexOf(this._currentMatch); // const newFocusedCell = this._findMatches[nextIndex.index].cell; - this.highlightCurrentFindMatchDecoration(nextIndex.index, nextIndex.remainder).then(offset => { - this.revealCellRange(nextIndex.index, nextIndex.remainder, offset); + this.highlightCurrentFindMatchDecoration(nextIndex.index, nextIndex.remainder).then(async offset => { + await this.revealCellRange(nextIndex.index, nextIndex.remainder, offset); this._state.changeMatchInfo( this._currentMatch, @@ -270,7 +270,7 @@ export class FindModel extends Disposable { }); } - private revealCellRange(cellIndex: number, matchIndex: number, outputOffset: number | null) { + private async revealCellRange(cellIndex: number, matchIndex: number, outputOffset: number | null) { const findMatch = this._findMatches[cellIndex]; if (matchIndex >= findMatch.contentMatches.length) { // reveal output range @@ -288,6 +288,9 @@ export class FindModel extends Disposable { findMatch.cell.isInputCollapsed = false; this._notebookEditor.focusElement(findMatch.cell); this._notebookEditor.setCellEditorSelection(findMatch.cell, match.range); + // First ensure the cell is visible in the notebook viewport + await this._notebookEditor.revealInView(findMatch.cell); + // Then reveal the specific range within the cell editor this._notebookEditor.revealRangeInCenterIfOutsideViewportAsync(findMatch.cell, match.range); } } diff --git a/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts b/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts index 8731f5e2c3f..e421996c3f2 100644 --- a/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts +++ b/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts @@ -313,6 +313,7 @@ function _createTestNotebookEditor(instantiationService: TestInstantiationServic override getViewIndexByModelIndex(index: number) { return listViewInfoAccessor.getViewIndex(viewModel.viewCells[index]); } override getCellRangeFromViewRange(startIndex: number, endIndex: number) { return listViewInfoAccessor.getCellRangeFromViewRange(startIndex, endIndex); } override revealCellRangeInView() { } + override async revealInView() { } override setHiddenAreas(_ranges: ICellRange[]): boolean { return cellList.setHiddenAreas(_ranges, true); }