From 13e8b61371925ebcea4069a67f16315e96c8f935 Mon Sep 17 00:00:00 2001 From: hrsh7th Date: Sun, 19 Sep 2021 13:40:27 +0900 Subject: [PATCH] Fix keymap bug --- lua/cmp/core.lua | 2 +- lua/cmp/utils/keymap.lua | 35 ++++------------------------------- 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/lua/cmp/core.lua b/lua/cmp/core.lua index a75407c..79cd72e 100644 --- a/lua/cmp/core.lua +++ b/lua/cmp/core.lua @@ -142,7 +142,7 @@ end ---Keypress handler core.on_keymap = function(keys, fallback) for key, action in pairs(config.get().mapping) do - if key == keys then + if keymap.equals(key, keys) then if type(action) == 'function' then action(fallback) else diff --git a/lua/cmp/utils/keymap.lua b/lua/cmp/utils/keymap.lua index 7d75da2..681b0ee 100644 --- a/lua/cmp/utils/keymap.lua +++ b/lua/cmp/utils/keymap.lua @@ -54,30 +54,7 @@ end ---@param b string ---@return boolean keymap.equals = function(a, b) - return keymap.to_upper(a) == keymap.to_upper(b) -end - ----Return upper case key sequence. ----@param keys string ----@return string -keymap.to_upper = function(keys) - local result = {} - local ctrl = false - for i = 1, #keys do - local c = string.sub(keys, i, i) - if c == '<' then - table.insert(result, c) - ctrl = true - elseif ctrl and c ~= '>' then - table.insert(result, string.upper(c)) - elseif ctrl and c == '>' then - table.insert(result, c) - ctrl = false - else - table.insert(result, c) - end - end - return table.concat(result, '') + return keymap.t(a) == keymap.t(b) end ---Feedkeys with callback @@ -121,7 +98,7 @@ keymap.listen = setmetatable({ cache = cache.new(), }, { __call = function(self, mode, keys, callback) - keys = keymap.to_upper(keymap.to_keymap(keys)) + keys = keymap.to_keymap(keys) local existing = keymap.find_map_by_lhs(mode, keys) if string.match(existing.rhs, '^.*' .. vim.pesc('v:lua.cmp.utils.keymap.listen.run') .. '.*$') then @@ -193,21 +170,17 @@ end keymap.find_map_by_lhs = function(mode, lhs) for _, map in ipairs(vim.api.nvim_buf_get_keymap(0, mode)) do if keymap.equals(map.lhs, lhs) then - map.lhs = keymap.to_upper(map.lhs) - map.rhs = keymap.to_upper(map.rhs) return map end end for _, map in ipairs(vim.api.nvim_get_keymap(mode)) do if keymap.equals(map.lhs, lhs) then - map.lhs = keymap.to_upper(map.lhs) - map.rhs = keymap.to_upper(map.rhs) return map end end return { - lhs = keymap.to_upper(lhs), - rhs = keymap.to_upper(lhs), + lhs = lhs, + rhs = lhs, expr = 0, script = 0, noremap = 1,