Skip to content

Commit

Permalink
fix after quote with double character
Browse files Browse the repository at this point in the history
  • Loading branch information
windwp committed Jun 6, 2021
1 parent 93f8b9f commit 64c9379
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
29 changes: 15 additions & 14 deletions lua/nvim-autopairs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<esc><cmd>lua MPairs.autopairs_closequote_expr()<cr>' .. 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(
'<esc><cmd>lua MPairs.autopairs_closequote_expr()<cr>' .. append
)
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions tests/afterquote_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 64c9379

Please sign in to comment.