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

Enable multi-select #124

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

Conversation

gpanders
Copy link
Contributor

@gpanders gpanders commented Oct 14, 2019

This enables multi-select in fzy with the Ctrl+t key. Pressing Ctrl+t on an item will make that item bold. Pressing Ctrl+t will de-select it. When at least one item is multi-selected, pressing the Return key will print each multi-selected item on its own line to stdout (this mimics the behavior of fzf's multi-select feature).

EDIT: Updated the key binding to Ctrl+t.

@maximbaz
Copy link

Nice work! I only want to point out that Ctrl-s is an unfortunate shortcut, because pressing Ctrl-s makes my terminal hang (and requires pressing Ctrl-q to unblock it). While searching for what's going on I discovered that running stty -ixon disables the "hang" functionality and therefore allows fzy to intercept and react on pressing Ctrl-s, but given that many people would probably stumble upon this issue as well, maybe we can choose a more "friendly" default shortcut.

@gpanders
Copy link
Contributor Author

gpanders commented Oct 15, 2019 via email

@maximbaz
Copy link

I would probably vote for Ctrl+Space as it's easier to type, but Ctrl+t sounds OK too.

Have you considered moving the selection down when you press the "select" shortcut? So that when you run echo 'a\nb\nc\nd' | ./fzy pressing Ctrl+Space three times would select a, b and c?

@maximbaz
Copy link

maximbaz commented Oct 15, 2019

Here's a small bug I discovered:

  1. Run echo 'a\nb\nc\nd' | ./fzy
  2. Type aa<Ctrl-s><Backspace><Enter>
[1]    566797 done                              echo 'a\nb\nc\nd' | 
       566798 segmentation fault (core dumped)  ./fzy

@gpanders
Copy link
Contributor Author

gpanders commented Oct 15, 2019 via email

@maximbaz
Copy link

I was on master but I switched to multiselect branch and still can reproduce this every time

@maximbaz
Copy link

What is printed for you in this case, aa?

@gpanders
Copy link
Contributor Author

gpanders commented Oct 15, 2019 via email

@maximbaz
Copy link

Thanks, with the latest code everything works well now, and I love how Ctrl-t scrolls and even wraps to the first entry when you select the last one 👍

Great job!

Default multi-select key is Ctrl+s
Allocate memory for the multiselect buffer in chunks, similar to how the
`choices` buffer is resized. This results in potentially more unused
(i.e. wasted) memory, but in fewer invocations of `malloc`/`realloc`,
which is probably more important, considering the size of the
multiselect array will never be that large.
@ghost

This comment has been minimized.

@alexchomiak
Copy link

@jhawthorn

Any update on when/if this will be pushed into master? This is a great feature.

@Soundtoxin
Copy link

Why was C-t chosen over the tab key (what fzf uses)?

@unrealapex
Copy link

Using Tab would cause a conflict because it is bound to replace the current search string with the selected item.

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.

5 participants