@@ -10,7 +10,7 @@ import { URI } from 'vs/base/common/uri';
10
10
import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
11
11
import { IMarkerService } from 'vs/platform/markers/common/markers' ;
12
12
import { IThemeService } from 'vs/platform/theme/common/themeService' ;
13
- import { IActiveNotebookEditor , ICellViewModel , INotebookEditor , type INotebookViewCellsUpdateEvent } from 'vs/workbench/contrib/notebook/browser/notebookBrowser' ;
13
+ import { IActiveNotebookEditor , ICellViewModel , INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser' ;
14
14
import { CellKind , NotebookCellsChangeType , NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
15
15
import { INotebookExecutionStateService , NotebookExecutionType } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService' ;
16
16
import { OutlineChangeEvent , OutlineConfigKeys , OutlineTarget } from 'vs/workbench/services/outline/browser/outline' ;
@@ -29,6 +29,10 @@ export class NotebookCellOutlineProvider {
29
29
private _uri : URI | undefined ;
30
30
private _entries : OutlineEntry [ ] = [ ] ;
31
31
get entries ( ) : OutlineEntry [ ] {
32
+ if ( this . delayedOutlineRecompute . isTriggered ( ) ) {
33
+ this . delayedOutlineRecompute . cancel ( ) ;
34
+ this . _recomputeState ( ) ;
35
+ }
32
36
return this . _entries ;
33
37
}
34
38
@@ -38,11 +42,15 @@ export class NotebookCellOutlineProvider {
38
42
readonly outlineKind = 'notebookCells' ;
39
43
40
44
get activeElement ( ) : OutlineEntry | undefined {
45
+ if ( this . delayedOutlineRecompute . isTriggered ( ) ) {
46
+ this . delayedOutlineRecompute . cancel ( ) ;
47
+ this . _recomputeState ( ) ;
48
+ }
41
49
return this . _activeEntry ;
42
50
}
43
51
44
52
private readonly _outlineEntryFactory : NotebookOutlineEntryFactory ;
45
- private readonly delayRecomputeActive : ( ) => void ;
53
+ private readonly delayedOutlineRecompute : Delayer < void > ; ;
46
54
constructor (
47
55
private readonly _editor : INotebookEditor ,
48
56
private readonly _target : OutlineTarget ,
@@ -53,29 +61,19 @@ export class NotebookCellOutlineProvider {
53
61
@IConfigurationService private readonly _configurationService : IConfigurationService ,
54
62
) {
55
63
this . _outlineEntryFactory = new NotebookOutlineEntryFactory ( notebookExecutionStateService ) ;
56
- const delayerRecomputeActive = this . _disposables . add ( new Delayer ( 10 ) ) ;
57
- this . delayRecomputeActive = ( ) => delayerRecomputeActive . trigger ( ( ) => this . _recomputeActive ( ) ) ;
58
-
59
- this . _disposables . add ( Event . debounce < void , void > (
60
- _editor . onDidChangeSelection ,
61
- ( last , _current ) => last ,
62
- 200
63
- ) ( ( ) => {
64
- this . delayRecomputeActive ( ) ;
64
+
65
+ const delayerRecomputeActive = this . _disposables . add ( new Delayer ( 200 ) ) ;
66
+ this . _disposables . add ( _editor . onDidChangeSelection ( ( ) => {
67
+ delayerRecomputeActive . trigger ( ( ) => this . _recomputeActive ( ) ) ;
65
68
} , this ) )
66
- this . _disposables . add ( Event . debounce < INotebookViewCellsUpdateEvent , INotebookViewCellsUpdateEvent > (
67
- _editor . onDidChangeViewCells ,
68
- ( last , _current ) => last ?? _current ,
69
- 200
70
- ) ( ( ) => {
71
- this . delayRecomputeActive ( ) ;
72
- } , this )
73
- ) ;
74
69
75
70
// .3s of a delay is sufficient, 100-200s is too quick and will unnecessarily block the ui thread.
76
71
// Given we're only updating the outline when the user types, we can afford to wait a bit.
77
- const delayer = this . _disposables . add ( new Delayer < void > ( 300 ) ) ;
78
- const delayedRecompute = ( ) => delayer . trigger ( ( ) => this . _recomputeState ( ) ) ;
72
+ this . delayedOutlineRecompute = this . _disposables . add ( new Delayer < void > ( 300 ) ) ;
73
+ const delayedRecompute = ( ) => {
74
+ delayerRecomputeActive . cancel ( ) ; // Active is always recomputed after a recomputing the outline state.
75
+ this . delayedOutlineRecompute . trigger ( ( ) => this . _recomputeState ( ) ) ;
76
+ } ;
79
77
80
78
this . _disposables . add ( _configurationService . onDidChangeConfiguration ( e => {
81
79
if ( e . affectsConfiguration ( NotebookSetting . outlineShowMarkdownHeadersOnly ) ||
@@ -106,7 +104,10 @@ export class NotebookCellOutlineProvider {
106
104
return ;
107
105
}
108
106
disposable . add ( this . _editor . textModel . onDidChangeContent ( contentChanges => {
109
- if ( contentChanges . rawEvents . some ( c => c . kind === NotebookCellsChangeType . ChangeCellContent ) ) {
107
+ if ( contentChanges . rawEvents . some ( c => c . kind === NotebookCellsChangeType . ChangeCellContent ||
108
+ c . kind === NotebookCellsChangeType . ChangeCellInternalMetadata ||
109
+ c . kind === NotebookCellsChangeType . Move ||
110
+ c . kind === NotebookCellsChangeType . ModelChange ) ) {
110
111
delayedRecompute ( ) ;
111
112
}
112
113
} ) ) ;
@@ -259,7 +260,7 @@ export class NotebookCellOutlineProvider {
259
260
}
260
261
} ) ) ;
261
262
262
- this . delayRecomputeActive ( ) ;
263
+ this . _recomputeActive ( ) ;
263
264
}
264
265
265
266
private _recomputeActive ( ) : { changeEventTriggered : boolean } {
0 commit comments