From 816b87cf917c2e6775eed709ba900448aad22cf3 Mon Sep 17 00:00:00 2001 From: "Harrison (Harry) Cramer" <32515581+harrisoncramer@users.noreply.github.com> Date: Sun, 5 May 2024 11:12:39 -0400 Subject: [PATCH] Small bug fixes (#298) fix: List remote branches for merge targets (#293) fix: consider remote branches (#297) fix: Save popup contents to temp_registers (#294) This is a #PATCH release. --- lua/gitlab/actions/comment.lua | 13 ++++--------- lua/gitlab/actions/common.lua | 2 +- lua/gitlab/actions/miscellaneous.lua | 8 ++++++++ lua/gitlab/actions/summary.lua | 2 +- lua/gitlab/git.lua | 10 +++++++--- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/lua/gitlab/actions/comment.lua b/lua/gitlab/actions/comment.lua index 4620b9d..b4c9aa1 100644 --- a/lua/gitlab/actions/comment.lua +++ b/lua/gitlab/actions/comment.lua @@ -188,28 +188,23 @@ M.create_comment_layout = function(opts) }, }, internal_layout) - local popup_opts = { - action_before_close = true, - action_before_exit = false, - } - miscellaneous.set_cycle_popups_keymaps({ M.comment_popup, M.draft_popup }) local range = opts.ranged and { start_line = M.start_line, end_line = M.end_line } or nil local unlinked = opts.unlinked or false - ---Keybinding for focus on text section + ---Keybinding for focus on draft section state.set_popup_keymaps(M.draft_popup, function() local text = u.get_buffer_text(M.comment_popup.bufnr) confirm_create_comment(text, range, unlinked, opts.discussion_id) vim.api.nvim_set_current_win(M.current_win) - end, miscellaneous.toggle_bool, popup_opts) + end, miscellaneous.toggle_bool, miscellaneous.non_editable_popup_opts) - ---Keybinding for focus on draft section + ---Keybinding for focus on text section state.set_popup_keymaps(M.comment_popup, function(text) confirm_create_comment(text, range, unlinked, opts.discussion_id) vim.api.nvim_set_current_win(M.current_win) - end, miscellaneous.attach_file, popup_opts) + end, miscellaneous.attach_file, miscellaneous.editable_popup_opts) vim.schedule(function() local draft_mode = state.settings.discussion_tree.draft_mode diff --git a/lua/gitlab/actions/common.lua b/lua/gitlab/actions/common.lua index 1210e1c..8d8c640 100644 --- a/lua/gitlab/actions/common.lua +++ b/lua/gitlab/actions/common.lua @@ -113,7 +113,7 @@ end ---@param tree NuiTree M.copy_node_url = function(tree) local url = M.get_url(tree) - if url == nil then + if url ~= nil then vim.fn.setreg("+", url) u.notify("Copied '" .. url .. "' to clipboard", vim.log.levels.INFO) end diff --git a/lua/gitlab/actions/miscellaneous.lua b/lua/gitlab/actions/miscellaneous.lua index 868b4be..5cf4273 100644 --- a/lua/gitlab/actions/miscellaneous.lua +++ b/lua/gitlab/actions/miscellaneous.lua @@ -35,9 +35,17 @@ M.attach_file = function() end M.editable_popup_opts = { + action_before_close = true, + action_before_exit = false, save_to_temp_register = true, } +M.non_editable_popup_opts = { + action_before_close = true, + action_before_exit = false, + save_to_temp_register = false, +} + -- Get the index of the next popup when cycling forward local function next_index(i, n, count) count = count > 0 and count or 1 diff --git a/lua/gitlab/actions/summary.lua b/lua/gitlab/actions/summary.lua index 1bcedc5..1876109 100644 --- a/lua/gitlab/actions/summary.lua +++ b/lua/gitlab/actions/summary.lua @@ -63,7 +63,7 @@ M.summary = function() description_popup, M.edit_summary, miscellaneous.attach_file, - { cb = exit, action_before_close = true } + { cb = exit, action_before_close = true, save_to_temp_register = 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 }) diff --git a/lua/gitlab/git.lua b/lua/gitlab/git.lua index 503564e..debe831 100644 --- a/lua/gitlab/git.lua +++ b/lua/gitlab/git.lua @@ -6,6 +6,7 @@ local M = {} ---@param command table ---@return string|nil, string|nil local run_system = function(command) + -- Load here to prevent loop local u = require("gitlab.utils") local result = vim.fn.trim(vim.fn.system(command)) if vim.v.shell_error ~= 0 then @@ -16,9 +17,12 @@ local run_system = function(command) end ---Returns all branches for the current repository +---@param args table|nil extra arguments for `git branch` ---@return string|nil, string|nil -M.branches = function() - return run_system({ "git", "branch" }) +M.branches = function(args) + -- Load here to prevent loop + local u = require("gitlab.utils") + return run_system(u.combine({ "git", "branch" }, args or {})) end ---Checks whether the tree has any changes that haven't been pushed to the remote @@ -60,7 +64,7 @@ end ---Return the list of names of all remote-tracking branches or an empty list. ---@return table, string|nil M.get_all_remote_branches = function() - local all_branches, err = M.branches() + local all_branches, err = M.branches({ "--remotes" }) if err ~= nil then return {}, err end