diff --git a/lua/nvim-autopairs/conds.lua b/lua/nvim-autopairs/conds.lua index 9e98987..7098ab0 100644 --- a/lua/nvim-autopairs/conds.lua +++ b/lua/nvim-autopairs/conds.lua @@ -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 diff --git a/lua/nvim-autopairs/utils.lua b/lua/nvim-autopairs/utils.lua index 8b0951d..242fd43 100644 --- a/lua/nvim-autopairs/utils.lua +++ b/lua/nvim-autopairs/utils.lua @@ -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 diff --git a/tests/nvim-autopairs_spec.lua b/tests/nvim-autopairs_spec.lua index 3383ae2..ba6953d 100644 --- a/tests/nvim-autopairs_spec.lua +++ b/tests/nvim-autopairs_spec.lua @@ -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)