@@ -32,13 +32,13 @@ local View = Class:extend()
32
32
function View :new (args )
33
33
args .explorer :log_new (" View" )
34
34
35
- self .explorer = args .explorer
36
- self .adaptive_size = false
37
- self .side = (self .explorer .opts .view .side == " right" ) and " right" or " left"
38
- self .live_filter = { prev_focused_node = nil , }
39
- self .bufnr_by_tabid = {}
35
+ self .explorer = args .explorer
36
+ self .adaptive_size = false
37
+ self .side = (self .explorer .opts .view .side == " right" ) and " right" or " left"
38
+ self .live_filter = { prev_focused_node = nil , }
39
+ self .bufnr_by_tabid = {}
40
40
41
- self .winopts = {
41
+ self .winopts = {
42
42
relativenumber = self .explorer .opts .view .relativenumber ,
43
43
number = self .explorer .opts .view .number ,
44
44
list = false ,
@@ -246,10 +246,13 @@ end
246
246
--- @private
247
247
--- @param tabid integer
248
248
function View :close_internal (tabid )
249
+ --- BEGIN multi-instance FF
249
250
if self .explorer .opts .experimental .multi_instance then
250
251
log .line (" dev" , " View:close_internal(t%s)" , tabid )
251
252
end
252
- if not self :is_visible ({ tabpage = tabid }) then
253
+ --- END multi-instance FF
254
+
255
+ if not self :is_visible ({ tabpage = tabid }, " View:close_internal" ) then
253
256
return
254
257
end
255
258
self :save_tab_state (tabid )
@@ -263,9 +266,12 @@ function View:close_internal(tabid)
263
266
vim .api .nvim_set_current_win (vim .fn .win_getid (prev_win ))
264
267
end
265
268
if vim .api .nvim_win_is_valid (tree_win or 0 ) then
269
+ --- BEGIN multi-instance FF
266
270
if self .explorer .opts .experimental .multi_instance then
267
271
log .line (" dev" , " View:close_internal(t%s) w%s" , tabid , tree_win )
268
272
end
273
+ --- END multi-instance FF
274
+ ---
269
275
local success , error = pcall (vim .api .nvim_win_close , tree_win or 0 , true )
270
276
if not success then
271
277
notify .debug (" Failed to close window: " .. error )
@@ -278,29 +284,37 @@ function View:close_internal(tabid)
278
284
end
279
285
280
286
function View :close_this_tab_only ()
287
+ --- BEGIN multi-instance FF
281
288
if self .explorer .opts .experimental .multi_instance then
282
289
log .line (" dev" , " View:close_this_tab_only()" )
283
290
end
291
+ --- END multi-instance FF
292
+
284
293
self :close_internal (vim .api .nvim_get_current_tabpage ())
285
294
end
286
295
287
296
-- TODO this is broken at 1.13.0 - current tab does not close when tab.sync.close is set
288
297
function View :close_all_tabs ()
289
298
log .line (" dev" , " View:close_all_tabs() globals.WINID_BY_TABID=%s" , vim .inspect (globals .WINID_BY_TABID ))
290
299
for tabid , _ in pairs (globals .WINID_BY_TABID ) do
300
+ --- BEGIN multi-instance FF
291
301
if self .explorer .opts .experimental .multi_instance then
292
302
log .line (" dev" , " View:close_all_tabs()" )
293
303
end
304
+ --- END multi-instance FF
305
+
294
306
self :close_internal (tabid )
295
307
end
296
308
end
297
309
298
310
--- @param tabid integer | nil
299
311
--- @param callsite string
300
312
function View :close (tabid , callsite )
313
+ --- BEGIN multi-instance FF
301
314
if self .explorer .opts .experimental .multi_instance then
302
315
log .line (" dev" , " View:close(t%s, %s)" , tabid , callsite )
303
316
end
317
+ --- END multi-instance FF
304
318
305
319
if self .explorer .opts .tab .sync .close then
306
320
self :close_all_tabs ()
313
327
314
328
--- @param options table | nil
315
329
function View :open (options )
316
- if self :is_visible () then
330
+ if self :is_visible (nil , " View:open " ) then
317
331
return
318
332
end
319
333
@@ -405,7 +419,7 @@ function View:resize(size)
405
419
self .width = size
406
420
end
407
421
408
- if not self :is_visible () then
422
+ if not self :is_visible (nil , " View:resize " ) then
409
423
return
410
424
end
411
425
463
477
function View :abandon_current_window ()
464
478
local tab = vim .api .nvim_get_current_tabpage ()
465
479
480
+ --- BEGIN multi-instance FF
466
481
if self .explorer .opts .experimental .multi_instance then
467
482
log .line (" dev" , " View:abandon_current_window() t%d w%s b%s member b%s %s" ,
468
483
tab ,
@@ -471,8 +486,7 @@ function View:abandon_current_window()
471
486
self .bufnr_by_tabid [tab ],
472
487
(globals .BUFNR_BY_TABID [tab ] == self .bufnr_by_tabid [tab ]) and " " or " MISMATCH" )
473
488
end
474
-
475
- -- TODO multi-instance maybe kill the buffer instead of retaining
489
+ --- END multi-instance FF
476
490
477
491
-- reset both bufnr registries
478
492
globals .BUFNR_BY_TABID [tab ] = nil
@@ -482,18 +496,42 @@ function View:abandon_current_window()
482
496
end
483
497
484
498
function View :abandon_all_windows ()
485
- -- TODO multi-instance kill the buffer instead of retaining
486
499
for tab , _ in pairs (vim .api .nvim_list_tabpages ()) do
487
500
globals .BUFNR_BY_TABID [tab ] = nil
488
501
globals .WINID_BY_TABID [tab ] = nil
489
502
end
490
503
end
491
504
492
505
--- @param opts table | nil
506
+ --- @param callsite string
493
507
--- @return boolean
494
- function View :is_visible (opts )
495
- -- TODO multi-instance rewrite and consistency check
508
+ function View :is_visible (opts , callsite )
509
+ local msg
510
+
511
+ --- BEGIN multi-instance FF
512
+ if self .explorer .opts .experimental .multi_instance then
513
+ msg = string.format (" View:is_visible(%s, %-20.20s)" , vim .inspect (opts , { newline = " " }), callsite )
514
+ end
515
+ --- END multi-instance FF
516
+
496
517
if opts and opts .tabpage then
518
+ --- BEGIN multi-instance FF
519
+ if self .explorer .opts .experimental .multi_instance then
520
+ local winid = self :winid (opts .tabpage )
521
+ local winid_by_tabid = opts .tabpage and globals .WINID_BY_TABID [opts .tabpage ] or nil
522
+ msg = string.format (" %s globals.WINID_BY_TABID[%s]=w%s view.winid(%s)=w%s" ,
523
+ msg ,
524
+ opts .tabpage , winid_by_tabid ,
525
+ opts .tabpage , winid
526
+ )
527
+ if winid ~= winid_by_tabid then
528
+ msg = string.format (" %s MISMATCH" , msg )
529
+ notify .error (msg )
530
+ end
531
+ log .line (" dev" , " %s" , msg )
532
+ end
533
+ --- END multi-instance FF
534
+
497
535
if not globals .WINID_BY_TABID [opts .tabpage ] then
498
536
return false
499
537
end
@@ -502,8 +540,24 @@ function View:is_visible(opts)
502
540
end
503
541
504
542
if opts and opts .any_tabpage then
505
- for _ , winid in pairs (globals .WINID_BY_TABID ) do
506
- if winid and vim .api .nvim_win_is_valid (winid ) then
543
+ for tabid , winid_by_tabid in pairs (globals .WINID_BY_TABID ) do
544
+ --- BEGIN multi-instance FF
545
+ if self .explorer .opts .experimental .multi_instance then
546
+ local winid = self :winid (tabid )
547
+ msg = string.format (" %s globals.WINID_BY_TABID[%s]=w%s view.winid(%s)=w%s" ,
548
+ msg ,
549
+ tabid , winid_by_tabid ,
550
+ tabid , winid
551
+ )
552
+ if winid ~= winid_by_tabid then
553
+ msg = string.format (" %s MISMATCH" , msg )
554
+ notify .error (msg )
555
+ end
556
+ log .line (" dev" , " %s" , msg )
557
+ end
558
+ --- END multi-instance FF
559
+
560
+ if winid_by_tabid and vim .api .nvim_win_is_valid (winid_by_tabid ) then
507
561
return true
508
562
end
509
563
end
516
570
517
571
--- @param opts table | nil
518
572
function View :set_cursor (opts )
519
- if self :is_visible () then
573
+ if self :is_visible (nil , " View:set_cursor " ) then
520
574
pcall (vim .api .nvim_win_set_cursor , self :get_winid (nil , " View:set_cursor" ), opts )
521
575
end
522
576
end
@@ -530,7 +584,7 @@ function View:focus(winid, open_if_closed)
530
584
self :close (nil , " View:focus" )
531
585
self :open ()
532
586
wid = self :get_winid (nil , " View:focus2" )
533
- elseif open_if_closed and not self :is_visible () then
587
+ elseif open_if_closed and not self :is_visible (nil , " View:focus " ) then
534
588
self :open ()
535
589
end
536
590
@@ -547,7 +601,7 @@ function View:api_winid(opts)
547
601
if tabpage == 0 then
548
602
tabpage = vim .api .nvim_get_current_tabpage ()
549
603
end
550
- if self :is_visible ({ tabpage = tabpage }) then
604
+ if self :is_visible ({ tabpage = tabpage }, " View:api_winid " ) then
551
605
return self :get_winid (tabpage , " View:winid" )
552
606
else
553
607
return nil
@@ -559,8 +613,6 @@ function View:restore_tab_state()
559
613
self :set_cursor (globals .CURSORS [vim .api .nvim_get_current_tabpage ()])
560
614
end
561
615
562
- --- TODO multi-instance remove comment
563
- --- not legacy codepath
564
616
--- winid containing the buffer
565
617
--- @param tabid number | nil (optional ) the number of the chosen tabpage. Defaults to current tabpage.
566
618
--- @return integer ? winid
@@ -583,42 +635,44 @@ end
583
635
function View :get_winid (tabid , callsite )
584
636
local tabid_param = tabid
585
637
tabid = tabid or vim .api .nvim_get_current_tabpage ()
586
- local tabinfo_winid = nil
638
+ local global_winid = nil
587
639
640
+ --- BEGIN multi-instance FF
588
641
if self .explorer .opts .experimental .multi_instance then
589
642
local msg_fault = " "
590
643
if not globals .WINID_BY_TABID [tabid ] then
591
644
msg_fault = " no WINID_BY_TABID"
592
645
elseif not vim .api .nvim_win_is_valid (globals .WINID_BY_TABID [tabid ]) then
593
646
msg_fault = string.format (" invalid globals.WINID_BY_TABID[tabid] %d" , globals .WINID_BY_TABID [tabid ])
594
647
else
595
- tabinfo_winid = globals .WINID_BY_TABID [tabid ]
648
+ global_winid = globals .WINID_BY_TABID [tabid ]
596
649
end
597
650
598
651
local winid = self :winid (tabid )
599
652
600
- if winid ~= tabinfo_winid then
653
+ if winid ~= global_winid then
601
654
msg_fault = " MISMATCH"
602
655
end
603
656
604
- local msg = string.format (" View:get_winid(%3s, %-20.20s) globals.TABPAGES [%s]=w%s view.winid(%s)=w%s %s" ,
657
+ local msg = string.format (" View:get_winid(%3s, %-20.20s) globals.WINID_BY_TABID [%s]=w%s view.winid(%s)=w%s %s" ,
605
658
tabid_param ,
606
659
callsite ,
607
- tabid , tabinfo_winid ,
660
+ tabid , global_winid ,
608
661
tabid , winid ,
609
662
msg_fault
610
663
)
611
664
612
665
log .line (" dev" , " %s" , msg )
613
666
614
- if winid ~= tabinfo_winid then
667
+ if winid ~= global_winid then
615
668
notify .error (msg )
616
669
end
617
670
end
671
+ --- END multi-instance FF
618
672
619
673
-- legacy codepath
620
- if tabinfo_winid and vim .api .nvim_win_is_valid (tabinfo_winid ) then
621
- return tabinfo_winid
674
+ if global_winid and vim .api .nvim_win_is_valid (global_winid ) then
675
+ return global_winid
622
676
end
623
677
end
624
678
627
681
--- @return number
628
682
function View :get_bufnr (callsite )
629
683
local tab = vim .api .nvim_get_current_tabpage ()
684
+
685
+ --- BEGIN multi-instance FF
630
686
if self .explorer .opts .experimental .multi_instance then
631
687
local msg = string.format (" View:get_bufnr(%-20.20s) globals.BUFNR_BY_TABID[%s]=b%s view.bufnr_by_tab[%s]=b%s %s" ,
632
688
callsite ,
@@ -641,6 +697,8 @@ function View:get_bufnr(callsite)
641
697
642
698
log .line (" dev" , msg )
643
699
end
700
+ --- END multi-instance FF
701
+
644
702
return globals .BUFNR_BY_TABID [tab ]
645
703
end
646
704
@@ -657,7 +715,6 @@ function View:prevent_buffer_override()
657
715
local curbuf = vim .api .nvim_win_get_buf (curwin )
658
716
local bufname = vim .api .nvim_buf_get_name (curbuf )
659
717
660
- --- TODO multi-instance this can be removed as winid() will handle it
661
718
if not bufname :match (" NvimTree" ) then
662
719
for i , winid in ipairs (globals .WINID_BY_TABID ) do
663
720
if winid == view_winid then
0 commit comments