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

Allow scrolling past the main cursor in the view mode #3128

Closed
alexherbo2 opened this issue Oct 9, 2019 · 6 comments · Fixed by #3231
Closed

Allow scrolling past the main cursor in the view mode #3128

alexherbo2 opened this issue Oct 9, 2019 · 6 comments · Fixed by #3231

Comments

@alexherbo2
Copy link
Contributor

https://discuss.kakoune.com/t/view-mode-movement/745/4

@Delapouite
Copy link
Contributor

Strongly related to #2844

@FlyingWombat
Copy link

So, do you think the view should push the cursor? Or should the cursor stay put, and have the view snap back to the cursor on a normal key press?

@alexherbo2
Copy link
Contributor Author

Behave like the scrolling in web browsers, don’t allow interacting with selections in the view mode.

@Anfid
Copy link
Contributor

Anfid commented Nov 19, 2019

As far as I understand, currently there are 2 kinds of scrolling. One restores all cursor selections after scrolling (vj, vk), and the other one does not (mouse scroll, <c-d>, <c-u>). In the second case, all selections are always just dropped (even if scrolling does not move main cursor) and the cursor is moved if necessary.

I see this issue fixed in following ways:

  1. As @alexherbo2 suggested, allow scrolling past the main cursor and prevent interactions with selections. However, what should happen in this case on cursor movement command after scroll? I also feel like allowing cursor to be out of view will break many existing configurations, but make future ones more flexible.
  2. Prevent restoring selections (i.e. drop all selections) only if next scroll command will move the main cursor and make this the "default" kind of scroll. In case users need to scroll till cursor, there are already vt and vb commands.
  3. Create custom mappings that mimic the behavior described in second point. Currently it is more hacky, than I want it to be, because there is no direct way of getting current view position. This requires getting it with gtGb, parsing selection to get line numbers and saving it to separate variable. Then in the binding compare current cursor position with view position and work with that. Possibly exporting few extra view variables (like window_top, window_left etc.) would simplify this logic enough for average user to set it up.

I think I could get my hands on either of two last variants, but not confident enough to try implementing the first. Any opinions on this?

@Anfid
Copy link
Contributor

Anfid commented Nov 19, 2019

I actually did implement 3rd option locally and scroll command in my config looks like this:

define-command -params 2 scroll %{ execute-keys %sh{
    if [ $1 = "down" ]; then
        if [ "$kak_window_top" = "$kak_cursor_line" ]; then
            echo "<space>;${2}j${2}vj"
        else
            echo ${2}vj
        fi
    elif [ $1 = "up" ]; then
        if [ "$(($kak_window_bottom))" = "$kak_cursor_line" ]; then
            echo "<space>;${2}k${2}vk"
        else
            echo ${2}vk
        fi
    fi
} }

map global normal <a-j> ': scroll down 5<ret>'
map global normal <a-k> ': scroll up 5<ret>'

I added window_top, bottom, left and right builtin variables.

However, I only see this as a temporary solution and think that core scrolling function should be reworked.

@alexherbo2
Copy link
Contributor Author

@mawww Can you reopen the issue?

It’s too easy to destroy crafted selections with mouse scrolls and clicks (when activating a window, it also sets the selection) or keyboard scrolls (e.g. Page Up and Page Down keys).

You can see how scrolling past the main selection behaves in Dance for example. It works well, as Dance notifies you with hidden selections (see #2727 for a screenshot). Helix also highlights line numbers, so you can see where the main and other selections reside.

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 a pull request may close this issue.

4 participants