* fix: Jumping to wrong buffer (#261)
* fix: Go to last line and show warning when diagnostic is past the end of buffer (#262)
* fix: Get recent pipeline through other means (#266)
* feat: Add keymaps and linewise actions to layouts (#265)

This is a #MINOR release, because we are introducing new keybindings for the comment/note popups.

---------

Co-authored-by: Jakub F. Bortlík <jakub.bortlik@proton.me>
Co-authored-by: sunfuze <sunfuze.1989@gmail.com>
This commit is contained in:
Harrison (Harry) Cramer
2024-04-15 09:56:21 -04:00
committed by GitHub
parent 138b96baea
commit f906af0c3a
20 changed files with 358 additions and 103 deletions

View File

@@ -38,4 +38,58 @@ M.editable_popup_opts = {
save_to_temp_register = true,
}
-- Get the index of the next popup when cycling forward
local function next_index(i, n, count)
count = count > 0 and count or 1
for _ = 1, count do
if i < n then
i = i + 1
elseif i == n then
i = 1
end
end
return i
end
---Get the index of the previous popup when cycling backward
---@param i integer The current index
---@param n integer The total number of popups
---@param count integer The count used with the keymap (replaced with 1 if no count was given)
local function prev_index(i, n, count)
count = count > 0 and count or 1
for _ = 1, count do
if i > 1 then
i = i - 1
elseif i == 1 then
i = n
end
end
return i
end
---Setup keymaps for cycling popups. The keymap accepts count.
---@param popups table Table of Popups
M.set_cycle_popups_keymaps = function(popups)
local number_of_popups = #popups
for i, popup in ipairs(popups) do
popup:map("n", state.settings.popup.keymaps.next_field, function()
vim.api.nvim_set_current_win(popups[next_index(i, number_of_popups, vim.v.count)].winid)
end, { desc = "Go to next field (accepts count)" })
popup:map("n", state.settings.popup.keymaps.prev_field, function()
vim.api.nvim_set_current_win(popups[prev_index(i, number_of_popups, vim.v.count)].winid)
end, { desc = "Go to previous field (accepts count)" })
end
end
---Toggle the value in a "Boolean buffer"
M.toggle_bool = function()
local bufnr = vim.api.nvim_get_current_buf()
local current_val = u.get_buffer_text(bufnr)
vim.schedule(function()
u.switch_can_edit_buf(bufnr, true)
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { u.toggle_string_bool(current_val) })
u.switch_can_edit_buf(bufnr, false)
end)
end
return M