mirror of
https://github.com/ilyakooo0/nvim-autopairs.git
synced 2024-09-11 07:15:44 +03:00
fix: pairs on after quote
This commit is contained in:
parent
150697f4a5
commit
d616b72b05
@ -14,11 +14,11 @@ require('nvim-autopairs').setup()
|
|||||||
## Default values
|
## Default values
|
||||||
|
|
||||||
``` lua
|
``` lua
|
||||||
|
|
||||||
local disable_filetype = { "TelescopePrompt" }
|
local disable_filetype = { "TelescopePrompt" }
|
||||||
local ignored_next_char = string.gsub([[ [%w%%%'%[%"%.] ]],"%s+", "")
|
local ignored_next_char = string.gsub([[ [%w%%%'%[%"%.] ]],"%s+", "")
|
||||||
local enable_moveright = true
|
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
|
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)
|
[autotag](https://github.com/windwp/nvim-ts-autotag)
|
||||||
|
|
||||||
|
@ -400,7 +400,7 @@ M.autopairs_cr = function(bufnr)
|
|||||||
return utils.esc('<cr>')
|
return utils.esc('<cr>')
|
||||||
end
|
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)
|
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)
|
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)
|
local new_text = line:sub(0, i) .. rule.end_pair .. line:sub(i + 1,#line)
|
||||||
M.state.expr_quote = new_text
|
M.state.expr_quote = new_text
|
||||||
local append = "a";
|
local append = "a";
|
||||||
if col > 2 then append = "la" end
|
if col > 0 then append = "la" end
|
||||||
return utils.esc('<esc><cmd>lua MPairs.autopairs_closequote_expr()<cr>' .. append)
|
return utils.esc('<esc><cmd>lua MPairs.autopairs_closequote_expr()<cr>' .. append)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,6 +2,9 @@ local npairs = require('nvim-autopairs')
|
|||||||
|
|
||||||
_G.npairs = npairs
|
_G.npairs = npairs
|
||||||
|
|
||||||
|
npairs.setup({
|
||||||
|
enable_afterquote = true,
|
||||||
|
})
|
||||||
local data = {
|
local data = {
|
||||||
{
|
{
|
||||||
name = 'add bracket after quote ',
|
name = 'add bracket after quote ',
|
||||||
@ -9,8 +12,8 @@ local data = {
|
|||||||
filetype = 'lua',
|
filetype = 'lua',
|
||||||
linenr = 5,
|
linenr = 5,
|
||||||
key = [[(]],
|
key = [[(]],
|
||||||
before = [[const abc=|"visudsa" ]],
|
before = [[const abc=|"test" ]],
|
||||||
after = [[const abc=(|"visudsa") ]],
|
after = [[const abc=(|"test") ]],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name = 'add bracket after quote ',
|
name = 'add bracket after quote ',
|
||||||
@ -18,10 +21,19 @@ local data = {
|
|||||||
filetype = 'lua',
|
filetype = 'lua',
|
||||||
linenr = 5,
|
linenr = 5,
|
||||||
key = [[(]],
|
key = [[(]],
|
||||||
before = [[|"visudsa" ]],
|
before = [[|"test" ]],
|
||||||
after = [[(|"visudsa") ]],
|
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 ',
|
name = 'add bracket after quote ',
|
||||||
filepath = './tests/endwise/init.lua',
|
filepath = './tests/endwise/init.lua',
|
||||||
|
Loading…
Reference in New Issue
Block a user