Issue #44 resolved

evil-scroll-line-to-center and evil-window-middle have inconsistent behavior on windows with an odd number of lines

topher200
created an issue

The functions evil-scroll-line-to-center and evil-window-middle correspond to the keybindings 'zz' and 'M', respectively.

=== Expected behavior ===

User presses 'zz': the window scrolls the current line to the vertical center of the window

User presses 'M': nothing should happen, since the cursor is already on the center line

=== Actual behavior ===

User presses 'zz': the window scrolls the current line to the vertical center of the window

User presses 'M': the cursor moves one line higher

=== Solution === I'm attaching a patch that reduces the window height count by 1 (before dividing by 2) when doing the center calculation in evil-window-middle. It made more sense to modify this function, since evil-scroll-line-to-center gets its functionality by just calling the 'recenter' elisp function.

Comments (2)

  1. Frank Fischer repo owner

    `evil-window-middle' moves point to the lower middle line in windows with even number of lines (addresses #44).

    Emacs' function `recenter' moves the line to be centered below the window center in windows with an even number of lines. This change makes `evil-window-middle' leaving point on that line.

    Wiki macro error: Changeset 23b62cb7533a not found.

  2. Frank Fischer repo owner

    Using window-height is dangerous because this function does include the mode-line and/or the header-line and is therefore unpredictable. Furthermore even window-body-height is dangerous because it does not respect line-spacing and could therefore again lead to strange results. That's the reason why move-to-window-line has been used.

    Anyway, ... should make the necessary changes you desire. But note, that line-wrapping can still lead to the odd behavior you describe because recenter behaves differently on over-long lines than evil-window-middle.

  3. Log in to comment