@@ -109,8 +109,10 @@ export class CellToolbarTracker implements IDisposable {
109109 this . _settings . changed . disconnect ( this . _onSettingsChanged , this ) ;
110110 }
111111
112- const cells = this . _panel . context . model . cells ;
113- cells . changed . disconnect ( this . updateConnectedCells , this ) ;
112+ const cells = this . _panel ?. context . model . cells ;
113+ if ( cells ) {
114+ cells . changed . disconnect ( this . updateConnectedCells , this ) ;
115+ }
114116 this . _panel = null ;
115117 }
116118
@@ -162,8 +164,8 @@ export class CellToolbarTracker implements IDisposable {
162164 }
163165 }
164166
165- private _getCell ( model : ICellModel ) : Cell {
166- return this . _panel . content . widgets . find ( widget => widget . model === model ) ;
167+ private _getCell ( model : ICellModel ) : Cell | undefined {
168+ return this . _panel ? .content . widgets . find ( widget => widget . model === model ) ;
167169 }
168170
169171 private _findToolbarWidgets ( cell : Cell ) : Widget [ ] {
@@ -185,7 +187,7 @@ export class CellToolbarTracker implements IDisposable {
185187 */
186188 private _onSettingsChanged ( ) : void {
187189 // Update menu items
188- const leftItems = ( this . _settings . composite [ 'leftMenu' ] as any ) as
190+ const leftItems = ( this . _settings ? .composite [ 'leftMenu' ] as any ) as
189191 | ICellMenuItem [ ]
190192 | null ;
191193 // Test to avoid useless signal emission
@@ -199,7 +201,7 @@ export class CellToolbarTracker implements IDisposable {
199201 } else {
200202 this . _leftMenuItems . pushAll ( DEFAULT_LEFT_MENU ) ;
201203 }
202- const rightItems = ( ( this . _settings . composite [ 'rightMenu' ] as any ) ||
204+ const rightItems = ( ( this . _settings ? .composite [ 'rightMenu' ] as any ) ||
203205 [ ] ) as ICellMenuItem [ ] ;
204206 // Test to avoid useless signal emission
205207 if ( this . _rightMenuItems . length > 0 ) {
@@ -211,7 +213,7 @@ export class CellToolbarTracker implements IDisposable {
211213
212214 // Update tags
213215 const newDefaultTags =
214- ( this . _settings . composite [ 'defaultTags' ] as string [ ] ) || [ ] ;
216+ ( this . _settings ? .composite [ 'defaultTags' ] as string [ ] ) || [ ] ;
215217 // Update default tag in shared tag list
216218 const toAdd = newDefaultTags . filter (
217219 tag => ! this . _previousDefaultTags . includes ( tag )
@@ -226,11 +228,13 @@ export class CellToolbarTracker implements IDisposable {
226228
227229 // Update left space
228230 const leftSpace = ( this . _settings ?. composite [ 'leftSpace' ] as number ) || 0 ;
229- this . _panel . node
230- . querySelectorAll ( `div.${ LEFT_SPACER_CLASSNAME } ` )
231- . forEach ( node => {
232- ( node as HTMLElement ) . style . width = `${ leftSpace } px` ;
233- } ) ;
231+ if ( this . _panel ) {
232+ this . _panel . node
233+ . querySelectorAll ( `div.${ LEFT_SPACER_CLASSNAME } ` )
234+ . forEach ( node => {
235+ ( node as HTMLElement ) . style . width = `${ leftSpace } px` ;
236+ } ) ;
237+ }
234238 }
235239
236240 private _allTags : ObservableList < string > = new ObservableList < string > ( ) ;
@@ -240,7 +244,7 @@ export class CellToolbarTracker implements IDisposable {
240244 ICellMenuItem
241245 > ( ) ;
242246 private _previousDefaultTags = new Array < string > ( ) ;
243- private _panel : NotebookPanel ;
247+ private _panel : NotebookPanel | null ;
244248 private _rightMenuItems : ObservableList < ICellMenuItem > = new ObservableList <
245249 ICellMenuItem
246250 > ( ) ;
0 commit comments