Use replace_endpair when expanding with endwise

This commit is contained in:
Yarden Sod-Moriah 2022-04-20 11:55:39 +03:00 committed by windwp
parent e9b47f0f68
commit 0ebfef16ec
2 changed files with 54 additions and 12 deletions

View File

@ -553,26 +553,32 @@ M.autopairs_cr = function(bufnr)
#rule.end_pair,
rule.is_regex
)
local cond_opt = {
ts_node = M.state.ts_node,
check_endwise_ts = true,
rule = rule,
bufnr = bufnr,
col = col + 1,
line = line,
prev_char = prev_char,
next_char = next_char,
}
local end_pair = rule:get_end_pair(cond_opt)
local end_pair_length = rule:get_end_pair_length(end_pair)
-- log.debug('prev_char' .. rule.start_pair)
-- log.debug('prev_char' .. prev_char)
-- log.debug('next_char' .. next_char)
if
rule.is_endwise
and utils.compare(rule.start_pair, prev_char, rule.is_regex)
and rule:can_cr({
ts_node = M.state.ts_node,
check_endwise_ts = true,
bufnr = bufnr,
rule = rule,
col = col,
prev_char = prev_char,
next_char = next_char,
line = line,
})
and rule:can_cr(cond_opt)
then
return utils.esc(
rule.end_pair
.. utils.repeat_key(utils.key.join_left, #rule.end_pair)
end_pair
.. utils.repeat_key(utils.key.join_left, end_pair_length)
-- FIXME do i need to re indent twice #118
.. '<cr><esc>====O'
)

View File

@ -596,6 +596,42 @@ local data = {
before = [[ | aaa]],
after = [[ "ab| aaa]]
},
{
setup_func = function()
npairs.clear_rules()
npairs.add_rule(Rule("{", "}"):end_wise())
end,
filetype = 'javascript',
name = 'custom endwise rule',
key = [[<cr>]],
before = [[function () {| ]],
after = {
[[function () {]],
[[|]],
[[}]],
},
},
{
setup_func = function()
npairs.clear_rules()
npairs.add_rule(
Rule("{", "")
:replace_endpair(function ()
return "}"
end)
:end_wise()
)
end,
filetype = 'javascript',
name = 'custom endwise rule with custom end_pair',
key = [[<cr>]],
before = [[function () {| ]],
after = {
[[function () {]],
[[|]],
[[}]],
},
},
}
local run_data = _G.Test_filter(data)