From 0e83ce52d98a2e8b6367da25ccf42633e4260073 Mon Sep 17 00:00:00 2001 From: fjchen7 Date: Fri, 30 Dec 2022 12:17:36 +0800 Subject: [PATCH 1/6] Support ignoring mapping in help panel --- lua/diffview/ui/panels/help_panel.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lua/diffview/ui/panels/help_panel.lua b/lua/diffview/ui/panels/help_panel.lua index 6e66a091..b9115e9f 100644 --- a/lua/diffview/ui/panels/help_panel.lua +++ b/lua/diffview/ui/panels/help_panel.lua @@ -125,6 +125,9 @@ function HelpPanel:update_components() maps = utils.tbl_fmap(maps, function(v) if v[1] ~= "n" then return nil end local desc = v[4] and v[4].desc + if desc == false then + desc = "diffview_ignored" + end if not desc then if type(v[3]) == "string" then @@ -212,10 +215,12 @@ function HelpPanel:render() for _, item in ipairs(section.items) do ---@cast item CompStruct comp = item.comp + if comp.context.label_rhs == "diffview_ignored" then goto continue end comp:add_text(comp.context.label_lhs, "DiffviewSecondary") comp:add_text(" -> ", "DiffviewNonText") comp:add_text(comp.context.label_rhs) comp:ln() + ::continue:: end end end From 927db721d7956a1eb4da7ae7ae6101604a9b402a Mon Sep 17 00:00:00 2001 From: fjchen7 Date: Fri, 30 Dec 2022 12:21:38 +0800 Subject: [PATCH 2/6] Update doc --- README.md | 14 ++++++++++++-- doc/diffview.txt | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bd7358dd..479466a7 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ set of paths, and view the changes made in a diff split. This is a porcelain interface for git-log, and supports a good number of its options. Things like: - Filtering commits by grepping commit messages and commit authors. -- Tracing the line evolution of a given set of line ranges for multiple files. +- Tracing the line evolution of a given set of line ranges for multiple files. - Only listing changes for a specific commit range, branch, or tag. - Following file changes through renames. @@ -175,7 +175,7 @@ require("diffview").setup({ }, view = { -- Configure the layout and behavior of different types of views. - -- Available layouts: + -- Available layouts: -- 'diff1_plain' -- |'diff2_horizontal' -- |'diff2_vertical' @@ -414,6 +414,16 @@ view = { } ``` +Specially, setting `desc` to false will ignore mapping in the help panel: + +```lua +view = { + -- Ignore mapping in the help panel + { "n", "<2-LeftMouse>", actions.select_entry, { desc = false } }, +} + +``` + To disable any single mapping without disabling them all, set its `{rhs}` to `false`: diff --git a/doc/diffview.txt b/doc/diffview.txt index 30fe72aa..f9e61a2e 100644 --- a/doc/diffview.txt +++ b/doc/diffview.txt @@ -651,6 +651,14 @@ keymaps *diffview-config-keymaps* } < + Specially, setting `desc` to false will ignore mapping in the help panel: > + + view = { + -- Ignore mapping in the help panel + { "n", "<2-LeftMouse>", actions.select_entry, { desc = false } }, + } +< + To disable all the default mappings simply set: > keymaps = { From b67b282de9ab5781188fbfc54fb44d41a23ca324 Mon Sep 17 00:00:00 2001 From: fjchen7 Date: Tue, 3 Jan 2023 21:40:49 +0800 Subject: [PATCH 3/6] Remove goto --- lua/diffview/ui/panels/help_panel.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lua/diffview/ui/panels/help_panel.lua b/lua/diffview/ui/panels/help_panel.lua index b9115e9f..8c50d1b5 100644 --- a/lua/diffview/ui/panels/help_panel.lua +++ b/lua/diffview/ui/panels/help_panel.lua @@ -215,12 +215,12 @@ function HelpPanel:render() for _, item in ipairs(section.items) do ---@cast item CompStruct comp = item.comp - if comp.context.label_rhs == "diffview_ignored" then goto continue end - comp:add_text(comp.context.label_lhs, "DiffviewSecondary") - comp:add_text(" -> ", "DiffviewNonText") - comp:add_text(comp.context.label_rhs) - comp:ln() - ::continue:: + if comp.context.label_rhs ~= "diffview_ignored" then + comp:add_text(comp.context.label_lhs, "DiffviewSecondary") + comp:add_text(" -> ", "DiffviewNonText") + comp:add_text(comp.context.label_rhs) + comp:ln() + end end end end From ddd1d94d8f77c788c033c15eb77e8a364027098d Mon Sep 17 00:00:00 2001 From: fjchen7 Date: Sun, 8 Jan 2023 12:05:14 +0800 Subject: [PATCH 4/6] go with 'diffview_ignore' to hide keymap --- lua/diffview/ui/panels/help_panel.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lua/diffview/ui/panels/help_panel.lua b/lua/diffview/ui/panels/help_panel.lua index 8c50d1b5..01fbc7a0 100644 --- a/lua/diffview/ui/panels/help_panel.lua +++ b/lua/diffview/ui/panels/help_panel.lua @@ -125,9 +125,6 @@ function HelpPanel:update_components() maps = utils.tbl_fmap(maps, function(v) if v[1] ~= "n" then return nil end local desc = v[4] and v[4].desc - if desc == false then - desc = "diffview_ignored" - end if not desc then if type(v[3]) == "string" then @@ -215,7 +212,7 @@ function HelpPanel:render() for _, item in ipairs(section.items) do ---@cast item CompStruct comp = item.comp - if comp.context.label_rhs ~= "diffview_ignored" then + if comp.context.label_rhs ~= "diffview_ignore" then comp:add_text(comp.context.label_lhs, "DiffviewSecondary") comp:add_text(" -> ", "DiffviewNonText") comp:add_text(comp.context.label_rhs) From 5d9a40375d7759852ed695a92ad041cc1a4f6750 Mon Sep 17 00:00:00 2001 From: fjchen7 Date: Sun, 8 Jan 2023 12:10:06 +0800 Subject: [PATCH 5/6] update doc --- README.md | 10 ---------- doc/diffview.txt | 7 ++++--- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 479466a7..6ce61da2 100644 --- a/README.md +++ b/README.md @@ -414,16 +414,6 @@ view = { } ``` -Specially, setting `desc` to false will ignore mapping in the help panel: - -```lua -view = { - -- Ignore mapping in the help panel - { "n", "<2-LeftMouse>", actions.select_entry, { desc = false } }, -} - -``` - To disable any single mapping without disabling them all, set its `{rhs}` to `false`: diff --git a/doc/diffview.txt b/doc/diffview.txt index f9e61a2e..76115278 100644 --- a/doc/diffview.txt +++ b/doc/diffview.txt @@ -650,12 +650,13 @@ keymaps *diffview-config-keymaps* { "v", "b", function() print("bar") end, { nowait = true } }, } < - - Specially, setting `desc` to false will ignore mapping in the help panel: > + Setting a mapping's `desc` field to `diffview_ignore` will hide the mapping from + the help panel: > view = { -- Ignore mapping in the help panel - { "n", "<2-LeftMouse>", actions.select_entry, { desc = false } }, + { "n", "<2-LeftMouse>", actions.select_entry, { desc = + "diffview_ignore" } }, } < From 7787d4ec05a45a19de9baa4857b7d599d0ba2ef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sindre=20T=2E=20Str=C3=B8m?= Date: Sun, 8 Jan 2023 13:44:49 +0100 Subject: [PATCH 6/6] Ensure panel height accounts for ignored mappings --- doc/diffview.txt | 8 +++---- lua/diffview/ui/panels/help_panel.lua | 34 ++++++++++++++------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/doc/diffview.txt b/doc/diffview.txt index 76115278..8c10566a 100644 --- a/doc/diffview.txt +++ b/doc/diffview.txt @@ -650,13 +650,13 @@ keymaps *diffview-config-keymaps* { "v", "b", function() print("bar") end, { nowait = true } }, } < - Setting a mapping's `desc` field to `diffview_ignore` will hide the mapping from - the help panel: > + + Setting a mapping's `desc` field to `"diffview_ignore"` will hide the + mapping from the help panel: > view = { -- Ignore mapping in the help panel - { "n", "<2-LeftMouse>", actions.select_entry, { desc = - "diffview_ignore" } }, + { "n", "<2-LeftMouse>", actions.select_entry, { desc = "diffview_ignore" } }, } < diff --git a/lua/diffview/ui/panels/help_panel.lua b/lua/diffview/ui/panels/help_panel.lua index 01fbc7a0..5e50cc49 100644 --- a/lua/diffview/ui/panels/help_panel.lua +++ b/lua/diffview/ui/panels/help_panel.lua @@ -149,7 +149,6 @@ function HelpPanel:update_components() return a < b end) - height = height + #maps + 3 local items = { name = "items" } local section_schema = { name = "section", @@ -163,17 +162,22 @@ function HelpPanel:update_components() } for _, mapping in ipairs(maps) do - width = math.max(width, 14 + 4 + #mapping[5] + 2) - table.insert(items, { - name = "item", - context = { - label_lhs = ("%14s"):format(mapping[2]), - label_rhs = ("%s"):format(mapping[5]), - mapping = mapping, - }, - }) + local desc = mapping[5] + + if desc ~= "diffview_ignore" then + width = math.max(width, 14 + 4 + #mapping[5] + 2) + table.insert(items, { + name = "item", + context = { + label_lhs = ("%14s"):format(mapping[2]), + label_rhs = desc, + mapping = mapping, + }, + }) + end end + height = height + #items + 3 table.insert(sections, section_schema) end @@ -212,12 +216,10 @@ function HelpPanel:render() for _, item in ipairs(section.items) do ---@cast item CompStruct comp = item.comp - if comp.context.label_rhs ~= "diffview_ignore" then - comp:add_text(comp.context.label_lhs, "DiffviewSecondary") - comp:add_text(" -> ", "DiffviewNonText") - comp:add_text(comp.context.label_rhs) - comp:ln() - end + comp:add_text(comp.context.label_lhs, "DiffviewSecondary") + comp:add_text(" -> ", "DiffviewNonText") + comp:add_text(comp.context.label_rhs) + comp:ln() end end end