This commit is contained in:
windwp 2022-11-28 20:59:22 +07:00
parent 5d75276fce
commit 99f6963392
2 changed files with 18 additions and 4 deletions

View File

@ -199,13 +199,16 @@ cond.is_bracket_line = function()
---@param opts CondOpts
return function(opts)
log.debug('is_bracket_line')
if utils.is_bracket(opts.char) and opts.next_char == opts.rule.end_pair then
if utils.is_bracket(opts.char) and
(opts.next_char == opts.rule.end_pair
or opts.next_char == opts.rule.start_pair)
then
-- (( many char |)) => add
-- ( many char |)) => not add
local count_prev_char, count_next_char = count_bracket_char(
opts.line,
opts.char,
opts.next_char
opts.rule.start_pair,
opts.rule.end_pair
)
if count_prev_char ~= count_next_char then
return false

View File

@ -1,4 +1,3 @@
local helpers = {}
local npairs = require('nvim-autopairs')
local Rule = require('nvim-autopairs.rule')
local cond = require('nvim-autopairs.conds')
@ -694,6 +693,18 @@ local data = {
key = [[(]],
before = [[ |`abcd`]],
after = [[ (`abcd`) ]]
},
{
name='should not add bracket on line have bracket ',
key = [[(]],
before = [[ |(abcd))]],
after = [[ ((abcd)) ]]
},
{
name='not add bracket on line have bracket ',
key = [[(]],
before = [[ |(abcd) ( visual)]],
after = [[ ()(abcd) ( visual)]]
}
}