go-fuzzyfinder icon indicating copy to clipboard operation
go-fuzzyfinder copied to clipboard

Add toggle-all shortcut

Open nicula-stripe opened this issue 8 months ago • 0 comments

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 avatar Jun 10 '24 13:06 nicula-stripe