From de252fadc31b85bf1c13bfba0df725f02c03e4b3 Mon Sep 17 00:00:00 2001 From: windwp Date: Sat, 5 Jun 2021 16:52:39 +0700 Subject: [PATCH] fix move right multi character --- lua/nvim-autopairs.lua | 10 +++++----- tests/nvim-autopairs_spec.lua | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lua/nvim-autopairs.lua b/lua/nvim-autopairs.lua index 7afc785..59146bb 100644 --- a/lua/nvim-autopairs.lua +++ b/lua/nvim-autopairs.lua @@ -269,11 +269,11 @@ M.autopairs_map = function(bufnr, char) -- log.debug('prev_char' .. prev_char) -- log.debug('next_char' .. next_char) if - next_char == rule.end_pair - and rule.is_regex == false + utils.is_equal(rule.end_pair, next_char, rule.is_regex) and rule:can_move(cond_opt) then - return utils.esc(utils.key.join_right) + local end_pair = rule:get_end_pair(cond_opt) + return utils.esc(utils.repeat_key(utils.key.join_right, #end_pair)) end if utils.is_equal(rule.start_pair, prev_char, rule.is_regex) @@ -281,8 +281,8 @@ M.autopairs_map = function(bufnr, char) then local end_pair = rule:get_end_pair(cond_opt) if add_char == 0 then char = "" end - return utils.esc( - char .. end_pair .. utils.repeat_key(utils.key.join_left, #end_pair)) + return utils.esc(char .. end_pair + .. utils.repeat_key(utils.key.join_left, #end_pair)) end end end diff --git a/tests/nvim-autopairs_spec.lua b/tests/nvim-autopairs_spec.lua index 4df059f..31b892e 100644 --- a/tests/nvim-autopairs_spec.lua +++ b/tests/nvim-autopairs_spec.lua @@ -386,5 +386,30 @@ describe('autopairs ', function() after = [[((|)))) ]], }, } + + Test(run_data) + + npairs.setup({}) + npairs.add_rules { + Rule(' ', ' '):with_pair(function(opts) + local pair = opts.line:sub(opts.col, opts.col + 1) + return vim.tbl_contains({'()', '[]', '{}'}, pair) + end), + Rule('( ',' )') + :with_pair(function() return false end) + :with_del(function() return false end) + :with_move(function() return true end) + :use_regex(false,")") + } + run_data={ + { + name = "test disable check bracket line" , + filetype = "latex", + key = [[)]], + before = [[( | ) ]], + after = [[( )| ]], + }, + } + Test(run_data) end)