Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix (local)leader with more than one character #492

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/which-key.nvim.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*which-key.nvim.txt* For Neovim >= 0.8.0 Last change: 2023 July 28
*which-key.nvim.txt* For Neovim >= 0.8.0 Last change: 2023 July 30

==============================================================================
Table of Contents *which-key.nvim-table-of-contents*
Expand Down
31 changes: 28 additions & 3 deletions lua/which-key/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local cache = {}
---@type table<string,string>
local tcache = {}
local cache_leaders = ""
local cache_leader_details = {}

function M.check_cache()
---@type string
Expand All @@ -15,6 +16,10 @@ function M.check_cache()
cache = {}
tcache = {}
cache_leaders = leaders
cache_leader_details = {
["<leader>"] = M.parse_internal(vim.g.mapleader or ""),
["<localleader>"] = M.parse_internal(vim.g.maplocalleader or ""),
}
end
end

Expand Down Expand Up @@ -120,9 +125,29 @@ function M.parse_keys(keystr)
end
end

local mapleader = vim.g.mapleader
mapleader = mapleader and M.t(mapleader)
notation[1] = internal[1] == mapleader and "<leader>" or notation[1]
for leader, leader_sequence in pairs(cache_leader_details) do
local length = vim.tbl_count(leader_sequence)
if length > 1 then
local tmp = {}
for _, key in ipairs(notation) do
if key == leader then
for _, k in ipairs(leader_sequence) do
table.insert(tmp, k)
end
elseif key == " " then
table.insert(tmp, "<space>")
else
table.insert(tmp, key)
end
end
notation = tmp
elseif length == 1 then
local key = M.t(leader_sequence[1])
if internal[1] == key then
notation[1] = leader
end
end
end

if #notation ~= #internal then
error(vim.inspect({ keystr = keystr, internal = internal, notation = notation }))
Expand Down