Skip to content

Commit

Permalink
fix: recursion on ctrl-keys mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
Wansmer committed Mar 28, 2024
1 parent 41951c0 commit 1438f92
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lua/langmapper/auto.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ local function automapping(scope, bufnr)
for _, map in ipairs(mappings) do
local lhs = u.translate_keycode(map.lhs, lang)
for _, mode in ipairs(map.mode) do
if not (map.lhs == lhs or has_map(lhs, mode, mappings)) then
-- prevent recursion on ctrl-keys mappings
local is_same = vim.startswith(map.lhs:lower(), '<c-') and lhs:lower() == map.lhs:lower() or lhs == map.lhs
if not (is_same or has_map(lhs, mode, mappings)) then
local rhs = function()
local repl = vim.api.nvim_replace_termcodes(map.lhs, true, true, true)
vim.api.nvim_feedkeys(repl, 'm', true)
Expand Down
2 changes: 1 addition & 1 deletion lua/langmapper/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function M._map_translated_ctrls()
local tr_keycode = '<C-' .. tr_char .. '>'
local desc = M.update_desc(nil, 'feedkeys', keycode)
-- Prevent recursion
if not from:find(tr_char, 1, true) then
if not from:find(tr_char, 1, true) and not char == tr_char then
local term_keycodes = vim.api.nvim_replace_termcodes(keycode, true, true, true)
keymap(modes, tr_keycode, function()
vim.api.nvim_feedkeys(term_keycodes, 'm', true)
Expand Down

0 comments on commit 1438f92

Please sign in to comment.