Don't feed <C-f> manually but check auto-indentation
This commit is contained in:
@@ -154,7 +154,6 @@ core.on_change = function(self, trigger_event)
|
|||||||
self:get_context({ reason = types.cmp.ContextReason.Auto })
|
self:get_context({ reason = types.cmp.ContextReason.Auto })
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
self:autoindent(trigger_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))
|
||||||
@@ -204,25 +203,15 @@ core.autoindent = function(self, trigger_event, callback)
|
|||||||
return callback()
|
return callback()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Scan indentkeys.
|
-- Reset current completion if indentkeys matched.
|
||||||
for _, key in ipairs(vim.split(vim.bo.indentkeys, ',')) do
|
for _, key in ipairs(vim.split(vim.bo.indentkeys, ',')) do
|
||||||
if vim.tbl_contains({ '=' .. prefix, '0=' .. prefix }, key) then
|
if vim.tbl_contains({ '=' .. prefix, '0=' .. prefix }, key) then
|
||||||
local release = self:suspend()
|
self:reset()
|
||||||
vim.schedule(function() -- Check autoindent already applied.
|
self:set_context(context.empty())
|
||||||
if cursor_before_line == api.get_cursor_before_line() then
|
break
|
||||||
feedkeys.call(keymap.autoindent(), 'n', function()
|
|
||||||
release()
|
|
||||||
callback()
|
|
||||||
end)
|
|
||||||
else
|
|
||||||
callback()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- indentkeys does not matched.
|
|
||||||
callback()
|
callback()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -429,7 +418,6 @@ core.reset = function(self)
|
|||||||
for _, s in pairs(self.sources) do
|
for _, s in pairs(self.sources) do
|
||||||
s:reset()
|
s:reset()
|
||||||
end
|
end
|
||||||
self:get_context() -- To prevent new event
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return core
|
return core
|
||||||
|
|||||||
@@ -23,15 +23,6 @@ describe('feedkeys', function()
|
|||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('autoindent', function()
|
|
||||||
vim.cmd([[setlocal indentkeys+==end]])
|
|
||||||
feedkeys.call(keymap.t('iif<CR><Tab>end') .. keymap.autoindent(), 'nx')
|
|
||||||
assert.are.same(vim.api.nvim_buf_get_lines(0, 0, -1, false), {
|
|
||||||
'if',
|
|
||||||
'end',
|
|
||||||
})
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('testability', function()
|
it('testability', function()
|
||||||
feedkeys.call('i', 'n', function()
|
feedkeys.call('i', 'n', function()
|
||||||
feedkeys.call('', 'n', function()
|
feedkeys.call('', 'n', function()
|
||||||
|
|||||||
@@ -73,18 +73,6 @@ keymap.backspace = function(count)
|
|||||||
return table.concat(keys, '')
|
return table.concat(keys, '')
|
||||||
end
|
end
|
||||||
|
|
||||||
---Create autoindent keys
|
|
||||||
---@return string
|
|
||||||
keymap.autoindent = function()
|
|
||||||
local keys = {}
|
|
||||||
table.insert(keys, keymap.t('<Cmd>setlocal cindent<CR>'))
|
|
||||||
table.insert(keys, keymap.t('<Cmd>setlocal indentkeys+=!^F<CR>'))
|
|
||||||
table.insert(keys, keymap.t('<C-f>'))
|
|
||||||
table.insert(keys, keymap.t('<Cmd>setlocal %scindent<CR>'):format(vim.bo.cindent and '' or 'no'))
|
|
||||||
table.insert(keys, keymap.t('<Cmd>setlocal indentkeys=%s<CR>'):format(vim.bo.indentkeys:gsub('|', '\\|')))
|
|
||||||
return table.concat(keys, '')
|
|
||||||
end
|
|
||||||
|
|
||||||
---Return two key sequence are equal or not.
|
---Return two key sequence are equal or not.
|
||||||
---@param a string
|
---@param a string
|
||||||
---@param b string
|
---@param b string
|
||||||
|
|||||||
Reference in New Issue
Block a user