@@ -2,6 +2,7 @@ local D = require("no-neck-pain.util.debug")
2
2
local E = require (" no-neck-pain.util.event" )
3
3
local M = require (" no-neck-pain.util.map" )
4
4
local W = require (" no-neck-pain.util.win" )
5
+ local T = require (" no-neck-pain.util.trees" )
5
6
6
7
local N = {}
7
8
@@ -35,7 +36,7 @@ local S = {
35
36
-- Toggle the plugin by calling the `enable`/`disable` methods respectively.
36
37
function N .toggle ()
37
38
if S .enabled then
38
- return N .disable ()
39
+ return N .disable (" N.toggle " )
39
40
end
40
41
41
42
return N .enable ()
@@ -50,7 +51,7 @@ local function init()
50
51
end
51
52
52
53
-- before creating side buffers, we determine if we should consider externals
53
- S .win .external .trees = W .getSideTrees ()
54
+ S .win .external .trees = T .getSideTrees ()
54
55
S .win .main .left , S .win .main .right = W .createSideBuffers (S .win )
55
56
56
57
vim .fn .win_gotoid (S .win .main .curr )
@@ -71,7 +72,7 @@ function N.enable()
71
72
vim .api .nvim_create_autocmd ({ " VimResized" }, {
72
73
callback = function (p )
73
74
vim .schedule (function ()
74
- if E .skip (S .enabled , nil ) then
75
+ if E .skip (S .enabled , S . win . main , nil ) then
75
76
return
76
77
end
77
78
@@ -91,25 +92,26 @@ function N.enable()
91
92
end )
92
93
end ,
93
94
group = " NoNeckPain" ,
94
- desc = " Resizes side windows after shell has been resized" ,
95
+ desc = " Resizes side windows after terminal has been resized, closes them if not enough space left. " ,
95
96
})
96
97
97
98
vim .api .nvim_create_autocmd ({ " WinEnter" }, {
98
99
callback = function (p )
99
100
vim .schedule (function ()
100
- if E .skip (S .enabled , nil ) then
101
+ if E .skip (S .enabled , S . win . main , nil ) then
101
102
return
102
103
end
103
104
104
105
local focusedWin = vim .api .nvim_get_current_win ()
105
106
local buffers , total = W .listWinsExcept (S .win .main )
106
107
107
108
if total == 0 or not M .contains (buffers , focusedWin ) then
108
- return D .log (p .event , " no valid buffers to handle, no split to handle" )
109
+ return D .log (p .event , " valid: %s - or no split to handle" , total )
109
110
end
110
111
112
+ -- we skip side trees etc. as they are not part of the split manager.
111
113
local fileType = vim .api .nvim_buf_get_option (0 , " filetype" )
112
- if fileType == " NvimTree " or fileType == " undotree " then
114
+ if T . isSideTree ( fileType ) then
113
115
return D .log (p .event , " encountered an external window" )
114
116
end
115
117
@@ -152,7 +154,7 @@ function N.enable()
152
154
vim .api .nvim_create_autocmd ({ " QuitPre" , " BufDelete" }, {
153
155
callback = function (p )
154
156
vim .schedule (function ()
155
- if E .skip (S .enabled , nil ) then
157
+ if E .skip (S .enabled , nil , nil ) then
156
158
return
157
159
end
158
160
@@ -184,7 +186,7 @@ function N.enable()
184
186
then
185
187
D .log (p .event , " found last `wipe` buffer in list, disabling..." )
186
188
187
- return N .disable ()
189
+ return N .disable (p . event )
188
190
end
189
191
end
190
192
end )
@@ -196,7 +198,7 @@ function N.enable()
196
198
vim .api .nvim_create_autocmd ({ " WinClosed" , " BufDelete" }, {
197
199
callback = function (p )
198
200
vim .schedule (function ()
199
- if E .skip (S .enabled , nil ) or S .win .main .split == nil then
201
+ if E .skip (S .enabled , S . win . main , nil ) or S .win .main .split == nil then
200
202
return
201
203
end
202
204
@@ -251,17 +253,19 @@ function N.enable()
251
253
vim .api .nvim_create_autocmd ({ " WinEnter" , " WinClosed" }, {
252
254
callback = function (p )
253
255
vim .schedule (function ()
254
- if E .skip (S .enabled , S .win .split ) then
256
+ if E .skip (S .enabled , S .win .main , S . win . main . split ) then
255
257
return
256
258
end
257
259
258
260
local wins = vim .api .nvim_list_wins ()
259
- local trees = W .getSideTrees ()
261
+ local trees = T .getSideTrees ()
260
262
261
263
-- we cycle over supported integrations to see which got closed or opened
262
264
for name , tree in pairs (S .win .external .trees ) do
263
265
-- if there was a tree[name] but not anymore, we resize
264
- if tree .id ~= nil and not M .contains (wins , tree .id ) then
266
+ if tree ~= nil and tree .id ~= nil and not M .contains (wins , tree .id ) then
267
+ D .log (p .event , " %s have been closed, resizing" , name )
268
+
265
269
S .win .external .trees [name ] = {
266
270
id = nil ,
267
271
width = 0 ,
@@ -272,6 +276,8 @@ function N.enable()
272
276
273
277
-- we have a new tree registered, we can resize
274
278
if S .win .external .trees [name ].id == nil and trees [name ].id ~= nil then
279
+ D .log (p .event , " %s have been opened, resizing" , name )
280
+
275
281
S .win .external .trees = trees
276
282
return W .resizeSideBuffers (p .event , S .win )
277
283
end
0 commit comments