feat: support undo. fix #162

This commit is contained in:
zztrieuzz 2021-10-19 19:15:25 +07:00
parent df6b61a0c0
commit f9d8914a7c
4 changed files with 18 additions and 3 deletions

View File

@ -431,7 +431,12 @@ M.autopairs_map = function(bufnr, char)
if end_pair:match('<.*>') then
end_pair = utils.esc(end_pair)
end
return char .. end_pair .. utils.esc(move_text)
local result= char .. end_pair .. utils.esc(move_text)
if rule.is_undo then
result = utils.esc(utils.key.undo_sequence) .. result..utils.esc(utils.key.undo_sequence)
end
log.debug("key_map :" .. result)
return result
end
end
end

View File

@ -13,6 +13,7 @@ local log = require('nvim-autopairs._log')
--- @field is_regex boolean use regex to compare
--- @field is_multibyte boolean
--- @field is_endwise boolean only use on end_wise
--- @field is_undo boolean add break undo sequence
local Rule = {}
Rule.__index = Rule
@ -84,6 +85,12 @@ function Rule:use_key(key_map)
return self
end
function Rule:use_undo(value)
if value ~= nil then value = true end
self.is_undo = value
return self
end
function Rule:use_multibyte()
self.is_multibyte = true
self.end_pair_length = vim.fn.strdisplaywidth(self.end_pair)
@ -103,7 +110,7 @@ function Rule:get_map_cr(opts)
if self.map_cr_func then
return self.map_cr_func(opts)
end
return '<cr><c-o>O'
return '<cr><cr><c-g>u<up><c-t>'
end

View File

@ -11,6 +11,7 @@ local function setup(opt)
if #opt.ignored_next_char > 1 then
rule:with_pair(cond.not_after_regex_check(opt.ignored_next_char))
end
rule:use_undo(true)
return rule
end

View File

@ -8,7 +8,9 @@ M.key = {
left = "<left>",
right = "<right>",
join_left = "<c-g>U<left>",
join_right = "<c-g>U<right>"
join_right = "<c-g>U<right>",
undo_sequence = "<c-g>u",
noundo_sequence = "<c-g>U"
}
M.set_vchar = function(text)