From d616b72b05b2fb573aa6b65323e1fd9d370500c9 Mon Sep 17 00:00:00 2001 From: windwp Date: Mon, 24 May 2021 12:04:37 +0700 Subject: [PATCH] fix: pairs on after quote --- README.md | 6 +++--- lua/nvim-autopairs.lua | 4 ++-- tests/afterquote_spec.lua | 20 ++++++++++++++++---- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index cdb2939..a82c1cc 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,11 @@ require('nvim-autopairs').setup() ## Default values ``` lua - local disable_filetype = { "TelescopePrompt" } local ignored_next_char = string.gsub([[ [%w%%%'%[%"%.] ]],"%s+", "") local enable_moveright = true -local check_ts = false, +local enable_afterquote = true -- add bracket pairs after quote +local check_ts = false ``` @@ -251,7 +251,7 @@ Before Input After require('nvim-autopairs').get_rule('"') -- get rule " then modify it ``` -### autotag html and tsx +### autotag html and tsx [autotag](https://github.com/windwp/nvim-ts-autotag) diff --git a/lua/nvim-autopairs.lua b/lua/nvim-autopairs.lua index 7e61dd5..3e3cc54 100644 --- a/lua/nvim-autopairs.lua +++ b/lua/nvim-autopairs.lua @@ -400,7 +400,7 @@ M.autopairs_cr = function(bufnr) return utils.esc('') end ---- map to auto add pairs on close quote (|"aaaaa" => (|"aaaaaa") +--- add bracket pairs after quote (|"aaaaa" => (|"aaaaaa") M.autopairs_afterquote = function(line, key_char) if M.config.enable_afterquote then line = line or utils.text_get_current_line(0) @@ -417,7 +417,7 @@ M.autopairs_afterquote = function(line, key_char) 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 > 2 then append = "la" end + if col > 0 then append = "la" end return utils.esc('lua MPairs.autopairs_closequote_expr()' .. append) end end diff --git a/tests/afterquote_spec.lua b/tests/afterquote_spec.lua index 9b183bd..fc3b124 100644 --- a/tests/afterquote_spec.lua +++ b/tests/afterquote_spec.lua @@ -2,6 +2,9 @@ local npairs = require('nvim-autopairs') _G.npairs = npairs +npairs.setup({ + enable_afterquote = true, +}) local data = { { name = 'add bracket after quote ', @@ -9,8 +12,8 @@ local data = { filetype = 'lua', linenr = 5, key = [[(]], - before = [[const abc=|"visudsa" ]], - after = [[const abc=(|"visudsa") ]], + before = [[const abc=|"test" ]], + after = [[const abc=(|"test") ]], }, { name = 'add bracket after quote ', @@ -18,10 +21,19 @@ local data = { filetype = 'lua', linenr = 5, key = [[(]], - before = [[|"visudsa" ]], - after = [[(|"visudsa") ]], + before = [[|"test" ]], + after = [[(|"test") ]], }, + { + name = 'add bracket after quote ', + filepath = './tests/endwise/init.lua', + filetype = 'lua', + linenr = 5, + key = [[{]], + before = [[(|"test") ]], + after = [[({|"test"}) ]], + }, { name = 'add bracket after quote ', filepath = './tests/endwise/init.lua',