From 64c937940c2d890bd192a56e1a831e378fe0168b Mon Sep 17 00:00:00 2001 From: windwp Date: Sun, 6 Jun 2021 14:46:37 +0700 Subject: [PATCH] fix after quote with double character --- lua/nvim-autopairs.lua | 29 +++++++++++++++-------------- tests/afterquote_spec.lua | 9 +++++++++ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/lua/nvim-autopairs.lua b/lua/nvim-autopairs.lua index 259efed..d3bd320 100644 --- a/lua/nvim-autopairs.lua +++ b/lua/nvim-autopairs.lua @@ -417,21 +417,22 @@ M.autopairs_afterquote = function(line, key_char) local char = line:sub(i, i + #next_char - 1) local char_end = line:sub(i + 1, i + #next_char) if not is_prev_slash and char == next_char then - if char_end ~= ',' then - for _, rule in pairs(M.state.rules) do - if rule.start_pair == prev_char and char_end ~= rule.end_pair then - local new_text = line:sub(0, i) - .. rule.end_pair - .. line:sub(i + 1, #line) - M.state.expr_quote = new_text - local append = 'a' - if col > 0 then - append = 'la' - end - return utils.esc( - 'lua MPairs.autopairs_closequote_expr()' .. append - ) + if char_end == ',' then + return utils.esc(key_char) + end + for _, rule in pairs(M.state.rules) do + if rule.start_pair == prev_char and char_end ~= rule.end_pair then + local new_text = line:sub(0, i) + .. rule.end_pair + .. line:sub(i + 1, #line) + M.state.expr_quote = new_text + local append = 'a' + if col > 0 then + append = 'la' end + return utils.esc( + 'lua MPairs.autopairs_closequote_expr()' .. append + ) end end end diff --git a/tests/afterquote_spec.lua b/tests/afterquote_spec.lua index 488c85d..5c4db10 100644 --- a/tests/afterquote_spec.lua +++ b/tests/afterquote_spec.lua @@ -81,6 +81,15 @@ local data = { before = [[|"data", abcdef]], after = [[(|"data", abcdef]], }, + { + name = 'not add bracket with quote have comma', + filepath = './tests/endwise/init.lua', + filetype = 'lua', + linenr = '5', + key = [[(]], + before = [[|"data", "abcdef"]], + after = [[(|"data", "abcdef"]], + }, } local run_data = _G.Test_filter(data)