Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
15976:50aa746472f6 | 15977:7fbdceabad64 |
---|---|
5717 */ | 5717 */ |
5718 void | 5718 void |
5719 set_fraction(win_T *wp) | 5719 set_fraction(win_T *wp) |
5720 { | 5720 { |
5721 if (wp->w_height > 1) | 5721 if (wp->w_height > 1) |
5722 // When cursor is in the first line the percentage is computed as if | |
5723 // it's halfway that line. Thus with two lines it is 25%, with three | |
5724 // lines 17%, etc. Similarly for the last line: 75%, 83%, etc. | |
5722 wp->w_fraction = ((long)wp->w_wrow * FRACTION_MULT | 5725 wp->w_fraction = ((long)wp->w_wrow * FRACTION_MULT |
5723 + wp->w_height / 2) / (long)wp->w_height; | 5726 + FRACTION_MULT / 2) / (long)wp->w_height; |
5724 } | 5727 } |
5725 | 5728 |
5726 /* | 5729 /* |
5727 * Set the height of a window. | 5730 * Set the height of a window. |
5728 * "height" excludes any window toolbar. | 5731 * "height" excludes any window toolbar. |
5768 { | 5771 { |
5769 linenr_T lnum; | 5772 linenr_T lnum; |
5770 int sline, line_size; | 5773 int sline, line_size; |
5771 int height = wp->w_height; | 5774 int height = wp->w_height; |
5772 | 5775 |
5773 /* Don't change w_topline when height is zero. Don't set w_topline when | 5776 // Don't change w_topline when height is zero. Don't set w_topline when |
5774 * 'scrollbind' is set and this isn't the current window. */ | 5777 // 'scrollbind' is set and this isn't the current window. |
5775 if (height > 0 && (!wp->w_p_scb || wp == curwin)) | 5778 if (height > 0 && (!wp->w_p_scb || wp == curwin)) |
5776 { | 5779 { |
5777 /* | 5780 /* |
5778 * Find a value for w_topline that shows the cursor at the same | 5781 * Find a value for w_topline that shows the cursor at the same |
5779 * relative position in the window as before (more or less). | 5782 * relative position in the window as before (more or less). |
5780 */ | 5783 */ |
5781 lnum = wp->w_cursor.lnum; | 5784 lnum = wp->w_cursor.lnum; |
5782 if (lnum < 1) /* can happen when starting up */ | 5785 if (lnum < 1) /* can happen when starting up */ |
5783 lnum = 1; | 5786 lnum = 1; |
5784 wp->w_wrow = ((long)wp->w_fraction * (long)height - 1L | 5787 wp->w_wrow = ((long)wp->w_fraction * (long)height - 1L) |
5785 + FRACTION_MULT / 2) / FRACTION_MULT; | 5788 / FRACTION_MULT; |
5786 line_size = plines_win_col(wp, lnum, (long)(wp->w_cursor.col)) - 1; | 5789 line_size = plines_win_col(wp, lnum, (long)(wp->w_cursor.col)) - 1; |
5787 sline = wp->w_wrow - line_size; | 5790 sline = wp->w_wrow - line_size; |
5788 | 5791 |
5789 if (sline >= 0) | 5792 if (sline >= 0) |
5790 { | 5793 { |
5816 wp->w_skipcol += wp->w_width - win_col_off(wp) | 5819 wp->w_skipcol += wp->w_width - win_col_off(wp) |
5817 + win_col_off2(wp); | 5820 + win_col_off2(wp); |
5818 --wp->w_wrow; | 5821 --wp->w_wrow; |
5819 } | 5822 } |
5820 } | 5823 } |
5821 set_topline(wp, lnum); | |
5822 } | 5824 } |
5823 else if (sline > 0) | 5825 else if (sline > 0) |
5824 { | 5826 { |
5825 while (sline > 0 && lnum > 1) | 5827 while (sline > 0 && lnum > 1) |
5826 { | 5828 { |
5857 lnum++; | 5859 lnum++; |
5858 wp->w_wrow -= line_size + sline; | 5860 wp->w_wrow -= line_size + sline; |
5859 } | 5861 } |
5860 else if (sline > 0) | 5862 else if (sline > 0) |
5861 { | 5863 { |
5862 /* First line of file reached, use that as topline. */ | 5864 // First line of file reached, use that as topline. |
5863 lnum = 1; | 5865 lnum = 1; |
5864 wp->w_wrow -= sline; | 5866 wp->w_wrow -= sline; |
5865 } | 5867 } |
5866 | 5868 } |
5867 set_topline(wp, lnum); | 5869 set_topline(wp, lnum); |
5868 } | |
5869 } | 5870 } |
5870 | 5871 |
5871 if (wp == curwin) | 5872 if (wp == curwin) |
5872 { | 5873 { |
5873 if (get_scrolloff_value()) | 5874 if (get_scrolloff_value()) |