Fix #420
This commit is contained in:
@@ -151,7 +151,7 @@ core.prepare = function(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---Check auto-completion
|
---Check auto-completion
|
||||||
core.on_change = function(self, event)
|
core.on_change = function(self, trigger_event)
|
||||||
local ignore = false
|
local ignore = false
|
||||||
ignore = ignore or self.suspending
|
ignore = ignore or self.suspending
|
||||||
ignore = ignore or (vim.fn.pumvisible() == 1 and (vim.v.completed_item).word)
|
ignore = ignore or (vim.fn.pumvisible() == 1 and (vim.v.completed_item).word)
|
||||||
@@ -161,14 +161,14 @@ core.on_change = function(self, event)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
self:autoindent(event, function()
|
self:autoindent(trigger_event, function()
|
||||||
local ctx = self:get_context({ reason = types.cmp.ContextReason.Auto })
|
local ctx = self:get_context({ reason = types.cmp.ContextReason.Auto })
|
||||||
debug.log(('ctx: `%s`'):format(ctx.cursor_before_line))
|
debug.log(('ctx: `%s`'):format(ctx.cursor_before_line))
|
||||||
if ctx:changed(ctx.prev_context) then
|
if ctx:changed(ctx.prev_context) then
|
||||||
self.view:on_change()
|
self.view:on_change()
|
||||||
debug.log('changed')
|
debug.log('changed')
|
||||||
|
|
||||||
if vim.tbl_contains(config.get().completion.autocomplete or {}, event) then
|
if vim.tbl_contains(config.get().completion.autocomplete or {}, trigger_event) then
|
||||||
self:complete(ctx)
|
self:complete(ctx)
|
||||||
else
|
else
|
||||||
self.filter.timeout = THROTTLE_TIME
|
self.filter.timeout = THROTTLE_TIME
|
||||||
@@ -193,10 +193,16 @@ core.on_moved = function(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---Check autoindent
|
---Check autoindent
|
||||||
---@param event cmp.TriggerEvent
|
---@param trigger_event cmp.TriggerEvent
|
||||||
---@param callback function
|
---@param callback function
|
||||||
core.autoindent = function(self, event, callback)
|
core.autoindent = function(self, trigger_event, callback)
|
||||||
if event == types.cmp.TriggerEvent.TextChanged then
|
if trigger_event ~= types.cmp.TriggerEvent.TextChanged then
|
||||||
|
return callback()
|
||||||
|
end
|
||||||
|
if not api.is_insert_mode() then
|
||||||
|
return callback()
|
||||||
|
end
|
||||||
|
|
||||||
local cursor_before_line = api.get_cursor_before_line()
|
local cursor_before_line = api.get_cursor_before_line()
|
||||||
local prefix = pattern.matchstr('[^[:blank:]]\\+$', cursor_before_line)
|
local prefix = pattern.matchstr('[^[:blank:]]\\+$', cursor_before_line)
|
||||||
if prefix then
|
if prefix then
|
||||||
@@ -220,7 +226,6 @@ core.autoindent = function(self, event, callback)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
callback()
|
callback()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user