Skip to content

Commit

Permalink
feat: Make keypress message configuratble (#351)
Browse files Browse the repository at this point in the history
* feat(keypress): Make keypress message configuratble

This should partially fix the the problems between `mini` view of
`noice.nvim` discussed in #350

* refactor: show_keypress => show_keys

Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
  • Loading branch information
ranjithshegde and folke committed Oct 21, 2022
1 parent 26eb530 commit fd2422f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ WhichKey comes with the following defaults:
ignore_missing = false, -- enable this to hide mappings for which you didn't specify a label
hidden = { "<silent>", "<cmd>", "<Cmd>", "<CR>", "call", "lua", "^:", "^ "}, -- hide mapping boilerplate
show_help = true, -- show help message on the command line when the popup is visible
show_keys = true, -- show the currently pressed key and its label as a message in the command line
triggers = "auto", -- automatically setup triggers
-- triggers = {"<leader>"} -- or specify a list manually
triggers_blacklist = {
Expand Down
1 change: 1 addition & 0 deletions doc/which-key.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ WhichKey comes with the following defaults:
ignore_missing = false, -- enable this to hide mappings for which you didn't specify a label
hidden = { "<silent>", "<cmd>", "<Cmd>", "<CR>", "call", "lua", "^:", "^ "}, -- hide mapping boilerplate
show_help = true, -- show help message on the command line when the popup is visible
show_keypress = true, -- show the currently pressed key and its label as a message in the command line
triggers = "auto", -- automatically setup triggers
-- triggers = {"<leader>"} -- or specify a list manually
triggers_blacklist = {
Expand Down
1 change: 1 addition & 0 deletions lua/which-key/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ local defaults = {
ignore_missing = false, -- enable this to hide mappings for which you didn't specify a label
hidden = { "<silent>", "<cmd>", "<Cmd>", "<CR>", "^:", "^ ", "^call ", "^lua " }, -- hide mapping boilerplate
show_help = true, -- show a help message in the command line for using WhichKey
show_keys = true, -- show the currently pressed key and its label as a message in the command line
triggers = "auto", -- automatically setup triggers
-- triggers = {"<leader>"} -- or specifiy a list manually
triggers_nowait = {}, -- list of triggers, where WhichKey should not wait for timeoutlen and show immediately
Expand Down
18 changes: 12 additions & 6 deletions lua/which-key/layout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,18 @@ function Layout:trail()
if Config.options.key_labels[step] then
step = Config.options.key_labels[step]
end
table.insert(cmd_line, { step, "WhichKeyGroup" })
if i ~= #self.mapping.keys.notation then
table.insert(cmd_line, { " " .. self.options.icons.breadcrumb .. " ", "WhichKeySeparator" })
if Config.options.show_keys then
table.insert(cmd_line, { step, "WhichKeyGroup" })
if i ~= #self.mapping.keys.notation then
table.insert(cmd_line, { " " .. self.options.icons.breadcrumb .. " ", "WhichKeySeparator" })
end
end
end
local width = 0
for _, line in pairs(cmd_line) do
width = width + Text.len(line[1])
if Config.options.show_keys then
for _, line in pairs(cmd_line) do
width = width + Text.len(line[1])
end
end
local help = { --
["<bs>"] = "go up one level",
Expand All @@ -79,7 +83,9 @@ function Layout:trail()
table.insert(help_line, { key .. " ", "WhichKey" })
table.insert(help_line, { label .. " ", "WhichKeySeparator" })
end
table.insert(cmd_line, { string.rep(" ", math.floor(vim.o.columns / 2 - help_width / 2) - width) })
if Config.options.show_keys then
table.insert(cmd_line, { string.rep(" ", math.floor(vim.o.columns / 2 - help_width / 2) - width) })
end

if self.options.show_help then
for _, l in pairs(help_line) do
Expand Down

0 comments on commit fd2422f

Please sign in to comment.