Skip to content

Commit

Permalink
Add exclude-current action
Browse files Browse the repository at this point in the history
  • Loading branch information
junegunn committed Feb 9, 2025
1 parent 67dd7e1 commit 1be1991
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 12 deletions.
1 change: 1 addition & 0 deletions man/man1/fzf.1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions src/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ const (
actHideHeader
actBell
actExclude
actExcludeCurrent
)

func (a actionType) Name() string {
Expand Down Expand Up @@ -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:
Expand Down
81 changes: 69 additions & 12 deletions test/test_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1669,23 +1669,80 @@ def test_abort_action_chain
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
Expand Down

0 comments on commit 1be1991

Please sign in to comment.