diff --git a/lua/fittencode/bindings.lua b/lua/fittencode/bindings.lua index 246cd1c..0453097 100644 --- a/lua/fittencode/bindings.lua +++ b/lua/fittencode/bindings.lua @@ -246,18 +246,24 @@ function M.setup_commands() }) end +local KEYMAPS = { + { '', API.accept_all_suggestions }, + { '', API.accept_line }, + { '', API.accept_word }, + { '', API.revoke_line }, + { '', API.revoke_word }, +} + function M.setup_keymaps() - Base.map('i', '', function() - if API.has_suggestions() then - API.accept_all_suggestions() - else - Lines.tab() - end - end) - Base.map('i', '', API.accept_line) - Base.map('i', '', API.accept_word) - Base.map('i', '', API.revoke_line) - Base.map('i', '', API.revoke_word) + for _, keymap in ipairs(KEYMAPS) do + Base.map('i', keymap[1], function() + if API.has_suggestions() then + keymap[2]() + else + Lines.feedkeys(keymap[1]) + end + end) + end Base.map('i', '', API.triggering_completion) end diff --git a/lua/fittencode/views/lines.lua b/lua/fittencode/views/lines.lua index dee58cd..a45522a 100644 --- a/lua/fittencode/views/lines.lua +++ b/lua/fittencode/views/lines.lua @@ -24,17 +24,13 @@ local function is_spaces_line(line) end ---@param chars string -local function feedkeys(chars) +function M.feedkeys(chars) local keys = api.nvim_replace_termcodes(chars, true, false, true) api.nvim_feedkeys(keys, 'in', true) end local function undojoin() - feedkeys('u') -end - -function M.tab() - feedkeys('') + M.feedkeys('u') end ---@param line string