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:
Jakub F. Bortlík
2023-12-05 14:06:32 +01:00
committed by GitHub
parent 02db3e4b0e
commit cc68476b15
8 changed files with 75 additions and 37 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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()