Release (#256)
* 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:
committed by
GitHub
parent
138b96baea
commit
f906af0c3a
@@ -74,14 +74,10 @@ M.pick_target = function(mr)
|
||||
return
|
||||
end
|
||||
|
||||
local all_branch_names = u.get_all_git_branches(true)
|
||||
vim.ui.select(all_branch_names, {
|
||||
prompt = "Choose target branch for merge",
|
||||
}, function(choice)
|
||||
if choice then
|
||||
mr.target = choice
|
||||
M.pick_template(mr)
|
||||
end
|
||||
-- Select target branch interactively if it hasn't been selected by other means
|
||||
u.select_target_branch(function(target)
|
||||
mr.target = target
|
||||
M.pick_template(mr)
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -177,6 +173,14 @@ M.open_confirmation_popup = function(mr)
|
||||
|
||||
local layout, title_popup, description_popup, target_popup, delete_branch_popup, squash_popup = M.create_layout()
|
||||
|
||||
local popups = {
|
||||
title_popup,
|
||||
description_popup,
|
||||
delete_branch_popup,
|
||||
squash_popup,
|
||||
target_popup,
|
||||
}
|
||||
|
||||
M.layout = layout
|
||||
M.layout_buf = layout.bufnr
|
||||
M.layout_visible = true
|
||||
@@ -209,6 +213,10 @@ M.open_confirmation_popup = function(mr)
|
||||
vim.api.nvim_buf_set_lines(M.delete_branch_bufnr, 0, -1, false, { u.bool_to_string(delete_branch) })
|
||||
vim.api.nvim_buf_set_lines(M.squash_bufnr, 0, -1, false, { u.bool_to_string(squash) })
|
||||
|
||||
u.switch_can_edit_buf(M.delete_branch_bufnr, false)
|
||||
u.switch_can_edit_buf(M.squash_bufnr, false)
|
||||
u.switch_can_edit_buf(M.target_bufnr, false)
|
||||
|
||||
local popup_opts = {
|
||||
cb = exit,
|
||||
action_before_close = true,
|
||||
@@ -217,9 +225,10 @@ M.open_confirmation_popup = function(mr)
|
||||
|
||||
state.set_popup_keymaps(description_popup, M.create_mr, miscellaneous.attach_file, popup_opts)
|
||||
state.set_popup_keymaps(title_popup, M.create_mr, nil, popup_opts)
|
||||
state.set_popup_keymaps(target_popup, M.create_mr, nil, popup_opts)
|
||||
state.set_popup_keymaps(delete_branch_popup, M.create_mr, nil, popup_opts)
|
||||
state.set_popup_keymaps(squash_popup, M.create_mr, nil, popup_opts)
|
||||
state.set_popup_keymaps(target_popup, M.create_mr, M.select_new_target, popup_opts)
|
||||
state.set_popup_keymaps(delete_branch_popup, M.create_mr, miscellaneous.toggle_bool, popup_opts)
|
||||
state.set_popup_keymaps(squash_popup, M.create_mr, miscellaneous.toggle_bool, popup_opts)
|
||||
miscellaneous.set_cycle_popups_keymaps(popups)
|
||||
|
||||
vim.api.nvim_set_current_buf(M.description_bufnr)
|
||||
end)
|
||||
@@ -237,6 +246,18 @@ M.build_description_lines = function(template_content)
|
||||
return description_lines
|
||||
end
|
||||
|
||||
---Prompts for interactive selection of a new target among remote-tracking branches
|
||||
M.select_new_target = function()
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
u.select_target_branch(function(target)
|
||||
vim.schedule(function()
|
||||
u.switch_can_edit_buf(bufnr, true)
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { target })
|
||||
u.switch_can_edit_buf(bufnr, false)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
---This function will POST the new MR to create it
|
||||
M.create_mr = function()
|
||||
local description = u.get_buffer_text(M.description_bufnr)
|
||||
|
||||
@@ -432,7 +432,12 @@ M.jump_to_reviewer = function(tree)
|
||||
u.notify("Could not get discussion node", vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
reviewer.jump(root_node.file_name, get_new_line(root_node), get_old_line(root_node))
|
||||
local line_number = (root_node.new_line or root_node.old_line or 1)
|
||||
if root_node.range then
|
||||
local start_old_line, start_new_line = common.parse_line_code(root_node.range.start.line_code)
|
||||
line_number = root_node.old_line and start_old_line or start_new_line
|
||||
end
|
||||
reviewer.jump(root_node.file_name, line_number, root_node.old_line == nil)
|
||||
M.refresh_view()
|
||||
end
|
||||
|
||||
@@ -973,20 +978,18 @@ end
|
||||
---@param tree NuiTree
|
||||
M.open_in_browser = function(tree)
|
||||
local url = M.get_url(tree)
|
||||
if url == nil then
|
||||
return
|
||||
if url ~= nil then
|
||||
u.open_in_browser(url)
|
||||
end
|
||||
u.open_in_browser(url)
|
||||
end
|
||||
|
||||
---@param tree NuiTree
|
||||
M.copy_node_url = function(tree)
|
||||
local url = M.get_url(tree)
|
||||
if url == nil then
|
||||
return
|
||||
if url ~= nil then
|
||||
vim.fn.setreg("+", url)
|
||||
u.notify("Copied '" .. url .. "' to clipboard", vim.log.levels.INFO)
|
||||
end
|
||||
u.notify("Copied '" .. url .. "' to clipboard", vim.log.levels.INFO)
|
||||
vim.fn.setreg("+", url)
|
||||
end
|
||||
|
||||
M.add_emoji_to_note = function(tree, unlinked)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -32,6 +32,11 @@ M.summary = function()
|
||||
local info_lines = state.settings.info.enabled and M.build_info_lines() or { "" }
|
||||
|
||||
local layout, title_popup, description_popup, info_popup = M.create_layout(info_lines)
|
||||
local popups = {
|
||||
title_popup,
|
||||
description_popup,
|
||||
info_popup,
|
||||
}
|
||||
|
||||
M.layout = layout
|
||||
M.layout_buf = layout.bufnr
|
||||
@@ -48,12 +53,10 @@ M.summary = function()
|
||||
|
||||
if info_popup then
|
||||
vim.api.nvim_buf_set_lines(info_popup.bufnr, 0, -1, false, info_lines)
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = info_popup.bufnr })
|
||||
vim.api.nvim_set_option_value("readonly", false, { buf = info_popup.bufnr })
|
||||
u.switch_can_edit_buf(info_popup.bufnr, false)
|
||||
M.color_details(info_popup.bufnr) -- Color values in details popup
|
||||
end
|
||||
|
||||
M.color_details(info_popup.bufnr) -- Color values in details popup
|
||||
|
||||
state.set_popup_keymaps(
|
||||
description_popup,
|
||||
M.edit_summary,
|
||||
@@ -61,6 +64,8 @@ M.summary = function()
|
||||
{ cb = exit, action_before_close = true }
|
||||
)
|
||||
state.set_popup_keymaps(title_popup, M.edit_summary, nil, { cb = exit, action_before_close = true })
|
||||
state.set_popup_keymaps(info_popup, M.edit_summary, nil, { cb = exit, action_before_close = true })
|
||||
miscellaneous.set_cycle_popups_keymaps(popups)
|
||||
|
||||
vim.api.nvim_set_current_buf(description_popup.bufnr)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user