Skip to content

Commit

Permalink
Fix rules are overwritten when defined with a function
Browse files Browse the repository at this point in the history
  • Loading branch information
mityu committed Jul 6, 2024
1 parent 6ad6e6a commit 25e11e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion autoload/gyoza/applier.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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 <buffer> <silent> <expr> <Plug>(_gyoza_apply) <SID>do_apply()
Expand Down
15 changes: 15 additions & 0 deletions test/applier.vimspec
Original file line number Diff line number Diff line change
Expand Up @@ -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<CR>')
\.call({-> gyoza#applier#trigger_applicant(rules)})
\.call({-> s:assert.equals(GetAllLines(), ['if', "\tfoo", 'endif'])})
\.feedkeys('<ESC>Goif<CR>')
\.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')
Expand Down

0 comments on commit 25e11e7

Please sign in to comment.