Skip to content
This repository was archived by the owner on Jan 27, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions lua/compe/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local Debug = require'compe.utils.debug'
local Callback = require'compe.utils.callback'
local api = vim.api
local Completion = require'compe.completion'
local Source = require'compe.source'
local Config = require'compe.config'
Expand Down Expand Up @@ -57,6 +58,50 @@ compe.unregister_source = function(id)
Completion.unregister_source(id)
end

do
local function replace(keys)
return vim.api.nvim_replace_termcodes(keys, true, true, true)
end

local function feedkeys(keys)
api.nvim_feedkeys(replace(keys), 'n', true)
end

local input = api.nvim_input

local function mode() return api.nvim_get_mode()['mode'] end

-- use with expr mapping
compe.confirm = function(keys)
if vim.fn.pumvisible() == 0 then return replace(keys) end

local mode_correct = mode():match('i') ~= nil

if mode_correct
and vim.fn.complete_info({'selected'})['selected'] == -1
and Config.get().preselect == 'confirm'
then
feedkeys("<Down>") -- selected the next one
end

local function run()
vim.fn.luaeval('require"compe"._confirm_pre()')
input('<Plug>(compe-confirm)')
end

-- we have to check this first because calling complete_info again will cause it to screw up
if Config.get().preselect == 'confirm' then
run()
elseif mode_correct and vim.fn.complete_info({'selected'})['selected'] ~= -1 then
run()
else
return replace(keys)
end

return replace('<Ignore>')
end
end

--- Private API

--- _complete
Expand Down