mirror of
https://github.com/ilyakooo0/nvim-autopairs.git
synced 2024-10-26 08:41:46 +03:00
fix #102
- fix mapping multiple rule same pair on keymap - fix sort rule order
This commit is contained in:
parent
4a3d9426fd
commit
b3d5d29163
@ -164,7 +164,19 @@ M.on_attach = function(bufnr)
|
||||
end
|
||||
-- sort by length
|
||||
table.sort(rules, function(a, b)
|
||||
return (#a.start_pair or 0) > (#b.start_pair or 0)
|
||||
if a.start_pair == b.start_pair then
|
||||
if not b.key_map then
|
||||
return a.key_map and 1
|
||||
end
|
||||
if not a.key_map then
|
||||
return b.key_map and -1
|
||||
end
|
||||
return #a.key_map < #b.key_map
|
||||
end
|
||||
if #a.start_pair == #b.start_pair then
|
||||
return string.byte(a.start_pair) > string.byte(b.start_pair)
|
||||
end
|
||||
return #a.start_pair > #b.start_pair
|
||||
end)
|
||||
|
||||
M.state.rules = rules
|
||||
@ -325,9 +337,13 @@ M.autopairs_map = function(bufnr, char)
|
||||
if rule.is_regex and rule.key_map and rule.key_map ~= '' then
|
||||
new_text = line:sub(1, col) .. line:sub(col + 1, #line)
|
||||
add_char = 0
|
||||
elseif rule.key_map and #rule.key_map > 1 and utils.esc(rule.key_map) == char then
|
||||
new_text = line:sub(1, col) .. line:sub(col + 1, #line)
|
||||
add_char = 0
|
||||
elseif rule.key_map and #rule.key_map > 1 then
|
||||
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 = 1
|
||||
|
@ -403,6 +403,24 @@ local data = {
|
||||
before = [[(o)=| ]],
|
||||
after = [[(o)=> { | } ]]
|
||||
|
||||
},
|
||||
{
|
||||
setup_func = function()
|
||||
npairs.add_rules({
|
||||
Rule('(', ')'):use_key('<c-w>'):replace_endpair(function()
|
||||
return '<bs><del><del><del>'
|
||||
end, true),
|
||||
Rule('(', ')'):use_key('<c-h>'):replace_endpair(function()
|
||||
return '<bs><del>'
|
||||
end, true),
|
||||
})
|
||||
end,
|
||||
name="mapping same pair with different key",
|
||||
filetype="typescript",
|
||||
key="(",
|
||||
before = [[(test|) ]],
|
||||
after = [[(test(|)) ]]
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user