From 1df216ef70e26b0cac8d8326121ad93991d46266 Mon Sep 17 00:00:00 2001 From: windwp Date: Wed, 28 Jul 2021 15:20:41 +0700 Subject: [PATCH] fix: afterquote quote with out any text --- lua/nvim-autopairs.lua | 2 ++ tests/afterquote_spec.lua | 15 ++++++++++++--- tests/endwise/init.lua | 3 +-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lua/nvim-autopairs.lua b/lua/nvim-autopairs.lua index 0fbee75..087a89e 100644 --- a/lua/nvim-autopairs.lua +++ b/lua/nvim-autopairs.lua @@ -427,10 +427,12 @@ 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 is_prev_slash = false for i = #line - 2, #line, 1 do diff --git a/tests/afterquote_spec.lua b/tests/afterquote_spec.lua index 3e6eff3..44913fb 100644 --- a/tests/afterquote_spec.lua +++ b/tests/afterquote_spec.lua @@ -22,8 +22,17 @@ local data = { filetype = 'lua', linenr = 5, key = [[(]], - before = [[|"test" ]], - after = [[(|"test") ]], + before = [[|"test"]], + after = [[(|"test")]], + }, + { + name = 'check quote without any text on end similar', + filepath = './tests/endwise/init.lua', + filetype = 'lua', + linenr = 5, + key = [[(]], + before = [[ const [template, setTemplate] = useState|'')]], + after = [[ const [template, setTemplate] = useState(|'')]], }, { @@ -98,6 +107,6 @@ local run_data = _G.Test_filter(data) local _, ts_utils = pcall(require, 'nvim-treesitter.ts_utils') _G.TU = ts_utils -describe('[endwise tag]', function() +describe('[afterquote tag]', function() _G.Test_withfile(run_data, {}) end) diff --git a/tests/endwise/init.lua b/tests/endwise/init.lua index cc5476a..15adc1d 100644 --- a/tests/endwise/init.lua +++ b/tests/endwise/init.lua @@ -1,8 +1,7 @@ local data1, data2 local function wind() - - + vim.api.nvim_get_current_buf()