mirror of
https://github.com/junegunn/fzf.git
synced 2026-03-01 21:07:08 +08:00
Empty change-with-nth restores the default --with-nth value
Previously, change-with-nth() with an empty value cleared with-nth entirely. Now it restores the original --with-nth expression, matching the convention used by change-nth.
This commit is contained in:
@@ -340,6 +340,7 @@ type Terminal struct {
|
|||||||
nthAttr tui.Attr
|
nthAttr tui.Attr
|
||||||
nth []Range
|
nth []Range
|
||||||
nthCurrent []Range
|
nthCurrent []Range
|
||||||
|
withNthDefault string
|
||||||
withNthExpr string
|
withNthExpr string
|
||||||
withNthEnabled bool
|
withNthEnabled bool
|
||||||
acceptNth func([]Token, int32) string
|
acceptNth func([]Token, int32) string
|
||||||
@@ -1093,6 +1094,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor
|
|||||||
nthAttr: opts.Theme.Nth.Attr,
|
nthAttr: opts.Theme.Nth.Attr,
|
||||||
nth: opts.Nth,
|
nth: opts.Nth,
|
||||||
nthCurrent: opts.Nth,
|
nthCurrent: opts.Nth,
|
||||||
|
withNthDefault: opts.WithNthExpr,
|
||||||
withNthExpr: opts.WithNthExpr,
|
withNthExpr: opts.WithNthExpr,
|
||||||
withNthEnabled: opts.WithNth != nil,
|
withNthEnabled: opts.WithNth != nil,
|
||||||
tabstop: opts.Tabstop,
|
tabstop: opts.Tabstop,
|
||||||
@@ -6386,10 +6388,12 @@ func (t *Terminal) Loop() error {
|
|||||||
if len(tokens) > 1 {
|
if len(tokens) > 1 {
|
||||||
a.a = strings.Join(append(tokens[1:], tokens[0]), "|")
|
a.a = strings.Join(append(tokens[1:], tokens[0]), "|")
|
||||||
}
|
}
|
||||||
|
// Empty value restores the default --with-nth
|
||||||
|
if len(withNthExpr) == 0 {
|
||||||
|
withNthExpr = t.withNthDefault
|
||||||
|
}
|
||||||
if withNthExpr != t.withNthExpr {
|
if withNthExpr != t.withNthExpr {
|
||||||
if len(withNthExpr) == 0 {
|
if factory, err := nthTransformer(withNthExpr); err == nil {
|
||||||
newWithNth = &withNthSpec{fn: nil}
|
|
||||||
} else if factory, err := nthTransformer(withNthExpr); err == nil {
|
|
||||||
newWithNth = &withNthSpec{fn: factory(t.delimiter)}
|
newWithNth = &withNthSpec{fn: factory(t.delimiter)}
|
||||||
} else {
|
} else {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1780,16 +1780,25 @@ class TestCore < TestInteractive
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_change_with_nth_clear
|
def test_change_with_nth_default
|
||||||
tmux.send_keys %(echo -e 'a b c\nd e f' | #{FZF} --with-nth 1 --bind 'space:change-with-nth()'), :Enter
|
# Empty value restores the default --with-nth
|
||||||
|
tmux.send_keys %(echo -e 'a b c\nd e f' | #{FZF} --with-nth 1 --bind 'space:change-with-nth(2|)'), :Enter
|
||||||
tmux.until do |lines|
|
tmux.until do |lines|
|
||||||
assert_equal 2, lines.item_count
|
assert_equal 2, lines.item_count
|
||||||
assert lines.any_include?('a')
|
assert lines.any_include?('a')
|
||||||
refute lines.any_include?('b')
|
refute lines.any_include?('b')
|
||||||
end
|
end
|
||||||
|
# Switch to field 2
|
||||||
tmux.send_keys :Space
|
tmux.send_keys :Space
|
||||||
tmux.until do |lines|
|
tmux.until do |lines|
|
||||||
assert lines.any_include?('a b c')
|
assert lines.any_include?('b')
|
||||||
|
refute lines.any_include?('a')
|
||||||
|
end
|
||||||
|
# Empty restores default (field 1)
|
||||||
|
tmux.send_keys :Space
|
||||||
|
tmux.until do |lines|
|
||||||
|
assert lines.any_include?('a')
|
||||||
|
refute lines.any_include?('b')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user