From 4f8dde0a6bcdc2880d397eb1c4ee85adb1046808 Mon Sep 17 00:00:00 2001 From: "Wansmer (Ivan Smirnov)" Date: Thu, 9 May 2024 09:47:30 +0300 Subject: [PATCH] refactor: remove extra `if` statement --- lua/langmapper/utils.lua | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) 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