Skip to content

Commit

Permalink
refactor: remove extra if statement
Browse files Browse the repository at this point in the history
  • Loading branch information
Wansmer committed May 9, 2024
1 parent f765ef0 commit 4f8dde0
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions lua/langmapper/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4f8dde0

Please sign in to comment.