Skip to content

Commit

Permalink
Use manual key conversion logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hrsh7th committed Jan 10, 2022
1 parent 38f5373 commit f2f6dce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lua/cmp/utils/keymap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ local keymap = {}
---@param keys string
---@return string
keymap.t = function(keys)
return vim.api.nvim_replace_termcodes(keys, true, true, true)
return (string.gsub(keys, '(<[A-Za-z0-9_%-%[%]%^@]->)', function(match)
return vim.api.nvim_eval(string.format([["\%s"]], match))
end))
end

---Normalize key sequence.
Expand Down
6 changes: 6 additions & 0 deletions lua/cmp/utils/keymap_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ local keymap = require('cmp.utils.keymap')
describe('keymap', function()
before_each(spec.before)

it('t', function()
assert.are.equal(keymap.t('<Tab>'), vim.api.nvim_replace_termcodes('<Tab>', true, true, true))
assert.are.equal(keymap.t('<C-g>u'), vim.api.nvim_replace_termcodes('<C-g>u', true, true, true))
assert.are.equal(keymap.t('<Cmd>aiueo<CR>'), vim.api.nvim_replace_termcodes('<Cmd>aiueo<CR>', true, true, true))
end)

it('to_keymap', function()
assert.are.equal(keymap.to_keymap('\n'), '<CR>')
assert.are.equal(keymap.to_keymap('<CR>'), '<CR>')
Expand Down

0 comments on commit f2f6dce

Please sign in to comment.