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

disable if cursor is not at the end of the input line #343

Closed
vaeth opened this issue Jun 18, 2018 · 8 comments
Closed

disable if cursor is not at the end of the input line #343

vaeth opened this issue Jun 18, 2018 · 8 comments

Comments

@vaeth
Copy link
Contributor

vaeth commented Jun 18, 2018

If the cursor is not at the end of the input line, the suggestions are written at the end of the line anyway.
This is confusing (and has strange side effects if the suggestion should be accepted).

It would of course be nice if the suggestion could be inserted at the cursor position.
If this is technically not possible or too hard to implement (as I suspect), I suggest to temporarily switch off the suggestions if the cursor is not at the end of the input line.

@vaeth
Copy link
Contributor Author

vaeth commented Jul 2, 2018

But fish will show this suggestion at the end of the line?
The problem is that then accepting this suggestion gives you a nonsense command.

@ericfreese
Copy link
Member

In the case described on the PR, the buffer would be "dock" after typing the "o", the suggestion would add "er" to the end of it. Pressing ^E twice accepts the "er" and leaves the buffer as "docker".

@ericfreese
Copy link
Member

Do you have an example that produces a nonsense command?

@vaeth
Copy link
Contributor Author

vaeth commented Jul 2, 2018

Assume that $PWD=/

Typing ls / /[cursor left][cursor left]b suggests ls /b /ls /bin/ /
Typing ls[space][cursor left][space] suggests ls ls bin/
Typing ls /[cursor left][cursor left][space] suggests ls /ls bin/ /

The problem is that the suggestion in such a case should be at the end of the word of the current cursor (which in the last due examples due to the "space" happens to be the empty word) and not at the end of the line. Of course, inserting suggestions in the middle of the line would be better, but this is very hard to implement. IMHO it is better to not produce them than to insert them in the wrong place.

@vaeth
Copy link
Contributor Author

vaeth commented Jul 2, 2018

You are right: My patch is not correct: It should test whether the cursor is in the last word of the line, not in the last position.

ericfreese added a commit that referenced this issue Jul 2, 2018
To prevent the suggestion from not starting with the buffer string.

Example:

`ls / /[cursor left][cursor left]b`

Before the patch, suggests `ls /b /ls /bin/ /`

After the patch, suggests `ls /b /bin/`.

#343 (comment)
@ericfreese
Copy link
Member

Thanks for those examples. I hadn't considered those cases. I've pushed another commit to #350 that moves the cursor to the end of the buffer in the completion pseudoterminal to ensure that completions are only generated at the end of the buffer. Let me know if that solves the issue for you.

I've come across another similar issue and I'm not sure how to solve it. Typing ls "/" results in a suggestion of ls "/"ls "/bin". The issue seems to be that pressing tab after a quoted string moves your cursor to the end of the string in the quote and fetches completions there. Do you have any idea how to prevent this behavior? I may end up asking on the mailing list since I haven't come up with anything browsing through the docs for completion-related options and zstyles.

@vaeth
Copy link
Contributor Author

vaeth commented Jul 2, 2018

It works perfectly now.

I can confirm that pressing tab in a quoted string replaces the cursor, and I also did not find a zle setting to change this behaviour. Probably it is really best to ask on the ML.

ericfreese added a commit that referenced this issue Jul 2, 2018
To prevent the suggestion from not starting with the buffer string.

Example:

`ls / /[cursor left][cursor left]b`

Before the patch, suggests `ls /b /ls /bin/ /`

After the patch, suggests `ls /b /bin/`.

#343 (comment)
@ericfreese
Copy link
Member

Ok I'm going to go ahead and close this ticket and open a new one for the issue described in my last comment.

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