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

Cancel object indent selection on lines with no indentation #1904

Closed
aver-d opened this issue Mar 4, 2018 · 3 comments
Closed

Cancel object indent selection on lines with no indentation #1904

aver-d opened this issue Mar 4, 2018 · 3 comments

Comments

@aver-d
Copy link
Contributor

aver-d commented Mar 4, 2018

When on a line with no indentation, currently the entire buffer is selected with the commands <a-a>i and <a-i>i.

It's fairly easy to accidentally select the entire buffer, and I don't recall ever having the intention to use <a-a>i or <a-i>i in this way. % or %_ seem more obvious.

I wonder if an improved default behaviour would be to show the "no selections remaining" message in the event of the indentation level being zero.

There's maybe also a logical intuition that at the left-most area of the buffer there is no indentation to select, and the command can therefore be considered invalid.

@Delapouite
Copy link
Contributor

I find this problem a bit related to the umbrella topic of "undoing selections": #898 . In this kind of "oops" moment that is <a-i>i on col 0, it should be easy to go back to the previous selections list.

@mawww
Copy link
Owner

mawww commented Mar 24, 2018

I agree with Delapouite on this one. I think <a-i>i on base identation is doing the right thing (it does select that identation level, and it so happens to be the whole buffer). The real problem is getting back to the previous selection when this was not intended.

I suspect that the bug you are experiencing is a different one though:

func():
    first line
    second line

    fourth line

When the cursor is on what could be called 'third line', selecting indentation selects the whole buffer, when it should select first to fourth line (leaving func() alone). This is a bug in the indent selector.

Is that the actual bug you are hitting ?

@aver-d
Copy link
Contributor Author

aver-d commented Mar 25, 2018

Actually, no, not related to any bug – just a general thought about this text object's behaviour, and a thought more pragmatic than philosophical.

Object indent is a good friend of mine, but I don't find the zero indent useful for selecting the entire buffer. A more likely scenario would be the problem of regaining my previous position and focus after seeing the cursor suddenly jump to the end of the buffer.

I thought I might not be the only person who found this behaviour unhelpful (and possibly confusing to new users), so I raised the topic as a suggestion for an alternative default.

You both mention this is related to the wider issue of losing selections. In this particular case the selection is conceptually simple, so anyone who wants to solve this "problem" can do so in straightforward way ahead of time:

def object-indent %{
  eval -no-hooks %{
    exec -draft gh <a-k> \h <ret>
    exec <a-i>i
  }
}
map global object i -docstring 'indent' '<esc>:object-indent<ret>'

An error occurs where a line does not begin with whitespace; the selection does not change.

Anyway, I'll now close this issue. Thanks both for your input.

@aver-d aver-d closed this as completed Mar 25, 2018
mawww added a commit that referenced this issue Mar 25, 2018
Look for the first non empty line preceeding the current line, or
if not found, the first non empty line following it.

Fixes #1904
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

3 participants