Skip to content

Commit

Permalink
fix(event): prevent unwanted resize (#255)
Browse files Browse the repository at this point in the history
## 📃 Summary

resize is triggered when there shouldn't be, this pr fixes an unwanted
event trigger
  • Loading branch information
shortcuts authored Nov 10, 2023
1 parent e32701c commit 9ba2907
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
10 changes: 7 additions & 3 deletions lua/no-neck-pain/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ function N.enable(scope)
callback = function(p)
p.event = string.format("%s:splits", p.event)
A.debounce(p.event, function()
if not S.hasTabs(S) or E.skip(S.tabs[S.activeTab]) then
return
if not S.hasTabs(S) or E.skip(S.getTab(S)) then
return D.log(p.event, "skip split logic")
end

if S.checkSides(S, "and", false) then
Expand Down Expand Up @@ -256,7 +256,7 @@ function N.enable(scope)
p.event = string.format("%s:integrations", p.event)
A.debounce(p.event, function()
if not S.hasTabs(S) or not S.isActiveTabRegistered(S) or E.skip(S.getTab(S)) then
return
return D.log(p.event, "skip integrations logic")
end

if S.checkSides(S, "and", false) then
Expand All @@ -267,6 +267,10 @@ function N.enable(scope)
return D.log(p.event, "skip integrations logic: no registered integration")
end

if vim.startswith(p.event, "WinEnter") and #S.getUnregisteredWins(S) == 0 then
return D.log(p.event, "skip integrations logic: no new windows")
end

N.init(p.event, false, true)
end)
end,
Expand Down
6 changes: 6 additions & 0 deletions lua/no-neck-pain/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,19 @@ end

---Closes side integrations if opened.
---
---@return boolean: whether we closed something or not.
---@private
function State:closeIntegration()
local hasClosedIntegration = false

for _, opts in pairs(self.tabs[self.activeTab].wins.integrations) do
if opts.id ~= nil and opts.close ~= nil then
vim.cmd(opts.close)
hasClosedIntegration = true
end
end

return hasClosedIntegration
end

---Reopens the integrations if they were previously closed.
Expand Down
10 changes: 7 additions & 3 deletions lua/no-neck-pain/wins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ function W.createSideBuffers(skipIntegrations)

local closedIntegrations = false
if not skipIntegrations then
closedIntegrations = true
S.closeIntegration(S)
closedIntegrations = S.closeIntegration(S)
end

for _, side in pairs(Co.SIDES) do
Expand Down Expand Up @@ -259,7 +258,12 @@ function W.getPadding(side)
return 0
end

D.log(side, "%d currently with splits - computing integrations width", occupied)
D.log(
side,
"%d currently with %d vsplits - computing integrations width",
occupied,
tab.layers.vsplit
)

-- now we need to determine how much we should substract from the remaining padding
-- if there's side integrations open.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_integrations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ T["nvimdapui"]["keeps sides open"] = function()
child.lua([[require('dapui').open()]])
vim.loop.sleep(50)

eq(helpers.winsInTab(child), {1010, 1009, 1008, 1007, 1001, 1000, 1002, 1006, 1003})
eq(helpers.winsInTab(child), { 1010, 1009, 1008, 1007, 1001, 1000, 1002, 1006, 1003 })

eq_state(child, "tabs[1].wins.main", {
curr = 1000,
Expand Down

0 comments on commit 9ba2907

Please sign in to comment.