Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toggle-all shortcut #219

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

nicula-stripe
Copy link

Summary

This PR does the following:

  • Adds a shortcut on Ctrl+T which toggles (selects/unselects) all items in the list. Also, some tests for this feature are added.
  • When in multi-select mode, the number of selected items is printed on the line with the fuzzyfinder result count (to avoid confusion regarding what is selected).

Tests

In order for the tests of this feature to work, I've had to update the version of tcell to v2.7.4.

With the old version (v2.6.0), the test reaches a deadlock when testing the multi-select functionality with many KeyUps followed by some KeyTabs. To reproduce, apply the following patch on a clean master:

diff --git a/fuzzyfinder_test.go b/fuzzyfinder_test.go
index a5f2102..51d8246 100644
--- a/fuzzyfinder_test.go
+++ b/fuzzyfinder_test.go
@@ -614,8 +614,19 @@ func TestFindMulti(t *testing.T) {
 	}{
 		"input glow": {events: runes("glow"), expected: []int{0}},
 		"select two items": {events: keys([]input{
-			{tcell.KeyTab, rune(tcell.KeyTab), tcell.ModNone},
 			{tcell.KeyUp, rune(tcell.KeyUp), tcell.ModNone},
+			{tcell.KeyUp, rune(tcell.KeyUp), tcell.ModNone},
+			{tcell.KeyUp, rune(tcell.KeyUp), tcell.ModNone},
+			{tcell.KeyUp, rune(tcell.KeyUp), tcell.ModNone},
+			{tcell.KeyUp, rune(tcell.KeyUp), tcell.ModNone},
+			{tcell.KeyUp, rune(tcell.KeyUp), tcell.ModNone},
+			{tcell.KeyUp, rune(tcell.KeyUp), tcell.ModNone},
+			{tcell.KeyUp, rune(tcell.KeyUp), tcell.ModNone},
+			{tcell.KeyUp, rune(tcell.KeyUp), tcell.ModNone},
+			{tcell.KeyUp, rune(tcell.KeyUp), tcell.ModNone},
+			{tcell.KeyTab, rune(tcell.KeyTab), tcell.ModNone},
+			{tcell.KeyTab, rune(tcell.KeyTab), tcell.ModNone},
+			{tcell.KeyTab, rune(tcell.KeyTab), tcell.ModNone},
 			{tcell.KeyTab, rune(tcell.KeyTab), tcell.ModNone},
 		}...), expected: []int{0, 1}},
 		"select two items with another order": {events: keys([]input{

And then run go test -c && ./go-fuzzyfinder.test. You'll notice:

fatal error: all goroutines are asleep - deadlock!
...

@nicula-stripe nicula-stripe force-pushed the nicula/add-toggle-all branch from 81d924d to 68cbe26 Compare June 28, 2024 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant