Skip to content

Commit

Permalink
feat(commands): added require("edgy").toggle()
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 9, 2023
1 parent 1fc4519 commit 280cf44
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ in your layout.
in the given position or in all edgebars using an optional filter
- `require("edgy").close(pos?)` close all edgebars or a edgebar in the given position
- `require("edgy").open(pos?)` open all pinned views in the given position
- `require("edgy").toggle(pos?)` toggle all pinned views in the given position
- `require("edgy").goto_main()` move the cursor to the last focused main window
- `require("edgy").get_win(window?)` get the Edgy.Window object for the given window
or the current window
Expand Down
1 change: 1 addition & 0 deletions lua/edgy/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ M.goto_main = Editor.goto_main
M.get_win = Editor.get_win
M.close = Editor.close
M.open = Editor.open
M.toggle = Editor.toggle
M.select = Editor.select

return M
17 changes: 17 additions & 0 deletions lua/edgy/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,21 @@ function M.open(pos)
end
end

---@param pos? Edgy.Pos
function M.toggle(pos)
local has_open = false
for p, edgebar in pairs(Config.layout) do
if p == pos or pos == nil then
if #edgebar.wins > 0 then
has_open = true
end
end
end
if has_open then
M.close(pos)
else
M.open(pos)
end
end

return M

0 comments on commit 280cf44

Please sign in to comment.