Make Popups Configurable (#129)
This makes the popups in the plugin (those for editing and creating comments, replies, the pipeline, etc) configurable. Users can change the default width, height, transparency, and border properties, and set overrides per popup.
This commit is contained in:
@@ -10,12 +10,17 @@ local miscellaneous = require("gitlab.actions.miscellaneous")
|
||||
local reviewer = require("gitlab.reviewer")
|
||||
local M = {}
|
||||
|
||||
local comment_popup = Popup(u.create_popup_state("Comment", "40%", "60%"))
|
||||
local note_popup = Popup(u.create_popup_state("Note", "40%", "60%"))
|
||||
-- Popup creation is wrapped in a function so that it is performed *after* user
|
||||
-- configuration has been merged with default configuration, not when this file is being
|
||||
-- required.
|
||||
local function create_comment_popup()
|
||||
return Popup(u.create_popup_state("Comment", state.settings.popup.comment))
|
||||
end
|
||||
|
||||
-- This function will open a comment popup in order to create a comment on the changed/updated
|
||||
-- line in the current MR
|
||||
M.create_comment = function()
|
||||
local comment_popup = create_comment_popup()
|
||||
comment_popup:mount()
|
||||
state.set_popup_keymaps(comment_popup, function(text)
|
||||
M.confirm_create_comment(text)
|
||||
@@ -27,6 +32,7 @@ M.create_multiline_comment = function()
|
||||
if not u.check_visual_mode() then
|
||||
return
|
||||
end
|
||||
local comment_popup = create_comment_popup()
|
||||
local start_line, end_line = u.get_visual_selection_boundaries()
|
||||
comment_popup:mount()
|
||||
state.set_popup_keymaps(comment_popup, function(text)
|
||||
@@ -40,6 +46,7 @@ M.create_comment_suggestion = function()
|
||||
if not u.check_visual_mode() then
|
||||
return
|
||||
end
|
||||
local comment_popup = create_comment_popup()
|
||||
local start_line, end_line = u.get_visual_selection_boundaries()
|
||||
local current_line = vim.api.nvim_win_get_cursor(0)[1]
|
||||
local range = end_line - start_line
|
||||
@@ -81,6 +88,7 @@ M.create_comment_suggestion = function()
|
||||
end
|
||||
|
||||
M.create_note = function()
|
||||
local note_popup = Popup(u.create_popup_state("Note", state.settings.popup.note))
|
||||
note_popup:mount()
|
||||
state.set_popup_keymaps(note_popup, function(text)
|
||||
M.confirm_create_comment(text, nil, true)
|
||||
|
||||
@@ -13,8 +13,6 @@ local reviewer = require("gitlab.reviewer")
|
||||
local miscellaneous = require("gitlab.actions.miscellaneous")
|
||||
local discussions_tree = require("gitlab.actions.discussions.tree")
|
||||
|
||||
local edit_popup = Popup(u.create_popup_state("Edit Comment", "80%", "80%"))
|
||||
local reply_popup = Popup(u.create_popup_state("Reply", "80%", "80%"))
|
||||
local discussion_sign_name = "gitlab_discussion"
|
||||
local discussion_helper_sign_start = "gitlab_discussion_helper_start"
|
||||
local discussion_helper_sign_mid = "gitlab_discussion_helper_mid"
|
||||
@@ -470,6 +468,7 @@ end
|
||||
|
||||
-- The reply popup will mount in a window when you trigger it (settings.discussion_tree.reply) when hovering over a node in the discussion tree.
|
||||
M.reply = function(tree)
|
||||
local reply_popup = Popup(u.create_popup_state("Reply", state.settings.popup.reply))
|
||||
local node = tree:get_node()
|
||||
local discussion_node = M.get_root_node(tree, node)
|
||||
local id = tostring(discussion_node.id)
|
||||
@@ -536,6 +535,7 @@ end
|
||||
|
||||
-- This function (settings.discussion_tree.edit_comment) will open the edit popup for the current comment in the discussion tree
|
||||
M.edit_comment = function(tree, unlinked)
|
||||
local edit_popup = Popup(u.create_popup_state("Edit Comment", state.settings.popup.edit))
|
||||
local current_node = tree:get_node()
|
||||
local note_node = M.get_note_node(tree, current_node)
|
||||
local root_node = M.get_root_node(tree, current_node)
|
||||
@@ -811,37 +811,37 @@ M.set_tree_keymaps = function(tree, bufnr, unlinked)
|
||||
if M.is_current_node_note(tree) then
|
||||
M.edit_comment(tree, unlinked)
|
||||
end
|
||||
end, { buffer = bufnr })
|
||||
end, { buffer = bufnr, desc = "Edit comment" })
|
||||
vim.keymap.set("n", state.settings.discussion_tree.delete_comment, function()
|
||||
if M.is_current_node_note(tree) then
|
||||
M.delete_comment(tree, unlinked)
|
||||
end
|
||||
end, { buffer = bufnr })
|
||||
end, { buffer = bufnr, desc = "Delete comment" })
|
||||
vim.keymap.set("n", state.settings.discussion_tree.toggle_resolved, function()
|
||||
if M.is_current_node_note(tree) then
|
||||
M.toggle_discussion_resolved(tree)
|
||||
end
|
||||
end, { buffer = bufnr })
|
||||
end, { buffer = bufnr, desc = "Toggle resolved" })
|
||||
vim.keymap.set("n", state.settings.discussion_tree.toggle_node, function()
|
||||
M.toggle_node(tree)
|
||||
end, { buffer = bufnr })
|
||||
end, { buffer = bufnr, desc = "Toggle node" })
|
||||
vim.keymap.set("n", state.settings.discussion_tree.reply, function()
|
||||
if M.is_current_node_note(tree) then
|
||||
M.reply(tree)
|
||||
end
|
||||
end, { buffer = bufnr })
|
||||
end, { buffer = bufnr, desc = "Reply" })
|
||||
|
||||
if not unlinked then
|
||||
vim.keymap.set("n", state.settings.discussion_tree.jump_to_file, function()
|
||||
if M.is_current_node_note(tree) then
|
||||
M.jump_to_file(tree)
|
||||
end
|
||||
end, { buffer = bufnr })
|
||||
end, { buffer = bufnr, desc = "Jump to file" })
|
||||
vim.keymap.set("n", state.settings.discussion_tree.jump_to_reviewer, function()
|
||||
if M.is_current_node_note(tree) then
|
||||
M.jump_to_reviewer(tree)
|
||||
end
|
||||
end, { buffer = bufnr })
|
||||
end, { buffer = bufnr, desc = "Jump to reviewer" })
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
-- This module is responsible for the MR pipline
|
||||
-- This module is responsible for the MR pipeline
|
||||
-- This lets the user see the current status of the pipeline
|
||||
-- and retrigger the pipeline from within the editor
|
||||
local Popup = require("nui.popup")
|
||||
@@ -42,7 +42,8 @@ M.open = function()
|
||||
local width = string.len(pipeline.web_url) + 10
|
||||
local height = 6 + #pipeline_jobs + 3
|
||||
|
||||
local pipeline_popup = Popup(u.create_popup_state("Loading Pipeline...", width, height))
|
||||
local pipeline_popup =
|
||||
Popup(u.create_popup_state("Loading Pipeline...", state.settings.popup.pipeline, width, height))
|
||||
M.pipeline_popup = pipeline_popup
|
||||
pipeline_popup:mount()
|
||||
|
||||
|
||||
@@ -18,6 +18,15 @@ M.settings = {
|
||||
exit = "<Esc>",
|
||||
perform_action = "<leader>s",
|
||||
perform_linewise_action = "<leader>l",
|
||||
width = "40%",
|
||||
height = "60%",
|
||||
border = "rounded",
|
||||
opacity = 1.0,
|
||||
edit = nil,
|
||||
reply = nil,
|
||||
comment = nil,
|
||||
note = nil,
|
||||
pipeline = nil,
|
||||
},
|
||||
discussion_tree = {
|
||||
blacklist = {},
|
||||
@@ -207,7 +216,7 @@ M.set_popup_keymaps = function(popup, action, linewise_action, opts)
|
||||
end
|
||||
vim.keymap.set("n", M.settings.popup.exit, function()
|
||||
exit(popup, opts.cb)
|
||||
end, { buffer = popup.bufnr })
|
||||
end, { buffer = popup.bufnr, desc = "Exit popup" })
|
||||
if action ~= nil then
|
||||
vim.keymap.set("n", M.settings.popup.perform_action, function()
|
||||
local text = u.get_buffer_text(popup.bufnr)
|
||||
@@ -218,7 +227,7 @@ M.set_popup_keymaps = function(popup, action, linewise_action, opts)
|
||||
exit(popup)
|
||||
action(text, popup.bufnr)
|
||||
end
|
||||
end, { buffer = popup.bufnr })
|
||||
end, { buffer = popup.bufnr, desc = "Perform action" })
|
||||
end
|
||||
|
||||
if linewise_action ~= nil then
|
||||
@@ -227,7 +236,7 @@ M.set_popup_keymaps = function(popup, action, linewise_action, opts)
|
||||
local linnr = vim.api.nvim_win_get_cursor(0)[1]
|
||||
local text = u.get_line_content(bufnr, linnr)
|
||||
linewise_action(text)
|
||||
end, { buffer = popup.bufnr })
|
||||
end, { buffer = popup.bufnr, desc = "Perform linewise action" })
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -344,8 +344,16 @@ M.jump_to_buffer = function(bufnr, line_number)
|
||||
vim.api.nvim_win_set_cursor(0, { line_number, 0 })
|
||||
end
|
||||
|
||||
M.create_popup_state = function(title, width, height)
|
||||
return {
|
||||
---Get the popup view_opts
|
||||
---@param title string The string to appear on top of the popup
|
||||
---@param settings table User defined popup settings
|
||||
---@param width string Override default width
|
||||
---@param height string Override default height
|
||||
---@return table
|
||||
M.create_popup_state = function(title, settings, width, height)
|
||||
local default_settings = require("gitlab.state").settings.popup
|
||||
local user_settings = settings or {}
|
||||
local view_opts = {
|
||||
buf_options = {
|
||||
filetype = "markdown",
|
||||
},
|
||||
@@ -353,17 +361,19 @@ M.create_popup_state = function(title, width, height)
|
||||
enter = true,
|
||||
focusable = true,
|
||||
border = {
|
||||
style = "rounded",
|
||||
style = user_settings.border or default_settings.border,
|
||||
text = {
|
||||
top = title,
|
||||
},
|
||||
},
|
||||
position = "50%",
|
||||
size = {
|
||||
width = width,
|
||||
height = height,
|
||||
width = user_settings.width or width or default_settings.width,
|
||||
height = user_settings.height or height or default_settings.height,
|
||||
},
|
||||
opacity = user_settings.opacity or default_settings.opacity,
|
||||
}
|
||||
return view_opts
|
||||
end
|
||||
|
||||
M.read_file = function(file_path)
|
||||
|
||||
Reference in New Issue
Block a user