Skip to content

Commit bd6c0c2

Browse files
committed
feat: Show help hints
You can hide the help hints by setting `show_help_hints = false` in your config.
1 parent c33cfce commit bd6c0c2

File tree

7 files changed

+46
-6
lines changed

7 files changed

+46
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ require("diffview").setup({
162162
enhanced_diff_hl = false, -- See ':h diffview-config-enhanced_diff_hl'
163163
git_cmd = { "git" }, -- The git executable followed by default args.
164164
use_icons = true, -- Requires nvim-web-devicons
165+
show_help_hints = true, -- Show hints for how to open the help panel
165166
watch_index = true, -- Update views and index buffers when the git index changes.
166167
icons = { -- Only applies when use_icons is true.
167168
folder_closed = "",

doc/diffview_defaults.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require("diffview").setup({
1010
enhanced_diff_hl = false, -- See |diffview-config-enhanced_diff_hl|
1111
git_cmd = { "git" }, -- The git executable followed by default args.
1212
use_icons = true, -- Requires nvim-web-devicons
13+
show_help_hints = true, -- Show hints for how to open the help panel
1314
watch_index = true, -- Update views and index buffers when the git index changes.
1415
icons = { -- Only applies when use_icons is true.
1516
folder_closed = "",

lua/diffview/config.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ M.defaults = {
3939
enhanced_diff_hl = false,
4040
git_cmd = { "git" },
4141
use_icons = true,
42+
show_help_hints = true,
4243
watch_index = true,
4344
icons = {
4445
folder_closed = "",
@@ -331,6 +332,22 @@ function M.get_layout_keymaps(layout)
331332
end
332333
end
333334

335+
function M.find_option_keymap(t)
336+
for _, mapping in ipairs(t) do
337+
if mapping[3] and mapping[3] == actions.options then
338+
return mapping
339+
end
340+
end
341+
end
342+
343+
function M.find_help_keymap(t)
344+
for _, mapping in ipairs(t) do
345+
if type(mapping[4]) == "table" and mapping[4].desc == "Open the help panel" then
346+
return mapping
347+
end
348+
end
349+
end
350+
334351
---@param values vector
335352
---@param no_quote? boolean
336353
---@return string

lua/diffview/scene/views/diff/file_panel.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ local M = {}
2121
---@field render_data RenderData
2222
---@field components CompStruct
2323
---@field constrain_cursor function
24+
---@field help_mapping string
2425
local FilePanel = oop.create_class("FilePanel", Panel)
2526

2627
FilePanel.winopts = vim.tbl_extend("force", Panel.winopts, {
@@ -79,6 +80,9 @@ function FilePanel:setup_buffer()
7980
local opt = vim.tbl_extend("force", default_opt, mapping[4] or {}, { buffer = self.bufid })
8081
vim.keymap.set(mapping[1], mapping[2], mapping[3], opt)
8182
end
83+
84+
local help_keymap = config.find_help_keymap(conf.keymaps.file_panel)
85+
if help_keymap then self.help_mapping = help_keymap[2] end
8286
end
8387

8488
function FilePanel:update_components()

lua/diffview/scene/views/diff/render.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ return function(panel)
126126
end
127127

128128
panel.render_data:clear()
129+
local conf = config.get_config()
129130
local width = panel:get_width()
131+
130132
if width == -1 then
131133
local panel_config = panel:get_config()
132134
width = panel_config.width
@@ -140,6 +142,12 @@ return function(panel)
140142
"DiffviewFilePanelRootPath"
141143
)
142144

145+
if conf.show_help_hints and panel.help_mapping then
146+
comp:add_text("Help: ", "DiffviewFilePanelPath")
147+
comp:add_line(panel.help_mapping, "DiffviewFilePanelCounter")
148+
comp:add_line()
149+
end
150+
143151
if #panel.files.conflicting > 0 then
144152
comp = panel.components.conflicting.title.comp
145153
comp:add_text("Conflicts ", "DiffviewFilePanelTitle")

lua/diffview/scene/views/file_history/file_history_panel.lua

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ local perf_update = PerfTimer("[FileHistoryPanel] update")
3434
---@field render_data RenderData
3535
---@field option_panel FHOptionPanel
3636
---@field option_mapping string
37+
---@field help_mapping string
3738
---@field components CompStruct
3839
---@field constrain_cursor function
3940
local FileHistoryPanel = oop.create_class("FileHistoryPanel", Panel.__get())
@@ -125,18 +126,18 @@ end
125126

126127
function FileHistoryPanel:setup_buffer()
127128
local conf = config.get_config()
128-
local option_rhs = config.actions.options
129129
local default_opt = { silent = true, nowait = true, buffer = self.bufid }
130130

131131
for _, mapping in ipairs(conf.keymaps.file_history_panel) do
132-
local lhs, rhs = mapping[2], mapping[3]
133132
local opt = vim.tbl_extend("force", default_opt, mapping[4] or {}, { buffer = self.bufid })
134133
vim.keymap.set(mapping[1], mapping[2], mapping[3], opt)
135-
136-
if rhs == option_rhs then
137-
self.option_mapping = lhs
138-
end
139134
end
135+
136+
local option_keymap = config.find_option_keymap(conf.keymaps.file_history_panel)
137+
if option_keymap then self.option_mapping = option_keymap[2] end
138+
139+
local help_keymap = config.find_help_keymap(conf.keymaps.file_history_panel)
140+
if help_keymap then self.help_mapping = help_keymap[2] end
140141
end
141142

142143
function FileHistoryPanel:update_components()

lua/diffview/scene/views/file_history/render.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,12 @@ return {
155155

156156
perf:reset()
157157
panel.render_data:clear()
158+
158159
if not cache[panel] then
159160
prepare_panel_cache(panel)
160161
end
161162

163+
local conf = config.get_config()
162164
local comp = panel.components.header.comp
163165
local log_options = panel:get_log_options()
164166
local cached = cache[panel]
@@ -200,6 +202,12 @@ return {
200202
comp:ln()
201203
end
202204

205+
if conf.show_help_hints and panel.help_mapping then
206+
comp:add_text("Help: ", "DiffviewFilePanelPath")
207+
comp:add_text(panel.help_mapping, "DiffviewFilePanelCounter")
208+
comp:ln()
209+
end
210+
203211
-- title
204212
comp = panel.components.log.title.comp
205213
comp:add_line()

0 commit comments

Comments
 (0)