diff --git a/autoload/gyoza/applier.vim b/autoload/gyoza/applier.vim index 9006f36..fa9f73f 100644 --- a/autoload/gyoza/applier.vim +++ b/autoload/gyoza/applier.vim @@ -19,7 +19,7 @@ function gyoza#applier#trigger_applicant(all_rules) abort return endif - let s:rule_stack = a:all_rules->copy()->filter('prevline =~# v:val.pattern') + let s:rule_stack = a:all_rules->deepcopy()->filter('prevline =~# v:val.pattern') let s:cursor_text = getline('.')[col('.') - 1 :] inoremap (_gyoza_apply) do_apply() diff --git a/test/applier.vimspec b/test/applier.vimspec index 562d309..807b9ed 100644 --- a/test/applier.vimspec +++ b/test/applier.vimspec @@ -435,6 +435,21 @@ Describe Applier class \.run() End + It forgets kept text on next application when rule is defined with a function. + let rules = NewConfig().add_rule('^\s*if', {lines -> + \ {'pair': 'endif', 'cursor_text': lines.current}})._rules + call setline(1, 'iffoo') + call NewScripter() + \.feedkeys('^la') + \.call({-> gyoza#applier#trigger_applicant(rules)}) + \.call({-> s:assert.equals(GetAllLines(), ['if', "\tfoo", 'endif'])}) + \.feedkeys('Goif') + \.call({-> gyoza#applier#trigger_applicant(rules)}) + \.call({-> s:assert.equals(GetAllLines(), ['if', "\tfoo", 'endif', 'if', "\t", 'endif'])}) + \.call({-> s:assert.equals(GetCurpos(), [5, 2])}) + \.run() + End + It completes pair when block is nested. let rules = NewConfig() \.add_rule('^\s*if\>', 'endif')