This commit is contained in:
zztrieuzz 2022-01-12 11:28:39 +07:00
parent 5348e4a778
commit c027bbb7eb
3 changed files with 15 additions and 21 deletions

View File

@ -165,10 +165,9 @@ cond.is_bracket_line = function()
end
end
cond.inside_quote = function()
return function(opts)
log.debug('inside_quote')
log.debug('inside_quote')
return utils.is_in_quotes(opts.text, opts.col - 1)
end
end

View File

@ -45,12 +45,12 @@ end
---check cursor is inside a quote
---@param line string
---@param pos number positin in line
---@param quote nil|string specify a quote string
---@param quote_type nil|string specify a quote
---@return boolean
M.is_in_quotes = function (line, pos, quote)
M.is_in_quotes = function (line, pos, quote_type)
local cIndex = 0
local result = false
local last_char = quote or ''
local last_char = quote_type or ''
while cIndex < string.len(line) and cIndex < pos do
cIndex = cIndex + 1
@ -61,9 +61,11 @@ M.is_in_quotes = function (line, pos, quote)
line:sub(cIndex -1, cIndex -1) ~= "\\"
then
result = false
last_char = quote or ''
elseif result == false and M.is_quote(char) then
last_char = quote or char
last_char = quote_type or ''
elseif result == false and M.is_quote(char)
and (not quote_type or char == quote_type)
then
last_char = quote_type or char
result = true
end
end

View File

@ -162,19 +162,11 @@ local data = {
after = [[("abcd\""|)]]
},
{
name = "move right on close bracket",
filetype="javascript",
key = [[)]],
before = [[("(dsadsa|" gs})]],
after = [[("(dsadsa)|" gs})]]
},
{
name = "move right when inside single quote with special slash",
filetype="javascript",
key = [[']],
before = [[nvim_set_var('test_thing|')]],
after = [[nvim_set_var('test_thing'|)]]
filetype = 'rust',
name = 'move right double quote after single quote',
key = [["]],
before = [[ ('x').expect("|");]],
after = [[ ('x').expect(""|);]],
},
{
name = "delete bracket",
@ -587,6 +579,7 @@ describe('autopairs ', function()
if value.setup_func then
value.setup_func()
end
end,
})
end)