diff --git a/lua/nvim-autopairs/conds.lua b/lua/nvim-autopairs/conds.lua index dc10eeb1..a07518e0 100644 --- a/lua/nvim-autopairs/conds.lua +++ b/lua/nvim-autopairs/conds.lua @@ -40,6 +40,7 @@ end cond.before_regex = function(regex, length) length = length or 1 if length < 0 then length = nil end + length = length and -length ---@param opts CondOpts return function(opts) log.debug('before_regex') @@ -117,6 +118,7 @@ end cond.not_before_regex = function(regex, length) length = length or 1 if length < 0 then length = nil end + length = length and -length ---@param opts CondOpts return function(opts) log.debug('not_before_regex') diff --git a/tests/nvim-autopairs_spec.lua b/tests/nvim-autopairs_spec.lua index ac2bbe98..ff25a1d3 100644 --- a/tests/nvim-autopairs_spec.lua +++ b/tests/nvim-autopairs_spec.lua @@ -8,6 +8,7 @@ local utils = require('nvim-autopairs.utils') _G.npairs = npairs; -- use only = true to test 1 case +-- stylua: ignore local data = { { -- only = true, @@ -808,6 +809,17 @@ local data = { before = [[('|') ]], after = [[(''|) ]] }, + { + setup_func = function() + npairs.add_rules({ + Rule('123456', '789'):with_pair(cond.before_regex('^12345$', 5)), + }) + end, + name = '87 test before_regex with a specific string length', + key = [[123456]], + before = [[ some text before| ]], + after = [[ some text before123456|789 ]], + }, } local run_data = _G.Test_filter(data)