Repository navigation
Expand file tree
/
Copy pathhelp.lua
More file actions
65 lines (55 loc) · 1.97 KB
/
Copy pathhelp.lua
File metadata and controls
65 lines (55 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
local u = require("gitlab.utils")
local popup = require("gitlab.popup")
local event = require("nui.utils.autocmd").event
local state = require("gitlab.state")
local List = require("gitlab.utils.list")
local Popup = require("nui.popup")
local M = {}
---@class HelpPopupOpts
---@field discussion_tree? boolean Whether help popup is for the discussion tree
---Open the help popup.
---@param opts? HelpPopupOpts Table with options for the help popup
M.open = function(opts)
local help_opts = opts or {}
local bufnr = vim.api.nvim_get_current_buf()
local keymaps = vim.api.nvim_buf_get_keymap(bufnr, "n")
local help_content_lines = List.new(keymaps):reduce(function(agg, keymap)
if keymap.desc ~= nil then
local new_line = string.format("%s: %s", keymap.lhs:gsub(" ", "<space>"), keymap.desc)
table.insert(agg, new_line)
end
return agg
end, {})
if help_opts.discussion_tree then
table.insert(help_content_lines, "")
table.insert(
help_content_lines,
string.format(
"%s = draft; %s = unlinked comment; %s = resolved",
state.settings.discussion_tree.draft,
state.settings.discussion_tree.unlinked,
state.settings.discussion_tree.resolved
)
)
end
local max_line_length = u.get_max_length(help_content_lines)
---@type PopupOpts
local popup_opts = {
title = "Help",
user_settings = state.settings.popup.help,
width = max_line_length + 3,
height = #help_content_lines,
zindex = 70,
}
local help_popup = Popup(popup.create_popup_state(popup_opts))
help_popup:on(event.BufLeave, function()
help_popup:unmount()
end)
popup.set_up_autocommands(help_popup, nil, vim.api.nvim_get_current_win(), popup_opts)
help_popup:mount()
popup.set_popup_keymaps(help_popup, "Help", nil)
local currentBuffer = vim.api.nvim_get_current_buf()
vim.api.nvim_buf_set_lines(currentBuffer, 0, #help_content_lines, false, help_content_lines)
u.switch_can_edit_buf(currentBuffer, false)
end
return M