Mercurial > vim
comparison src/move.c @ 30677:a345ad853b08 v9.0.0673
patch 9.0.0673: first line wong with 'smoothscroll' and 'scrolloff' zero
Commit: https://github.com/vim/vim/commit/46b54747c5d252c584571a321231bad9330018ec
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Oct 6 15:46:49 2022 +0100
patch 9.0.0673: first line wong with 'smoothscroll' and 'scrolloff' zero
Problem: First line not scrolled properly with 'smoothscroll' and
'scrolloff' zero and using "k".
Solution: Make sure the cursor position is visible.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 06 Oct 2022 17:00:04 +0200 |
parents | bc48f3752d8d |
children | 815b02faced9 |
comparison
equal
deleted
inserted
replaced
30676:fee795c501bb | 30677:a345ad853b08 |
---|---|
264 * If the cursor is above or near the top of the window, scroll the window | 264 * If the cursor is above or near the top of the window, scroll the window |
265 * to show the line the cursor is in, with 'scrolloff' context. | 265 * to show the line the cursor is in, with 'scrolloff' context. |
266 */ | 266 */ |
267 else | 267 else |
268 { | 268 { |
269 if (curwin->w_topline > 1) | 269 if (curwin->w_topline > 1 || curwin->w_skipcol > 0) |
270 { | 270 { |
271 // If the cursor is above topline, scrolling is always needed. | 271 // If the cursor is above topline, scrolling is always needed. |
272 // If the cursor is far below topline and there is no folding, | 272 // If the cursor is far below topline and there is no folding, |
273 // scrolling down is never needed. | 273 // scrolling down is never needed. |
274 if (curwin->w_cursor.lnum < curwin->w_topline) | 274 if (curwin->w_cursor.lnum < curwin->w_topline) |
275 check_topline = TRUE; | 275 check_topline = TRUE; |
276 else if (check_top_offset()) | 276 else if (check_top_offset()) |
277 check_topline = TRUE; | 277 check_topline = TRUE; |
278 else if (curwin->w_cursor.lnum == curwin->w_topline) | |
279 { | |
280 colnr_T vcol; | |
281 | |
282 // check the cursor position is visible. Add 3 for the ">>>" | |
283 // displayed in the top-left. | |
284 getvvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL); | |
285 if (curwin->w_skipcol + 3 >= vcol) | |
286 check_topline = TRUE; | |
287 } | |
278 } | 288 } |
279 #ifdef FEAT_DIFF | 289 #ifdef FEAT_DIFF |
280 // Check if there are more filler lines than allowed. | 290 // Check if there are more filler lines than allowed. |
281 if (!check_topline && curwin->w_topfill > diff_check_fill(curwin, | 291 if (!check_topline && curwin->w_topfill > diff_check_fill(curwin, |
282 curwin->w_topline)) | 292 curwin->w_topline)) |
2005 int used; | 2015 int used; |
2006 int i; | 2016 int i; |
2007 linenr_T top; // just above displayed lines | 2017 linenr_T top; // just above displayed lines |
2008 linenr_T bot; // just below displayed lines | 2018 linenr_T bot; // just below displayed lines |
2009 linenr_T old_topline = curwin->w_topline; | 2019 linenr_T old_topline = curwin->w_topline; |
2020 int old_skipcol = curwin->w_skipcol; | |
2010 #ifdef FEAT_DIFF | 2021 #ifdef FEAT_DIFF |
2011 linenr_T old_topfill = curwin->w_topfill; | 2022 linenr_T old_topfill = curwin->w_topfill; |
2012 #endif | 2023 #endif |
2013 linenr_T new_topline; | 2024 linenr_T new_topline; |
2014 int off = get_scrolloff_value(); | 2025 int off = get_scrolloff_value(); |
2116 if (curwin->w_topfill < 0) | 2127 if (curwin->w_topfill < 0) |
2117 curwin->w_topfill = 0; | 2128 curwin->w_topfill = 0; |
2118 } | 2129 } |
2119 check_topfill(curwin, FALSE); | 2130 check_topfill(curwin, FALSE); |
2120 #endif | 2131 #endif |
2132 // TODO: if the line doesn't fit may optimize w_skipcol | |
2133 if (curwin->w_topline == curwin->w_cursor.lnum) | |
2134 { | |
2135 curwin->w_skipcol = 0; | |
2136 redraw_later(UPD_NOT_VALID); | |
2137 } | |
2121 if (curwin->w_topline != old_topline | 2138 if (curwin->w_topline != old_topline |
2139 || curwin->w_skipcol != old_skipcol | |
2122 #ifdef FEAT_DIFF | 2140 #ifdef FEAT_DIFF |
2123 || curwin->w_topfill != old_topfill | 2141 || curwin->w_topfill != old_topfill |
2124 #endif | 2142 #endif |
2125 ) | 2143 ) |
2126 curwin->w_valid &= | 2144 curwin->w_valid &= |