diff --git a/lua/nvim-autopairs.lua b/lua/nvim-autopairs.lua index 087a89e..d3c2aa6 100644 --- a/lua/nvim-autopairs.lua +++ b/lua/nvim-autopairs.lua @@ -427,39 +427,41 @@ M.autopairs_afterquote = function(line, key_char) line = line or utils.text_get_current_line(0) local _, col = utils.get_cursor() local prev_char, next_char = utils.text_cusor_line(line, col + 1, 1, 1, false) - local check_same = line:sub(col + 3, col + 3) if utils.is_bracket(prev_char) and utils.is_quote(next_char) and not utils.is_in_quote(line, col, next_char) - and check_same ~= next_char then + local count = 0 + local index = 0 local is_prev_slash = false - for i = #line - 2, #line, 1 do + local char_end='' + for i = col, #line, 1 do 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 - 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 + count = count + 1 + char_end = line:sub(i + 1, i + #next_char) + index = i end is_prev_slash = char == '\\' end + if count == 2 and index >=(#line -2) 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, index) + .. rule.end_pair + .. line:sub(index + 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 end end return utils.esc(key_char) diff --git a/tests/afterquote_spec.lua b/tests/afterquote_spec.lua index 44913fb..cf4eaea 100644 --- a/tests/afterquote_spec.lua +++ b/tests/afterquote_spec.lua @@ -98,7 +98,7 @@ local data = { linenr = '5', key = [[(]], before = [[|"data", "abcdef"]], - after = [[(|"data", "abcdef")]], + after = [[(|"data", "abcdef"]], }, }