diff --git a/lua/nvim-autopairs/conds.lua b/lua/nvim-autopairs/conds.lua index 1e81b33..429a7fc 100644 --- a/lua/nvim-autopairs/conds.lua +++ b/lua/nvim-autopairs/conds.lua @@ -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 diff --git a/tests/nvim-autopairs_spec.lua b/tests/nvim-autopairs_spec.lua index 1edaa46..b872d42 100644 --- a/tests/nvim-autopairs_spec.lua +++ b/tests/nvim-autopairs_spec.lua @@ -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)]] } }