@@ -129,7 +129,18 @@ function View:create_buffer(bufnr)
129
129
130
130
local tab = vim .api .nvim_get_current_tabpage ()
131
131
globals .BUFNR_PER_TAB [tab ] = bufnr or vim .api .nvim_create_buf (false , false )
132
- self .bufnr_by_tab [tab ] = globals .BUFNR_PER_TAB [tab ]
132
+
133
+ if self .explorer .opts .experimental .multi_instance then
134
+ local tabid = tab
135
+ self .bufnr_by_tab [tabid ] = globals .BUFNR_PER_TAB [tabid ]
136
+ log .line (" dev" , " buffer channel attaching t%d b%d" , tabid , self .bufnr_by_tab [tabid ])
137
+ vim .api .nvim_buf_attach (self .bufnr_by_tab [tabid ], true , {
138
+ on_detach = function (op , bnr )
139
+ log .line (" dev" , " buffer channel %s t%d b%d" , op , tabid , bnr )
140
+ end ,
141
+ })
142
+ end
143
+
133
144
vim .api .nvim_buf_set_name (self :get_bufnr (" View:create_buffer1" ), " NvimTree_" .. tab )
134
145
135
146
bufnr = self :get_bufnr (" View:create_buffer2" )
@@ -447,6 +458,7 @@ function View:reposition_window()
447
458
end
448
459
449
460
--- @private
461
+ --- @param callsite string
450
462
function View :set_current_win (callsite )
451
463
local current_tab = vim .api .nvim_get_current_tabpage ()
452
464
local current_win = vim .api .nvim_get_current_win ()
@@ -483,19 +495,44 @@ function View:open_in_win(opts)
483
495
events ._dispatch_on_tree_open ()
484
496
end
485
497
486
- function View :abandon_current_window ()
498
+ --- @param callsite string
499
+ function View :abandon_current_window (callsite )
487
500
local tab = vim .api .nvim_get_current_tabpage ()
501
+
502
+ if self .explorer .opts .experimental .multi_instance then
503
+ log .line (" dev" , " View:abandon_current_window(%-20.20s) t%d w%s b%s member b%s %s" ,
504
+ callsite ,
505
+ tab ,
506
+ globals .TABPAGES and globals .TABPAGES .winnr or nil ,
507
+ globals .BUFNR_PER_TAB [tab ],
508
+ self .bufnr_by_tab [tab ],
509
+ (globals .BUFNR_PER_TAB [tab ] == self .bufnr_by_tab [tab ]) and " " or " MISMATCH" )
510
+ end
511
+
512
+ -- TODO multi-instance kill the buffer instead of retaining
513
+
488
514
globals .BUFNR_PER_TAB [tab ] = nil
489
- self .bufnr_by_tab [tab ] = nil
490
515
if globals .TABPAGES [tab ] then
491
516
globals .TABPAGES [tab ].winnr = nil
492
517
end
493
518
end
494
519
495
- function View :abandon_all_windows ()
520
+ --- @param callsite string
521
+ function View :abandon_all_windows (callsite )
496
522
for tab , _ in pairs (vim .api .nvim_list_tabpages ()) do
523
+ if self .explorer .opts .experimental .multi_instance then
524
+ log .line (" dev" , " View:abandon_all_windows(%-20.20s) t%d w%s b%s member b%s %s" ,
525
+ callsite ,
526
+ tab ,
527
+ globals .TABPAGES and globals .TABPAGES .winnr or nil ,
528
+ globals .BUFNR_PER_TAB [tab ],
529
+ self .bufnr_by_tab [tab ],
530
+ (globals .BUFNR_PER_TAB [tab ] == self .bufnr_by_tab [tab ]) and " " or " MISMATCH" )
531
+ end
532
+
533
+ -- TODO multi-instance kill the buffer instead of retaining
534
+
497
535
globals .BUFNR_PER_TAB [tab ] = nil
498
- self .bufnr_by_tab [tab ] = nil
499
536
if globals .TABPAGES [tab ] then
500
537
globals .TABPAGES [tab ].winnr = nil
501
538
end
573
610
574
611
--- Returns the window number for nvim-tree within the tabpage specified
575
612
--- @param tabpage number | nil (optional ) the number of the chosen tabpage. Defaults to current tabpage.
576
- --- @param callsite string for logging purposes
613
+ --- @param callsite string
577
614
--- @return number | nil
578
615
function View :get_winnr (tabpage , callsite )
579
616
if self .explorer .opts .experimental .multi_instance then
@@ -605,7 +642,11 @@ function View:get_winnr(tabpage, callsite)
605
642
end
606
643
607
644
if ret ~= winid_from_bufnr then
608
- msg = string.format (" %s winid_from_bufnr w%s MISMATCH" , msg , winid_from_bufnr )
645
+ if ret then
646
+ msg = string.format (" %s winid_from_bufnr w%s MISMATCH" , msg , winid_from_bufnr )
647
+ else
648
+ msg = string.format (" %s winid_from_bufnr w%s STALE" , msg , winid_from_bufnr )
649
+ end
609
650
end
610
651
611
652
log .line (" dev" , " %s" , msg )
0 commit comments