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 select + motion or visual select #477

Open
marekzidek opened this issue Oct 3, 2020 · 10 comments · Fixed by #1101
Open

Add select + motion or visual select #477

marekzidek opened this issue Oct 3, 2020 · 10 comments · Fixed by #1101

Comments

@marekzidek
Copy link

marekzidek commented Oct 3, 2020

Feature I am often using in other file managers is to e.g. sort by date and then select everything from a date to bottom, or everything from a date to top. (In gui file manages, this is done by select and then shift click.)

Right now, Space select is working one by one and automatically goes downwards if held. I'd like to add a feature for e.g. Shift+Space or whatever to enter something like a visual mode and select ranges with motion keys (without disturbing any other previous selections by single Space/e.g. Shift+Space hits)

Is this something interesting for a pull request? Has this been tried, tackled with or rejected? I tried filtering out all issues by "select/visual" but found nothing similar. Or are we not interested in this and I should try in my own fork? Anyhow, I'd be happy if someone pointed me out to the right direction as I'm quite new to Go :)

@gokcehan
Copy link
Owner

gokcehan commented Oct 6, 2020

@marekzidek Sorry for late reply and thank you for your interest in contributing.

I don't think we have such a feature discussion before. It seems like there is already a usecase for this so I would be interested to see a pull request about this. Go is an easy language and if you know programming you should be able to pick it up easily. The feature itself might be more difficult to implement. My initial guess is that you should first implement a modal command to change the operation mode to visual mode as you say. And then you should check this operation mode in various movement commands to toggle selections of relevant file.

Feel free to shoot your questions here if you decide to work on this and I can try my best to guide you.

kmarius added a commit to kmarius/lf that referenced this issue Nov 21, 2020
kmarius added a commit to kmarius/lf that referenced this issue Dec 30, 2020
@lefuturiste
Copy link

It seems like @kmarius have worked on this feature, what's the next steps if we want to see this feature merged?

@kmarius
Copy link
Contributor

kmarius commented Jul 18, 2022

@lefuturiste I can create a PR soon-ish (maintainer seems quite busy anyway), there are still some open questions regarding e.g. how this should behave with wrapscroll etc. Other than that it works as expected.

@navakelvin
Copy link

@lefuturiste I can create a PR soon-ish (maintainer seems quite busy anyway), there are still some open questions regarding e.g. how this should behave with wrapscroll etc. Other than that it works as expected.

Excuse me sir, this was finally implemented?

@ilyagr
Copy link
Collaborator

ilyagr commented Feb 3, 2023

One approach would be to implement a command to "invert selection below the cursor", which would invert the selection status of every file at or below the cursor.

This would give most of the benefits of visual selection. To select a contiguous subset of files, you'd use this command on then first file you want to select. Then, you'd move down to the first file you do not want to select (the one after the end of the desired selection) and use the same command again. It would work in the opposite order as well (selecting the file after the last one you'd like to select, and then the first file of the selection).

One thing I'm unsure about is what key to assign to such a command, but I'm sure we'll find some. Update: I think it could simply be -. Some other seemingly available possibilities are _, `, ~.

Update 2: Inverting all files is currently bound to v. So, V might be a better binding for this command. It could be called invert-down. I'd personally prefer - and _ or ` and ~, but I don't think that's important enough to change the v binding now.

ilyagr added a commit to ilyagr/lf that referenced this issue Feb 3, 2023
This command inverts the selection for the current file and all the files below
it. Using this command twice substitutes for having a "visual" mode. This is
described in more detail in the docs and in
gokcehan#477 (comment).

Since `invert` is bound to `v` by default, `invert-below` gets `V` as a default
binding.

Fixes gokcehan#477
ilyagr added a commit to ilyagr/lf that referenced this issue Feb 3, 2023
This command inverts the selection for the current file and all the files below
it. Using this command twice substitutes for having a "visual" mode. This is
described in more detail in the docs and in
gokcehan#477 (comment).

Since `invert` is bound to `v` by default, `invert-below` gets `V` as a default
binding.

Fixes gokcehan#477. While that's not exactly what was asked for, I hope it's a suitable
replacement and seems more in the spirit of `lf`.
@ilyagr
Copy link
Collaborator

ilyagr commented Feb 12, 2023

I would appreciate it if people tried out #1101 and saw whether it works for them or if it's too confusing.

@ilyagr
Copy link
Collaborator

ilyagr commented Feb 15, 2023

I thought of an alternative design that might be more intuitive than #1101 and still relatively simple. I am not sure how motivated I am to implement it, though.

We could have a set-anchor command that marks the current file with an anchor. An anchor is like a tag, but is local to the current instance of lf and only one file can have an anchor (so, when you set an anchor, the old anchor is gone). It could be marked with @ (perhaps we forbid tags with that name).

Then, we would have a select-to-anchor command that selects all files between the current cursor position and the anchor. I am not sure what it should do if some files are already selected, it could keep that selection (this is probably the better option, on second thought) or it could invert the selection (that could also be a separate invert-to-anchor command if there's a use for it). We might want a separate unselect-to-anchor command.

These could be mapped to ` and ~ or a and A.

One outstanding issue is whether to have a command to remove the anchor. I'm not sure whether it's convenient to do that on :clear since the user might want to immediately create a new selection with the same anchor. It could also be fine.

Later, this could evolve further towards looking like a visual mode, but this halfway point might be easier to get to.

@DusanLesan
Copy link

@ilyagr I really like that idea. I would like existing selections to remain and toggle command for setting/removing the anchor.
Users could chain together anchor and select toggles so last selected file is a anchor.

gokcehan pushed a commit that referenced this issue Feb 25, 2023
This command inverts the selection for the current file and all the files below
it. Using this command twice substitutes for having a "visual" mode. This is
described in more detail in the docs and in
#477 (comment).

Fixes #477. While that's not exactly what was asked for, I hope it's a suitable
replacement and seems more in the spirit of `lf`, at least until a better
replacement is implemented.
@ilyagr
Copy link
Collaborator

ilyagr commented Feb 25, 2023

@gokcehan I think this should be reopened. I should've modified the commit message so that it didn't auto-close this.

@gokcehan gokcehan reopened this Feb 26, 2023
@laktak
Copy link
Contributor

laktak commented Jul 13, 2023

Not sure if this helps but Visidata (which is excellent btw) solves this with several commands:

   Row Selection
       s   t   u      select/toggle/unselect current row
      gs  gt  gu      select/toggle/unselect all rows
      zs  zt  zu      select/toggle/unselect all rows from top to cursor
     gzs gzt gzu      select/toggle/unselect all rows from cursor to bottom
      |   \ regex     select/unselect rows matching regex in current column
     g|  g\ regex     select/unselect rows matching regex in any visible column
...

https://www.visidata.org/man/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants