Skip to content

Commit

Permalink
Do not move right when char is not valid for rule (#357)
Browse files Browse the repository at this point in the history
Fixes #331
  • Loading branch information
bew committed May 25, 2023
1 parent 7747bba commit 59df87a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lua/nvim-autopairs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,12 @@ M.autopairs_map = function(bufnr, char)
-- log.debug("start_pair" .. rule.start_pair)
-- log.debug('prev_char' .. prev_char)
-- log.debug('next_char' .. next_char)
if utils.compare(rule.end_pair, next_char, rule.is_regex)
local char_matches_rule = (rule.end_pair == char or rule.key_map == char)
-- for simple pairs, char will match end_pair
-- for more complex pairs, user should map the wanted end char with `use_key`
-- on a dedicated rule
if char_matches_rule
and utils.compare(rule.end_pair, next_char, rule.is_regex)
and rule:can_move(cond_opt)
then
local end_pair = rule:get_end_pair(cond_opt)
Expand Down
30 changes: 30 additions & 0 deletions tests/nvim-autopairs_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,36 @@ local data = {
before = [[("abcd|}} ]],
after = [[("abcd}|} ]]
},
{
-- ref: issue #331
name = "move right, should not move on non-end-pair char: `§|§` with (" ,
setup_func = function()
npairs.add_rule(Rule("§","§"):with_move(cond.done()))
end,
key = [[(]],
before = [[§|§]],
after = [[§(|)§]]
},
{
-- ref: issue #331
name = "move right, should not move on non-end-pair char: `#|#` with \"" ,
setup_func = function()
npairs.add_rule(Rule("#","#"):with_move(cond.done()))
end,
key = [["]],
before = [[#|#]],
after = [[#"|"#]]
},
{
-- ref: issue #331 and #330
name = "move right, should not move on non-end-pair char: `<|>` with (" ,
setup_func = function()
npairs.add_rule(Rule("<",">"):with_move(cond.done()))
end,
key = [[(]],
before = [[<|>]],
after = [[<(|)>]],
},
{
name = "move right when inside grave with special slash" ,
key = [[`]],
Expand Down

0 comments on commit 59df87a

Please sign in to comment.