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

commandline --selection-anchor to get/set selection start position #9197

Closed
sshilovsky opened this issue Sep 9, 2022 · 4 comments
Closed

Comments

@sshilovsky
Copy link
Contributor

sshilovsky commented Sep 9, 2022

For example, with the buffer abcdef and selection bcd, with cursor on the right end:

commandline --selection-anchor should output 1;
commandline --selection-anchor 2 should switch selection to cd,
commandline --selection-anchor 3 --cursor 2 should select cd, but also swap the beginning and end of selection to backwards.

UPD fixed: --selection-anchor 3 in the last line example

@faho
Copy link
Member

faho commented Sep 9, 2022

Typically, to change the selection, you would just use one of the bind functions that changes the selection. E.g. you'd press right-arrow or ctrl+b or h or something, or trigger the corresponding bind function via commandline -f.

So, the question is: Why do you want this? What is the idea that you need this for?

@sshilovsky
Copy link
Contributor Author

sshilovsky commented Sep 9, 2022

I'm working on this: https://github.com/sshilovsky/fish-helix (helix-like bindings, helix is a modal editor similar to kakoune (#7748))

I'm trying to reproduce helix behavior as precise as possible, and for some motions this would be very helpful. And some seem to be impossible to implement with existing commands (e.g. Alt-: to ensure that the cursor is on the right end of the selection).

@faho
Copy link
Member

faho commented Sep 9, 2022

Okay, so you want fine-grained control over the selection, and your idea is that you have two ends, the cursor and the "anchor". Moving the cursor moves the one end, and moving the "anchor" moves the other.

I would call it the "selection-start". It might also be useful to accept relative movement as well - something to express "move the start one to the left" or right, without having to first query for the position. This would of course also be useful for the cursor position - it would remove a bunch of your math calls.

E.g. instead of

commandline -C (math max\(0, (commandline -C) - $count\))

just do

commandline -C -1

@sshilovsky
Copy link
Contributor Author

Relative movement would be a nice addition, but it's not the most urgent thing to be honest.

Imho commandline -C -1 feels more like "position to the last character". It also would have made my debugging so far trickier. I feel like a more explicit way for relative positioning would be best; not sure what the syntax should be though.

I agree on --selection-start. It goes along well with {begin,end}-selection commands. Anchor is a term from helix.

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

No branches or pull requests

2 participants