mirror of
https://github.com/ilyakooo0/nvim-autopairs.git
synced 2024-09-11 07:15:44 +03:00
fix #238
This commit is contained in:
parent
63779ea99e
commit
62519f7573
@ -407,17 +407,9 @@ M.autopairs_map = function(bufnr, char)
|
||||
local rules = M.get_buf_rules(bufnr)
|
||||
for _, rule in pairs(rules) do
|
||||
if rule.start_pair then
|
||||
if rule.is_regex and rule.key_map and rule.key_map ~= '' then
|
||||
if rule.key_map and rule.key_map:match('<.*>') then
|
||||
new_text = line:sub(1, col) .. line:sub(col + 1, #line)
|
||||
add_char = 0
|
||||
elseif rule.key_map and rule.key_map:match('<.*>') then
|
||||
-- if it is a special key like <c-a>
|
||||
if utils.esc(rule.key_map) ~= char then
|
||||
new_text = ''
|
||||
else
|
||||
new_text = line:sub(1, col) .. line:sub(col + 1, #line)
|
||||
add_char = 0
|
||||
end
|
||||
else
|
||||
new_text = line:sub(1, col) .. char .. line:sub(col + 1, #line)
|
||||
add_char = rule.key_map and #rule.key_map or 1
|
||||
|
@ -66,9 +66,16 @@ M.show = function(line)
|
||||
then
|
||||
local key = config.keys:sub(index, index)
|
||||
index = index + 1
|
||||
if utils.is_quote(char) then
|
||||
if
|
||||
utils.is_quote(char)
|
||||
or (
|
||||
utils.is_close_bracket(char)
|
||||
and utils.is_in_quotes(line, col, prev_char)
|
||||
)
|
||||
then
|
||||
offset = 0
|
||||
end
|
||||
|
||||
if i == str_length then
|
||||
is_end_key = false
|
||||
key = config.end_key
|
||||
@ -94,7 +101,7 @@ M.show = function(line)
|
||||
vim.api.nvim_buf_clear_namespace(0, M.ns_fast_wrap, row, row + 1)
|
||||
for _, pos in pairs(list_pos) do
|
||||
if char == pos.key then
|
||||
M.move_bracket(line, pos.col, end_pair,false)
|
||||
M.move_bracket(line, pos.col, end_pair, false)
|
||||
break
|
||||
end
|
||||
if char == string.upper(pos.key) then
|
||||
@ -123,7 +130,7 @@ M.move_bracket = function(line, target_pos, end_pair, change_pos)
|
||||
line = line:sub(1, target_pos) .. end_pair .. line:sub(target_pos + 1, #line)
|
||||
vim.api.nvim_set_current_line(line)
|
||||
if change_pos then
|
||||
vim.api.nvim_win_set_cursor(0,{row + 1, target_pos})
|
||||
vim.api.nvim_win_set_cursor(0, { row + 1, target_pos })
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -49,6 +49,7 @@ function Rule.new(...)
|
||||
end_pair_length = nil,
|
||||
}, opt)
|
||||
|
||||
---@param rule Rule
|
||||
local function constructor(rule)
|
||||
-- check multibyte
|
||||
if #rule.start_pair ~= vim.api.nvim_strwidth(rule.start_pair) then
|
||||
|
@ -596,6 +596,19 @@ local data = {
|
||||
before = [[ | aaa]],
|
||||
after = [[ "ab| aaa]]
|
||||
},
|
||||
{
|
||||
setup_func = function()
|
||||
npairs.add_rule(
|
||||
Rule('struct%s[a-zA-Z]+%s?{$', '};' )
|
||||
:use_regex(true, "{")
|
||||
)
|
||||
end,
|
||||
filetype = 'javascript',
|
||||
name = 'custom endwise rule',
|
||||
key = [[{]],
|
||||
before = [[struct abc | ]],
|
||||
after = [[struct abc {|};]],
|
||||
},
|
||||
{
|
||||
setup_func = function()
|
||||
npairs.clear_rules()
|
||||
|
@ -143,11 +143,15 @@ _G.Test_withfile = function(test_data, cb)
|
||||
0,
|
||||
{ pos_before.linenr, pos_before.colnr - 1 }
|
||||
)
|
||||
if type(value.key) == "function" then
|
||||
log.debug("call key")
|
||||
value.key()
|
||||
else
|
||||
log.debug('insert:' .. value.key)
|
||||
|
||||
helpers.insert(value.key, value.not_replace_term_code)
|
||||
vim.wait(2)
|
||||
helpers.feed('<esc>')
|
||||
end
|
||||
compare_text(
|
||||
value.linenr,
|
||||
value.after,
|
||||
|
Loading…
Reference in New Issue
Block a user