From fee404399adcebc0c6253e2ef4dc95871f81c806 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 27 Aug 2017 02:19:39 +0900 Subject: Make --expect additive Similarly to --bind or --color. --expect used to replace the previously specified keys, and fzf#wrap({'options': '--expect=f1'}) wouldn't work as expected. It forced us to come up with some ugly hacks like the following: https://github.com/junegunn/fzf.vim/blob/13b27c45c8bdf6c3a41376bb83e4895edadf8c7e/autoload/fzf/vim.vim#L1086 --- src/options.go | 8 ++++++-- src/options_test.go | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/options.go b/src/options.go index afd46b9e..e2f33f81 100644 --- a/src/options.go +++ b/src/options.go @@ -962,7 +962,9 @@ func parseOptions(opts *Options, allArgs []string) { case "--algo": opts.FuzzyAlgo = parseAlgo(nextString(allArgs, &i, "algorithm required (v1|v2)")) case "--expect": - opts.Expect = parseKeyChords(nextString(allArgs, &i, "key names required"), "key names required") + for k, v := range parseKeyChords(nextString(allArgs, &i, "key names required"), "key names required") { + opts.Expect[k] = v + } case "--no-expect": opts.Expect = make(map[int]string) case "--tiebreak": @@ -1140,7 +1142,9 @@ func parseOptions(opts *Options, allArgs []string) { } else if match, value := optString(arg, "--toggle-sort="); match { parseToggleSort(opts.Keymap, value) } else if match, value := optString(arg, "--expect="); match { - opts.Expect = parseKeyChords(value, "key names required") + for k, v := range parseKeyChords(value, "key names required") { + opts.Expect[k] = v + } } else if match, value := optString(arg, "--tiebreak="); match { opts.Criteria = parseTiebreak(value) } else if match, value := optString(arg, "--color="); match { diff --git a/src/options_test.go b/src/options_test.go index d3c93450..22f4e4ee 100644 --- a/src/options_test.go +++ b/src/options_test.go @@ -414,3 +414,10 @@ func TestPreviewOpts(t *testing.T) { t.Error(opts.Preview) } } + +func TestAdditiveExpect(t *testing.T) { + opts := optsFor("--expect=a", "--expect", "b", "--expect=c") + if len(opts.Expect) != 3 { + t.Error(opts.Expect) + } +} -- cgit v1.2.3