mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-15 06:43:47 -05:00
Add exclude-current action
https://github.com/junegunn/fzf/pull/4231#issuecomment-2646063208
This commit is contained in:
@@ -1602,6 +1602,7 @@ A key or an event can be bound to one or more of the following actions.
|
||||
\fBenable\-search\fR (enable search functionality)
|
||||
\fBend\-of\-line\fR \fIctrl\-e end\fR
|
||||
\fBexclude\fR (exclude the current item or the selected items from the result)
|
||||
\fBexclude\-current\fR (exclude the current item from the result)
|
||||
\fBexecute(...)\fR (see below for the details)
|
||||
\fBexecute\-silent(...)\fR (see below for the details)
|
||||
\fBfirst\fR (move to the first match; same as \fBpos(1)\fR)
|
||||
|
||||
@@ -1605,6 +1605,8 @@ func parseActionList(masked string, original string, prevActions []*action, putA
|
||||
appendAction(actBell)
|
||||
case "exclude":
|
||||
appendAction(actExclude)
|
||||
case "exclude-current":
|
||||
appendAction(actExcludeCurrent)
|
||||
default:
|
||||
t := isExecuteAction(specLower)
|
||||
if t == actIgnore {
|
||||
|
||||
@@ -585,6 +585,7 @@ const (
|
||||
actHideHeader
|
||||
actBell
|
||||
actExclude
|
||||
actExcludeCurrent
|
||||
)
|
||||
|
||||
func (a actionType) Name() string {
|
||||
@@ -4926,6 +4927,12 @@ func (t *Terminal) Loop() error {
|
||||
}
|
||||
}
|
||||
changed = true
|
||||
case actExcludeCurrent:
|
||||
if item := t.currentItem(); item != nil {
|
||||
denylist = append(denylist, item.Index())
|
||||
t.deselectItem(item)
|
||||
changed = true
|
||||
}
|
||||
case actExecute, actExecuteSilent:
|
||||
t.executeCommand(a.a, false, a.t == actExecuteSilent, false, false, "")
|
||||
case actExecuteMulti:
|
||||
|
||||
@@ -1669,23 +1669,80 @@ class TestCore < TestInteractive
|
||||
def test_exclude
|
||||
tmux.send_keys %(seq 1000 | #{FZF} --multi --bind 'a:exclude,b:reload(seq 1000),c:reload-sync(seq 1000)'), :Enter
|
||||
|
||||
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
||||
tmux.until { |lines| assert_includes lines, '> 1' }
|
||||
tmux.until do |lines|
|
||||
assert_equal 1000, lines.match_count
|
||||
assert_includes lines, '> 1'
|
||||
end
|
||||
tmux.send_keys :a
|
||||
tmux.until { |lines| assert_includes lines, '> 2' }
|
||||
tmux.until { |lines| assert_equal 999, lines.match_count }
|
||||
tmux.until do |lines|
|
||||
assert_includes lines, '> 2'
|
||||
assert_equal 999, lines.match_count
|
||||
end
|
||||
tmux.send_keys :Up, :BTab, :BTab, :BTab, :a
|
||||
tmux.until { |lines| assert_equal 996, lines.match_count }
|
||||
tmux.until { |lines| assert_includes lines, '> 9' }
|
||||
tmux.until do |lines|
|
||||
assert_equal 996, lines.match_count
|
||||
assert_includes lines, '> 9'
|
||||
end
|
||||
tmux.send_keys :b
|
||||
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
||||
tmux.until { |lines| assert_includes lines, '> 5' }
|
||||
tmux.until do |lines|
|
||||
assert_equal 1000, lines.match_count
|
||||
assert_includes lines, '> 5'
|
||||
end
|
||||
tmux.send_keys :Tab, :Tab, :Tab, :a
|
||||
tmux.until { |lines| assert_equal 997, lines.match_count }
|
||||
tmux.until { |lines| assert_includes lines, '> 2' }
|
||||
tmux.until do |lines|
|
||||
assert_equal 997, lines.match_count
|
||||
assert_includes lines, '> 2'
|
||||
end
|
||||
tmux.send_keys :c
|
||||
tmux.until { |lines| assert_equal 1000, lines.match_count }
|
||||
tmux.until { |lines| assert_includes lines, '> 2' }
|
||||
tmux.until do |lines|
|
||||
assert_equal 1000, lines.match_count
|
||||
assert_includes lines, '> 2'
|
||||
end
|
||||
|
||||
# TODO: We should also check the behavior of 'exclude' during reloads
|
||||
end
|
||||
|
||||
def test_exclude_current
|
||||
tmux.send_keys %(seq 1000 | #{FZF} --multi --bind 'a:exclude-current,b:reload(seq 1000),c:reload-sync(seq 1000)'), :Enter
|
||||
|
||||
tmux.until do |lines|
|
||||
assert_equal 1000, lines.match_count
|
||||
assert_includes lines, '> 1'
|
||||
end
|
||||
tmux.send_keys :a
|
||||
tmux.until do |lines|
|
||||
assert_includes lines, '> 2'
|
||||
assert_equal 999, lines.match_count
|
||||
end
|
||||
tmux.send_keys :Up, :BTab, :BTab, :BTab, :a
|
||||
tmux.until do |lines|
|
||||
assert_equal 998, lines.match_count
|
||||
assert_equal 3, lines.select_count
|
||||
assert_includes lines, '> 7'
|
||||
end
|
||||
tmux.send_keys :b
|
||||
tmux.until do |lines|
|
||||
assert_equal 1000, lines.match_count
|
||||
assert_equal 0, lines.select_count
|
||||
assert_includes lines, '> 5'
|
||||
end
|
||||
tmux.send_keys :Tab, :Tab, :Tab, :a
|
||||
tmux.until do |lines|
|
||||
assert_equal 999, lines.match_count
|
||||
assert_equal 3, lines.select_count
|
||||
assert_includes lines, '>>3'
|
||||
end
|
||||
tmux.send_keys :a
|
||||
tmux.until do |lines|
|
||||
assert_equal 998, lines.match_count
|
||||
assert_equal 2, lines.select_count
|
||||
assert_includes lines, '>>4'
|
||||
end
|
||||
tmux.send_keys :c
|
||||
tmux.until do |lines|
|
||||
assert_equal 1000, lines.match_count
|
||||
assert_includes lines, '> 2'
|
||||
end
|
||||
|
||||
# TODO: We should also check the behavior of 'exclude' during reloads
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user