Skip to content

Commit

Permalink
fix: pair on afterquote
Browse files Browse the repository at this point in the history
  • Loading branch information
windwp committed Jul 29, 2021
1 parent 1df216e commit ad40d49
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
44 changes: 23 additions & 21 deletions lua/nvim-autopairs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -427,38 +427,40 @@ 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(
'<esc><cmd>lua MPairs.autopairs_closequote_expr()<cr>' .. append
)
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(
'<esc><cmd>lua MPairs.autopairs_closequote_expr()<cr>' .. append
)
end
end
is_prev_slash = char == '\\'
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion tests/afterquote_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ local data = {
linenr = '5',
key = [[(]],
before = [[|"data", "abcdef"]],
after = [[(|"data", "abcdef")]],
after = [[(|"data", "abcdef"]],
},
}

Expand Down

0 comments on commit ad40d49

Please sign in to comment.