@@ -194,8 +194,10 @@ function Sidebar:setup_buffer_autocmd()
194
194
vim .api .nvim_create_autocmd (' CursorMoved' , {
195
195
buffer = 0 ,
196
196
callback = function ()
197
- -- Don't use _goto_location because we don't want to auto-close
198
- self :__goto_location (false )
197
+ if self .provider then
198
+ -- Don't use _goto_location because we don't want to auto-close
199
+ self :__goto_location (false )
200
+ end
199
201
end ,
200
202
})
201
203
end
@@ -363,15 +365,24 @@ function Sidebar:no_providers_ui()
363
365
end
364
366
365
367
--- Currently hovered node in outline
366
- --- @return outline.FlatSymbol
368
+ --- @return outline.FlatSymbol ?
367
369
function Sidebar :_current_node ()
368
370
local current_line = vim .api .nvim_win_get_cursor (self .view .win )[1 ]
369
- return self .flats [current_line ]
371
+ if self .flats then
372
+ return self .flats [current_line ]
373
+ end
370
374
end
371
375
372
376
--- @param change_focus boolean Whether to switch to code window after setting cursor
373
377
function Sidebar :__goto_location (change_focus )
378
+ if not self .provider then
379
+ return
380
+ end
374
381
local node = self :_current_node ()
382
+ if not node then
383
+ return
384
+ end
385
+
375
386
vim .api .nvim_win_set_cursor (self .code .win , { node .line + 1 , node .character })
376
387
377
388
if cfg .o .outline_window .center_on_jump then
@@ -426,20 +437,28 @@ function Sidebar:_move_and_jump(direction)
426
437
end
427
438
428
439
--- @param move_cursor boolean
429
- --- @param node_index integer Index for self.flats
430
- function Sidebar :_toggle_fold (move_cursor , node_index )
431
- local node = self .flats [node_index ] or self :_current_node ()
440
+ function Sidebar :_toggle_fold (move_cursor )
441
+ if not self .provider then
442
+ return
443
+ end
444
+ local node = self :_current_node ()
445
+ if not node then
446
+ return
447
+ end
432
448
local is_folded = folding .is_folded (node )
433
449
434
450
if folding .is_foldable (node ) then
435
- self :_set_folded (not is_folded , move_cursor , node_index )
451
+ self :_set_folded (not is_folded , move_cursor )
436
452
end
437
453
end
438
454
439
455
--- @param folded boolean
440
456
--- @param move_cursor ? boolean
441
457
--- @param node_index ? integer
442
458
function Sidebar :_set_folded (folded , move_cursor , node_index )
459
+ if not self .provider then
460
+ return
461
+ end
443
462
local node = self .flats [node_index ] or self :_current_node ()
444
463
local changed = (folded ~= folding .is_folded (node ))
445
464
462
481
463
482
--- @param nodes outline.Symbol[]
464
483
function Sidebar :_toggle_all_fold (nodes )
484
+ if not self .provider then
485
+ return
486
+ end
465
487
nodes = nodes or self .items
466
488
local folded = true
467
489
478
500
--- @param folded boolean ?
479
501
--- @param nodes ? outline.Symbol[]
480
502
function Sidebar :_set_all_folded (folded , nodes )
503
+ if not self .provider then
504
+ return
505
+ end
481
506
local stack = { nodes or self .items }
482
507
local current = self :_current_node ()
508
+ if not current then
509
+ return
510
+ end
483
511
484
512
while # stack > 0 do
485
513
local current_nodes = table.remove (stack , # stack )
0 commit comments