mirror of
https://github.com/ilyakooo0/nvim-autopairs.git
synced 2024-09-11 07:15:44 +03:00
fix: pair on afterquote
This commit is contained in:
parent
1df216ef70
commit
ad40d49f45
@ -427,26 +427,30 @@ 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)
|
||||
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, i)
|
||||
local new_text = line:sub(0, index)
|
||||
.. rule.end_pair
|
||||
.. line:sub(i + 1, #line)
|
||||
.. line:sub(index + 1, #line)
|
||||
M.state.expr_quote = new_text
|
||||
local append = 'a'
|
||||
if col > 0 then
|
||||
@ -458,8 +462,6 @@ M.autopairs_afterquote = function(line, key_char)
|
||||
end
|
||||
end
|
||||
end
|
||||
is_prev_slash = char == '\\'
|
||||
end
|
||||
end
|
||||
end
|
||||
return utils.esc(key_char)
|
||||
|
@ -98,7 +98,7 @@ local data = {
|
||||
linenr = '5',
|
||||
key = [[(]],
|
||||
before = [[|"data", "abcdef"]],
|
||||
after = [[(|"data", "abcdef")]],
|
||||
after = [[(|"data", "abcdef"]],
|
||||
},
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user