This commit is contained in:
hrsh7th
2022-01-25 10:06:36 +09:00
parent 27123b1297
commit 2d67b6dd76
3 changed files with 76 additions and 77 deletions

View File

@@ -260,20 +260,9 @@ core.complete = function(self, ctx)
end
---Update completion menu
core.filter = async.throttle(
setmetatable({
ctx = nil,
}, {
__call = function(this, self)
core.filter = async.throttle(function(self)
self.filter.timeout = self.view:visible() and THROTTLE_TIME or 0
-- Check context changed.
local ctx = self:get_context()
if this.ctx and not this.ctx:changed(ctx) then
return
end
this.ctx = ctx
-- Check invalid condition.
local ignore = false
ignore = ignore or not api.is_suitable_mode()
@@ -293,6 +282,8 @@ core.filter = async.throttle(
table.insert(sources, s)
end
local ctx = self:get_context()
-- Display completion results.
self.view:open(ctx, sources)
@@ -307,10 +298,7 @@ core.filter = async.throttle(
end) == 0 then
config.set_onetime({})
end
end
}),
THROTTLE_TIME
)
end, THROTTLE_TIME)
---Confirm completion.
---@param e cmp.Entry

View File

@@ -94,6 +94,7 @@ describe('keymap', function()
describe('realworld', function()
before_each(spec.before)
it('#226', function()
keymap.listen('i', '<c-n>', function(_, fallback)
fallback()
@@ -101,6 +102,7 @@ describe('keymap', function()
vim.api.nvim_feedkeys(keymap.t('iaiueo<CR>a<C-n><C-n>'), 'tx', true)
assert.are.same({ 'aiueo', 'aiueo' }, vim.api.nvim_buf_get_lines(0, 0, -1, true))
end)
it('#414', function()
keymap.listen('i', '<M-j>', function()
vim.api.nvim_feedkeys(keymap.t('<C-n>'), 'int', true)
@@ -108,5 +110,17 @@ describe('keymap', function()
vim.api.nvim_feedkeys(keymap.t('iaiueo<CR>a<M-j><M-j>'), 'tx', true)
assert.are.same({ 'aiueo', 'aiueo' }, vim.api.nvim_buf_get_lines(0, 0, -1, true))
end)
-- it('#744', function()
-- vim.api.nvim_buf_set_keymap(0, 'i', '<C-r>', 'recursive', {
-- noremap = true
-- })
-- vim.api.nvim_buf_set_keymap(0, 'i', '<CR>', '<CR>recursive', {
-- noremap = false
-- })
-- keymap.listen('i', '<CR>', function(_, fallback) fallback() end)
-- feedkeys.call(keymap.t('i<CR>'), 'tx')
-- assert.are.same({ '', 'recursive' }, vim.api.nvim_buf_get_lines(0, 0, -1, true))
-- end)
end)
end)

View File

@@ -197,8 +197,7 @@ view._get_entries_view = function(self)
end
---On entry change
view.on_entry_change = async.throttle(
function(self)
view.on_entry_change = async.throttle(function(self)
if not self:visible() then
return
end
@@ -225,8 +224,6 @@ view.on_entry_change = async.throttle(
else
self.ghost_text_view:hide()
end
end,
20
)
end, 20)
return view