diff --git a/lua/langmapper/utils.lua b/lua/langmapper/utils.lua index 8ff1dd9..d701bff 100644 --- a/lua/langmapper/utils.lua +++ b/lua/langmapper/utils.lua @@ -243,23 +243,23 @@ function M._set_variant_commands() local get_layout_id = c.config.os[os] and c.config.os[os].get_current_layout_id local can_check_layout = get_layout_id and type(get_layout_id) == 'function' - if can_check_layout then - for _, lang in ipairs(c.config.use_layouts) do - local from = c.config.layouts[lang].default_layout or c.config.default_layout - local to = c.config.layouts[lang].layout - - local to_check = collect_variant_commands(from, to) - if can_check_layout then - for key, value in pairs(to_check) do - vim.keymap.set('n', key, function() - if get_layout_id() == c.config.layouts[lang].id then - feed_nmap(value.on_layout) - else - feed_nmap(value.on_default) - end - end) + if not can_check_layout then + return + end + + for _, lang in ipairs(c.config.use_layouts) do + local from = c.config.layouts[lang].default_layout or c.config.default_layout + local to = c.config.layouts[lang].layout + + local to_check = collect_variant_commands(from, to) + for key, value in pairs(to_check) do + vim.keymap.set('n', key, function() + if get_layout_id() == c.config.layouts[lang].id then + feed_nmap(value.on_layout) + else + feed_nmap(value.on_default) end - end + end) end end end