File tree Expand file tree Collapse file tree
src/vs/workbench/contrib/notebook/browser Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -223,6 +223,9 @@ registerAction2(class extends Action2 {
223223 } else {
224224 controller . setFoldingStateDown ( index , CellFoldingState . Collapsed , levels ) ;
225225 }
226+
227+ const viewIndex = editor . viewModel ! . getNearestVisibleCellIndexUpwards ( index ) ;
228+ editor . selectElement ( editor . viewModel ! . viewCells [ viewIndex ] ) ;
226229 }
227230 }
228231} ) ;
Original file line number Diff line number Diff line change @@ -460,6 +460,30 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
460460 return this . _viewCells . indexOf ( cell as CellViewModel ) ;
461461 }
462462
463+ /**
464+ * If this._viewCells[index] is visible then return index
465+ */
466+ getNearestVisibleCellIndexUpwards ( index : number ) {
467+ for ( let i = this . _hiddenRanges . length - 1 ; i >= 0 ; i -- ) {
468+ const cellRange = this . _hiddenRanges [ i ] ;
469+ const foldStart = cellRange . start - 1 ;
470+ const foldEnd = cellRange . end ;
471+
472+ if ( foldStart > index ) {
473+ continue ;
474+ }
475+
476+ if ( foldStart <= index && foldEnd >= index ) {
477+ return index ;
478+ }
479+
480+ // foldStart <= index, foldEnd < index
481+ break ;
482+ }
483+
484+ return index ;
485+ }
486+
463487 getNextVisibleCellIndex ( index : number ) {
464488 for ( let i = 0 ; i < this . _hiddenRanges . length ; i ++ ) {
465489 const cellRange = this . _hiddenRanges [ i ] ;
You can’t perform that action at this time.
0 commit comments