Skip to content

Commit 132dd60

Browse files
authored
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.
1 parent b6f0233 commit 132dd60

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ require("gitlab").setup({
123123
pipeline = nil,
124124
reply = nil,
125125
squash_message = nil,
126+
backup_register = nil,
126127
},
127128
discussion_tree = { -- The discussion tree that holds all comments
128129
auto_open = true, -- Automatically open when the reviewer is opened

doc/gitlab.nvim.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ you call this function with no values the defaults will be used:
156156
pipeline = nil,
157157
reply = nil,
158158
squash_message = nil,
159+
backup_register = nil,
159160
},
160161
discussion_tree = { -- The discussion tree that holds all comments
161162
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
308309
window with Gitlab’s suggest changes
309310
<https://docs.gitlab.com/ee/user/project/merge_requests/reviews/suggestions.html>
310311
code block with prefilled code from the visual selection.
312+
Just like the summary, all the different kinds of comments are saved via the
313+
`settings.popup.perform_action` keybinding.
311314

315+
BACKUP REGISTER *gitlab.nvim.backup-register*
316+
317+
Sometimes, the action triggered by `settings.popup.perform_action` can fail.
318+
To prevent losing your carefully crafted note/comment/suggestion you can set
319+
`settings.popup.backup_register` to a writable register (see |registers|) to
320+
which the contents of the popup window will be saved just before the action is
321+
performed. A practical setting is `settings.popup.backup_register = "+"` which
322+
saves to the system clipboard (see |quoteplus|). This lets you easily apply
323+
the action on Gitlab in a browser, if it keeps failing in `gitlab.nvim`.
324+
325+
If you experience such problems, please first read the
326+
|gitlab.nvim.troubleshooting| section. If it does not help, see if there are
327+
any relevant known <https://github.com/harrisoncramer/gitlab.nvim/issues>. If
328+
there are none, please open one and provide any error messages that
329+
`gitlab.nvim` may be showing.
312330

313331
DISCUSSIONS AND NOTES *gitlab.nvim.discussions-and-notes*
314332

lua/gitlab/state.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ M.settings = {
3535
help = nil,
3636
pipeline = nil,
3737
squash_message = nil,
38+
backup_register = nil,
3839
},
3940
discussion_tree = {
4041
auto_open = true,
@@ -273,6 +274,9 @@ M.set_popup_keymaps = function(popup, action, linewise_action, opts)
273274
if action ~= nil then
274275
vim.keymap.set("n", M.settings.popup.perform_action, function()
275276
local text = u.get_buffer_text(popup.bufnr)
277+
if M.settings.popup.backup_register ~= nil then
278+
vim.cmd("0,$yank " .. M.settings.popup.backup_register)
279+
end
276280
if opts.action_before_close then
277281
action(text, popup.bufnr)
278282
exit(popup, opts)

0 commit comments

Comments
 (0)