disable add bracket after quote with comma

This commit is contained in:
windwp 2021-06-05 13:57:28 +07:00
parent 4b4ac6099d
commit b09ab7495e
2 changed files with 29 additions and 13 deletions

View File

@ -404,7 +404,7 @@ end
--- add bracket pairs after quote (|"aaaaa" => (|"aaaaaa")
M.autopairs_afterquote = function(line, key_char)
if M.config.enable_afterquote then
if M.config.enable_afterquote then
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)
@ -412,26 +412,34 @@ M.autopairs_afterquote = function(line, key_char)
utils.is_bracket(prev_char)
and utils.is_quote(next_char)
and not utils.is_in_quote(line, col, next_char)
then
local is_prev_slash = false
for i = col + 2 + #next_char, #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
then
local is_prev_slash = false
for i = col + 2 + #next_char, #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
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)
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)
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
is_prev_slash = char == '\\'
end
is_prev_slash = char == '\\'
end
end
end
return utils.esc(key_char)
end

View File

@ -64,7 +64,6 @@ local data = {
},
{
-- only=true,
name = 'test add close quote inside string',
filepath = './tests/endwise/init.lua',
filetype = 'lua',
@ -73,6 +72,15 @@ local data = {
before = [[const abc="visu|"dsa"" ]],
after = [[const abc="visu(|"dsa"" ]],
},
{
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)