-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add mappings api * fix(mappings): create lazily * feat(mappings): some fixes and don't create lazily
- Loading branch information
Showing
5 changed files
with
74 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
local mappings = {} | ||
|
||
function mappings.get_fallback(key) | ||
local lhs = ("<Plug>(NeocompleteFallback.%s)"):format(key) | ||
vim.keymap.set("i", lhs, key, { noremap = false }) | ||
return function() | ||
vim.api.nvim_feedkeys(vim.keycode(lhs), "im", false) | ||
end | ||
end | ||
|
||
local function get_mapping(rhs) | ||
for _, map in pairs(vim.api.nvim_get_keymap("i")) do | ||
---@diagnostic disable-next-line: undefined-field | ||
if type(map.rhs) == "string" and map.rhs == rhs then | ||
---@diagnostic disable-next-line: undefined-field | ||
return map.lhs | ||
end | ||
end | ||
end | ||
|
||
local function map(plug, callback) | ||
vim.keymap.set("i", plug, function() | ||
if require("neocomplete").mappings.is_open() then | ||
callback() | ||
else | ||
mappings.get_fallback(get_mapping(plug))() | ||
end | ||
end) | ||
end | ||
|
||
function mappings.setup() | ||
map("<Plug>(NeocompleteConfirm)", function() | ||
require("neocomplete").mappings.confirm() | ||
end) | ||
|
||
map("<Plug>(NeocompleteSelectNext)", function() | ||
require("neocomplete").mappings.select_next(1) | ||
end) | ||
|
||
map("<Plug>(NeocompleteSelectPrev)", function() | ||
require("neocomplete").mappings.select_prev(1) | ||
end) | ||
|
||
map("<Plug>(NeocompleteClose)", function() | ||
require("neocomplete").mappings.close() | ||
end) | ||
end | ||
|
||
return mappings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters