Mercurial > vim
diff src/window.c @ 15977:7fbdceabad64 v8.1.0994
patch 8.1.0994: relative cursor position is not calculated correctly
commit https://github.com/vim/vim/commit/8fcb60f961bdd134599fb016c6537fd496e800f5
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Mar 4 13:18:30 2019 +0100
patch 8.1.0994: relative cursor position is not calculated correctly
Problem: Relative cursor position is not calculated correctly.
Solution: Always set topline, also when window is one line only.
(Robert Webb) Add more info to getwininfo() for testing.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 04 Mar 2019 13:30:08 +0100 |
parents | c38fb03a6055 |
children | 096b8ccd855e |
line wrap: on
line diff
--- a/src/window.c +++ b/src/window.c @@ -5719,8 +5719,11 @@ win_drag_vsep_line(win_T *dragwin, int o set_fraction(win_T *wp) { if (wp->w_height > 1) + // When cursor is in the first line the percentage is computed as if + // it's halfway that line. Thus with two lines it is 25%, with three + // lines 17%, etc. Similarly for the last line: 75%, 83%, etc. wp->w_fraction = ((long)wp->w_wrow * FRACTION_MULT - + wp->w_height / 2) / (long)wp->w_height; + + FRACTION_MULT / 2) / (long)wp->w_height; } /* @@ -5770,8 +5773,8 @@ scroll_to_fraction(win_T *wp, int prev_h int sline, line_size; int height = wp->w_height; - /* Don't change w_topline when height is zero. Don't set w_topline when - * 'scrollbind' is set and this isn't the current window. */ + // Don't change w_topline when height is zero. Don't set w_topline when + // 'scrollbind' is set and this isn't the current window. if (height > 0 && (!wp->w_p_scb || wp == curwin)) { /* @@ -5781,8 +5784,8 @@ scroll_to_fraction(win_T *wp, int prev_h lnum = wp->w_cursor.lnum; if (lnum < 1) /* can happen when starting up */ lnum = 1; - wp->w_wrow = ((long)wp->w_fraction * (long)height - 1L - + FRACTION_MULT / 2) / FRACTION_MULT; + wp->w_wrow = ((long)wp->w_fraction * (long)height - 1L) + / FRACTION_MULT; line_size = plines_win_col(wp, lnum, (long)(wp->w_cursor.col)) - 1; sline = wp->w_wrow - line_size; @@ -5818,7 +5821,6 @@ scroll_to_fraction(win_T *wp, int prev_h --wp->w_wrow; } } - set_topline(wp, lnum); } else if (sline > 0) { @@ -5859,13 +5861,12 @@ scroll_to_fraction(win_T *wp, int prev_h } else if (sline > 0) { - /* First line of file reached, use that as topline. */ + // First line of file reached, use that as topline. lnum = 1; wp->w_wrow -= sline; } - - set_topline(wp, lnum); } + set_topline(wp, lnum); } if (wp == curwin)