fix: pair on afterquote

This commit is contained in:
windwp 2021-07-29 19:31:23 +07:00
parent 1df216ef70
commit ad40d49f45
2 changed files with 25 additions and 23 deletions

View File

@ -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(
'<esc><cmd>lua MPairs.autopairs_closequote_expr()<cr>' .. 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(
'<esc><cmd>lua MPairs.autopairs_closequote_expr()<cr>' .. append
)
end
end
end
end
end
return utils.esc(key_char)

View File

@ -98,7 +98,7 @@ local data = {
linenr = '5',
key = [[(]],
before = [[|"data", "abcdef"]],
after = [[(|"data", "abcdef")]],
after = [[(|"data", "abcdef"]],
},
}