cliedit: Fix crash when edit:listing:start-custom gets no &accept option.

This commit is contained in:
Qi Xiao 2019-12-14 16:42:17 +00:00
parent edc0e98805
commit 9b4add3b4e
2 changed files with 7 additions and 2 deletions

View File

@ -98,7 +98,9 @@ func listingStartCustom(app cli.App, fm *eval.Frame, opts customListingOpts, ite
return items, selected
},
Accept: func(s string) bool {
callWithNotifyPorts(app, fm.Evaler, opts.Accept, s)
if opts.Accept != nil {
callWithNotifyPorts(app, fm.Evaler, opts.Accept, s)
}
return false
},
AutoAccept: opts.AutoAccept,

View File

@ -114,7 +114,7 @@ func TestCustomListing_PassingValueCallback(t *testing.T) {
evals(f.Evaler,
`f = [q]{ put [&to-accept='q '$q &to-show=(styled 'q '$q blue)] }`,
`edit:listing:start-custom $f &accept=$edit:insert-at-dot~ &caption=A`)
`edit:listing:start-custom $f &caption=A`)
// Query.
f.TTYCtrl.Inject(term.K('x'))
f.TestTTY(t,
@ -124,6 +124,9 @@ func TestCustomListing_PassingValueCallback(t *testing.T) {
"q x ", Styles,
"##################################################",
)
// No-op accept.
f.TTYCtrl.Inject(term.K('\n'))
f.TestTTY(t, "~> ", term.DotHere)
}
func TestCustomListing_PassingBytesCallback(t *testing.T) {