Skip to content

Commit

Permalink
feat(integrations): skip redraw on every calls
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Mar 18, 2024
1 parent 8befa8f commit e1399af
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: JohnnyMorganz/stylua-action@v2
- uses: JohnnyMorganz/stylua-action@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: latest
Expand Down
27 changes: 26 additions & 1 deletion lua/no-neck-pain/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,36 @@ end
---@return boolean: whether we closed something or not.
---@private
function State:closeIntegration()
local wins = vim.api.nvim_list_wins()
local hasClosedIntegration = false

for _, opts in pairs(self.tabs[self.activeTab].wins.integrations) do
for name, opts in pairs(self.tabs[self.activeTab].wins.integrations) do
if opts.id ~= nil and opts.close ~= nil then
-- if this integration doesn't belong to any side we don't have to
-- close it to redraw side buffers
local side = _G.NoNeckPain.config.integrations[name].position
if side ~= "left" and side ~= "right" then
goto continue
end

-- first element in the current wins list means it's the far left one,
-- if the integration is already at this spot then we don't have to close anything
if side == "left" and wins[1] == self.tabs[self.activeTab].wins.main[side] then
goto continue
end

-- last element in the current wins list means it's the far right one,
-- if the integration is already at this spot then we don't have to close anything
if side == "right" and wins[#wins] == self.tabs[self.activeTab].wins.main[side] then
goto continue
end

D.log(string.format("closeIntegration:%s", name), "integration was opened")

vim.cmd(opts.close)
hasClosedIntegration = true
end
::continue::
end

return hasClosedIntegration
Expand All @@ -89,6 +112,8 @@ function State:reopenIntegration()
and opts.open ~= nil
and _G.NoNeckPain.config.integrations[name].reopen == true
then
D.log(string.format("reopenIntegration:%s", name), "integration was closed previously")

vim.cmd(opts.open)
end
end
Expand Down
6 changes: 2 additions & 4 deletions tests/test_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ T["commands"]["NoNeckPainWidthUp increases the width by 5"] = function()
Helpers.expect.global(child, "_G.NoNeckPain.config.width", 150)
end

T["commands"]["NoNeckPainWidthUp increases the width by N when mappings.widthUp is configured"] = function(
)
T["commands"]["NoNeckPainWidthUp increases the width by N when mappings.widthUp is configured"] = function()
child.lua([[require('no-neck-pain').setup({
mappings = {
widthUp = {mapping = "<Leader>k-", value = 12},
Expand Down Expand Up @@ -127,8 +126,7 @@ T["commands"]["NoNeckPainWidthUp decreases the width by 5"] = function()
Helpers.expect.global(child, "_G.NoNeckPain.config.width", 50)
end

T["commands"]["NoNeckPainWidthUp decreases the width by N when mappings.widthDown is configured"] = function(
)
T["commands"]["NoNeckPainWidthUp decreases the width by N when mappings.widthDown is configured"] = function()
child.lua([[require('no-neck-pain').setup({
mappings = {
widthDown = {mapping = "<Leader>k-", value = 8},
Expand Down

0 comments on commit e1399af

Please sign in to comment.