From 132dd60b9526c033bcdd9f148b4465202e09c92e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20F=2E=20Bortl=C3=ADk?= Date: Mon, 22 Jan 2024 14:14:40 +0100 Subject: [PATCH] Feat: save popup contents to register (#163) Users can now provide a backup register when creating comments, notes, and so forth which will automatically be populated with the contents of the buffer prior to submission to Gitlab. This ensures that even if the API call fails the contents of the buffer is saved, which prevents the user from losing their changes. This is a MINOR update. --- README.md | 1 + doc/gitlab.nvim.txt | 18 ++++++++++++++++++ lua/gitlab/state.lua | 4 ++++ 3 files changed, 23 insertions(+) diff --git a/README.md b/README.md index ecd7a33..18c99a8 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ require("gitlab").setup({ pipeline = nil, reply = nil, squash_message = nil, + backup_register = nil, }, discussion_tree = { -- The discussion tree that holds all comments auto_open = true, -- Automatically open when the reviewer is opened diff --git a/doc/gitlab.nvim.txt b/doc/gitlab.nvim.txt index 23806a9..6bed96d 100644 --- a/doc/gitlab.nvim.txt +++ b/doc/gitlab.nvim.txt @@ -156,6 +156,7 @@ you call this function with no values the defaults will be used: pipeline = nil, reply = nil, squash_message = nil, + backup_register = nil, }, discussion_tree = { -- The discussion tree that holds all comments auto_open = true, -- Automatically open when the reviewer is opened @@ -308,7 +309,24 @@ which works similar to `create_multiline_comment` but prefills the comment window with Gitlab’s suggest changes code block with prefilled code from the visual selection. +Just like the summary, all the different kinds of comments are saved via the +`settings.popup.perform_action` keybinding. +BACKUP REGISTER *gitlab.nvim.backup-register* + +Sometimes, the action triggered by `settings.popup.perform_action` can fail. +To prevent losing your carefully crafted note/comment/suggestion you can set +`settings.popup.backup_register` to a writable register (see |registers|) to +which the contents of the popup window will be saved just before the action is +performed. A practical setting is `settings.popup.backup_register = "+"` which +saves to the system clipboard (see |quoteplus|). This lets you easily apply +the action on Gitlab in a browser, if it keeps failing in `gitlab.nvim`. + +If you experience such problems, please first read the +|gitlab.nvim.troubleshooting| section. If it does not help, see if there are +any relevant known . If +there are none, please open one and provide any error messages that +`gitlab.nvim` may be showing. DISCUSSIONS AND NOTES *gitlab.nvim.discussions-and-notes* diff --git a/lua/gitlab/state.lua b/lua/gitlab/state.lua index 1531d33..c37c3e3 100644 --- a/lua/gitlab/state.lua +++ b/lua/gitlab/state.lua @@ -35,6 +35,7 @@ M.settings = { help = nil, pipeline = nil, squash_message = nil, + backup_register = nil, }, discussion_tree = { auto_open = true, @@ -273,6 +274,9 @@ M.set_popup_keymaps = function(popup, action, linewise_action, opts) if action ~= nil then vim.keymap.set("n", M.settings.popup.perform_action, function() local text = u.get_buffer_text(popup.bufnr) + if M.settings.popup.backup_register ~= nil then + vim.cmd("0,$yank " .. M.settings.popup.backup_register) + end if opts.action_before_close then action(text, popup.bufnr) exit(popup, opts)