Mercurial > vim
annotate src/move.c @ 25717:d3f992bc6ef8 v8.2.3394
patch 8.2.3394: filler lines are wrong when changing text in diff mode
Commit: https://github.com/vim/vim/commit/04626c243c47af91c2580eaf23e12286180e0e81
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Sep 1 16:02:07 2021 +0200
patch 8.2.3394: filler lines are wrong when changing text in diff mode
Problem: Filler lines are wrong when changing text in diff mode.
Solution: Don't change the filler lines on every change. Check
scrollbinding when updating the filler lines. (closes #8809)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 01 Sep 2021 16:15:04 +0200 |
parents | e8e2c4d33b9b |
children | 336e2d9924e6 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9852
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 /* | |
10 * move.c: Functions for moving the cursor and scrolling text. | |
11 * | |
12 * There are two ways to move the cursor: | |
13 * 1. Move the cursor directly, the text is scrolled to keep the cursor in the | |
14 * window. | |
15 * 2. Scroll the text, the cursor is moved into the text visible in the | |
16 * window. | |
17 * The 'scrolloff' option makes this a bit complicated. | |
18 */ | |
19 | |
20 #include "vim.h" | |
21 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7103
diff
changeset
|
22 static int scrolljump_value(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7103
diff
changeset
|
23 static int check_top_offset(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7103
diff
changeset
|
24 static void curs_rows(win_T *wp); |
7 | 25 |
26 typedef struct | |
27 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
28 linenr_T lnum; // line number |
7 | 29 #ifdef FEAT_DIFF |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
30 int fill; // filler lines |
7 | 31 #endif |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
32 int height; // height of added line |
7 | 33 } lineoff_T; |
34 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7103
diff
changeset
|
35 static void topline_back(lineoff_T *lp); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7103
diff
changeset
|
36 static void botline_forw(lineoff_T *lp); |
7 | 37 |
38 /* | |
39 * Compute wp->w_botline for the current wp->w_topline. Can be called after | |
40 * wp->w_topline changed. | |
41 */ | |
42 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
43 comp_botline(win_T *wp) |
7 | 44 { |
45 int n; | |
46 linenr_T lnum; | |
47 int done; | |
48 #ifdef FEAT_FOLDING | |
49 linenr_T last; | |
50 int folded; | |
51 #endif | |
52 | |
53 /* | |
54 * If w_cline_row is valid, start there. | |
55 * Otherwise have to start at w_topline. | |
56 */ | |
57 check_cursor_moved(wp); | |
58 if (wp->w_valid & VALID_CROW) | |
59 { | |
60 lnum = wp->w_cursor.lnum; | |
61 done = wp->w_cline_row; | |
62 } | |
63 else | |
64 { | |
65 lnum = wp->w_topline; | |
66 done = 0; | |
67 } | |
68 | |
69 for ( ; lnum <= wp->w_buffer->b_ml.ml_line_count; ++lnum) | |
70 { | |
71 #ifdef FEAT_FOLDING | |
72 last = lnum; | |
73 folded = FALSE; | |
74 if (hasFoldingWin(wp, lnum, NULL, &last, TRUE, NULL)) | |
75 { | |
76 n = 1; | |
77 folded = TRUE; | |
78 } | |
79 else | |
80 #endif | |
81 #ifdef FEAT_DIFF | |
82 if (lnum == wp->w_topline) | |
83 n = plines_win_nofill(wp, lnum, TRUE) + wp->w_topfill; | |
84 else | |
85 #endif | |
86 n = plines_win(wp, lnum, TRUE); | |
87 if ( | |
88 #ifdef FEAT_FOLDING | |
89 lnum <= wp->w_cursor.lnum && last >= wp->w_cursor.lnum | |
90 #else | |
91 lnum == wp->w_cursor.lnum | |
92 #endif | |
93 ) | |
94 { | |
95 wp->w_cline_row = done; | |
96 wp->w_cline_height = n; | |
97 #ifdef FEAT_FOLDING | |
98 wp->w_cline_folded = folded; | |
99 #endif | |
5764 | 100 redraw_for_cursorline(wp); |
7 | 101 wp->w_valid |= (VALID_CROW|VALID_CHEIGHT); |
102 } | |
103 if (done + n > wp->w_height) | |
104 break; | |
105 done += n; | |
106 #ifdef FEAT_FOLDING | |
107 lnum = last; | |
108 #endif | |
109 } | |
110 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
111 // wp->w_botline is the line that is just below the window |
7 | 112 wp->w_botline = lnum; |
113 wp->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP; | |
114 | |
115 set_empty_rows(wp, done); | |
116 } | |
117 | |
14720
a9665096074b
patch 8.1.0372: screen updating slow when 'cursorline' is set
Christian Brabandt <cb@256bit.org>
parents:
14317
diff
changeset
|
118 #ifdef FEAT_SYN_HL |
14846
10107703b9b2
patch 8.1.0435: cursorline highlight not removed in some situation
Christian Brabandt <cb@256bit.org>
parents:
14724
diff
changeset
|
119 void |
10107703b9b2
patch 8.1.0435: cursorline highlight not removed in some situation
Christian Brabandt <cb@256bit.org>
parents:
14724
diff
changeset
|
120 reset_cursorline(void) |
10107703b9b2
patch 8.1.0435: cursorline highlight not removed in some situation
Christian Brabandt <cb@256bit.org>
parents:
14724
diff
changeset
|
121 { |
14873
a8ed1cb85859
patch 8.1.0448: cursorline not removed when using 'cursorbind'
Christian Brabandt <cb@256bit.org>
parents:
14862
diff
changeset
|
122 curwin->w_last_cursorline = 0; |
14846
10107703b9b2
patch 8.1.0435: cursorline highlight not removed in some situation
Christian Brabandt <cb@256bit.org>
parents:
14724
diff
changeset
|
123 } |
14720
a9665096074b
patch 8.1.0372: screen updating slow when 'cursorline' is set
Christian Brabandt <cb@256bit.org>
parents:
14317
diff
changeset
|
124 #endif |
a9665096074b
patch 8.1.0372: screen updating slow when 'cursorline' is set
Christian Brabandt <cb@256bit.org>
parents:
14317
diff
changeset
|
125 |
7 | 126 /* |
5764 | 127 * Redraw when w_cline_row changes and 'relativenumber' or 'cursorline' is |
128 * set. | |
129 */ | |
15697
b7a88676e81c
patch 8.1.0856: when scrolling a window the cursorline is not always updated
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
130 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
131 redraw_for_cursorline(win_T *wp) |
5764 | 132 { |
133 if ((wp->w_p_rnu | |
134 #ifdef FEAT_SYN_HL | |
135 || wp->w_p_cul | |
136 #endif | |
137 ) | |
138 && (wp->w_valid & VALID_CROW) == 0 | |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
139 && !pum_visible()) |
14720
a9665096074b
patch 8.1.0372: screen updating slow when 'cursorline' is set
Christian Brabandt <cb@256bit.org>
parents:
14317
diff
changeset
|
140 { |
14724
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
141 if (wp->w_p_rnu) |
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
142 // win_line() will redraw the number column only. |
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
143 redraw_win_later(wp, VALID); |
14720
a9665096074b
patch 8.1.0372: screen updating slow when 'cursorline' is set
Christian Brabandt <cb@256bit.org>
parents:
14317
diff
changeset
|
144 #ifdef FEAT_SYN_HL |
14724
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
145 if (wp->w_p_cul) |
14720
a9665096074b
patch 8.1.0372: screen updating slow when 'cursorline' is set
Christian Brabandt <cb@256bit.org>
parents:
14317
diff
changeset
|
146 { |
14873
a8ed1cb85859
patch 8.1.0448: cursorline not removed when using 'cursorbind'
Christian Brabandt <cb@256bit.org>
parents:
14862
diff
changeset
|
147 if (wp->w_redr_type <= VALID && wp->w_last_cursorline != 0) |
14724
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
148 { |
14873
a8ed1cb85859
patch 8.1.0448: cursorline not removed when using 'cursorbind'
Christian Brabandt <cb@256bit.org>
parents:
14862
diff
changeset
|
149 // "w_last_cursorline" may be outdated, worst case we redraw |
a8ed1cb85859
patch 8.1.0448: cursorline not removed when using 'cursorbind'
Christian Brabandt <cb@256bit.org>
parents:
14862
diff
changeset
|
150 // too much. This is optimized for moving the cursor around in |
a8ed1cb85859
patch 8.1.0448: cursorline not removed when using 'cursorbind'
Christian Brabandt <cb@256bit.org>
parents:
14862
diff
changeset
|
151 // the current window. |
15400
ac5542aadd9c
patch 8.1.0708: third argument for redrawWinline() is always FALSE
Bram Moolenaar <Bram@vim.org>
parents:
15064
diff
changeset
|
152 redrawWinline(wp, wp->w_last_cursorline); |
ac5542aadd9c
patch 8.1.0708: third argument for redrawWinline() is always FALSE
Bram Moolenaar <Bram@vim.org>
parents:
15064
diff
changeset
|
153 redrawWinline(wp, wp->w_cursor.lnum); |
14724
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
154 } |
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
155 else |
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
156 redraw_win_later(wp, SOME_VALID); |
14720
a9665096074b
patch 8.1.0372: screen updating slow when 'cursorline' is set
Christian Brabandt <cb@256bit.org>
parents:
14317
diff
changeset
|
157 } |
14722
9b150311eb9c
patch 8.1.0373: screen updating still slow when 'cursorline' is set
Christian Brabandt <cb@256bit.org>
parents:
14720
diff
changeset
|
158 #endif |
14720
a9665096074b
patch 8.1.0372: screen updating slow when 'cursorline' is set
Christian Brabandt <cb@256bit.org>
parents:
14317
diff
changeset
|
159 } |
5764 | 160 } |
161 | |
162 /* | |
7 | 163 * Update curwin->w_topline and redraw if necessary. |
164 * Used to update the screen before printing a message. | |
165 */ | |
166 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
167 update_topline_redraw(void) |
7 | 168 { |
169 update_topline(); | |
170 if (must_redraw) | |
171 update_screen(0); | |
172 } | |
173 | |
174 /* | |
175 * Update curwin->w_topline to move the cursor onto the screen. | |
176 */ | |
177 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
178 update_topline(void) |
7 | 179 { |
180 long line_count; | |
181 int halfheight; | |
182 int n; | |
183 linenr_T old_topline; | |
184 #ifdef FEAT_DIFF | |
185 int old_topfill; | |
186 #endif | |
187 #ifdef FEAT_FOLDING | |
188 linenr_T lnum; | |
189 #endif | |
190 int check_topline = FALSE; | |
191 int check_botline = FALSE; | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
192 long *so_ptr = curwin->w_p_so >= 0 ? &curwin->w_p_so : &p_so; |
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
193 int save_so = *so_ptr; |
7 | 194 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
195 // If there is no valid screen and when the window height is zero just use |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
196 // the cursor line. |
11258
84f71a8a5f2c
patch 8.0.0515: ml_get errors in silent Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
197 if (!screen_valid(TRUE) || curwin->w_height == 0) |
6247 | 198 { |
22782
53b996eb5e76
patch 8.2.1939: invalid memory access in Ex mode with global command
Bram Moolenaar <Bram@vim.org>
parents:
22403
diff
changeset
|
199 check_cursor_lnum(); |
6247 | 200 curwin->w_topline = curwin->w_cursor.lnum; |
201 curwin->w_botline = curwin->w_topline; | |
202 curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP; | |
203 curwin->w_scbind_pos = 1; | |
204 return; | |
205 } | |
206 | |
7 | 207 check_cursor_moved(curwin); |
208 if (curwin->w_valid & VALID_TOPLINE) | |
209 return; | |
210 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
211 // When dragging with the mouse, don't scroll that quickly |
1121 | 212 if (mouse_dragging > 0) |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
213 *so_ptr = mouse_dragging - 1; |
7 | 214 |
215 old_topline = curwin->w_topline; | |
216 #ifdef FEAT_DIFF | |
217 old_topfill = curwin->w_topfill; | |
218 #endif | |
219 | |
220 /* | |
221 * If the buffer is empty, always set topline to 1. | |
222 */ | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
223 if (BUFEMPTY()) // special case - file is empty |
7 | 224 { |
225 if (curwin->w_topline != 1) | |
226 redraw_later(NOT_VALID); | |
227 curwin->w_topline = 1; | |
228 curwin->w_botline = 2; | |
229 curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP; | |
230 curwin->w_scbind_pos = 1; | |
231 } | |
232 | |
233 /* | |
234 * If the cursor is above or near the top of the window, scroll the window | |
235 * to show the line the cursor is in, with 'scrolloff' context. | |
236 */ | |
237 else | |
238 { | |
239 if (curwin->w_topline > 1) | |
240 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
241 // If the cursor is above topline, scrolling is always needed. |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
242 // If the cursor is far below topline and there is no folding, |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
243 // scrolling down is never needed. |
7 | 244 if (curwin->w_cursor.lnum < curwin->w_topline) |
245 check_topline = TRUE; | |
246 else if (check_top_offset()) | |
247 check_topline = TRUE; | |
248 } | |
249 #ifdef FEAT_DIFF | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
250 // Check if there are more filler lines than allowed. |
7 | 251 if (!check_topline && curwin->w_topfill > diff_check_fill(curwin, |
252 curwin->w_topline)) | |
253 check_topline = TRUE; | |
254 #endif | |
255 | |
256 if (check_topline) | |
257 { | |
258 halfheight = curwin->w_height / 2 - 1; | |
259 if (halfheight < 2) | |
260 halfheight = 2; | |
261 | |
262 #ifdef FEAT_FOLDING | |
263 if (hasAnyFolding(curwin)) | |
264 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
265 // Count the number of logical lines between the cursor and |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
266 // topline + scrolloff (approximation of how much will be |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
267 // scrolled). |
7 | 268 n = 0; |
269 for (lnum = curwin->w_cursor.lnum; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
270 lnum < curwin->w_topline + *so_ptr; ++lnum) |
7 | 271 { |
272 ++n; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
273 // stop at end of file or when we know we are far off |
7 | 274 if (lnum >= curbuf->b_ml.ml_line_count || n >= halfheight) |
275 break; | |
276 (void)hasFolding(lnum, NULL, &lnum); | |
277 } | |
278 } | |
279 else | |
280 #endif | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
281 n = curwin->w_topline + *so_ptr - curwin->w_cursor.lnum; |
7 | 282 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
283 // If we weren't very close to begin with, we scroll to put the |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
284 // cursor in the middle of the window. Otherwise put the cursor |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
285 // near the top of the window. |
7 | 286 if (n >= halfheight) |
287 scroll_cursor_halfway(FALSE); | |
288 else | |
289 { | |
532 | 290 scroll_cursor_top(scrolljump_value(), FALSE); |
7 | 291 check_botline = TRUE; |
292 } | |
293 } | |
294 | |
295 else | |
296 { | |
297 #ifdef FEAT_FOLDING | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
298 // Make sure topline is the first line of a fold. |
7 | 299 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
300 #endif | |
301 check_botline = TRUE; | |
302 } | |
303 } | |
304 | |
305 /* | |
306 * If the cursor is below the bottom of the window, scroll the window | |
307 * to put the cursor on the window. | |
308 * When w_botline is invalid, recompute it first, to avoid a redraw later. | |
309 * If w_botline was approximated, we might need a redraw later in a few | |
310 * cases, but we don't want to spend (a lot of) time recomputing w_botline | |
311 * for every small change. | |
312 */ | |
313 if (check_botline) | |
314 { | |
315 if (!(curwin->w_valid & VALID_BOTLINE_AP)) | |
316 validate_botline(); | |
317 | |
318 if (curwin->w_botline <= curbuf->b_ml.ml_line_count) | |
319 { | |
1744 | 320 if (curwin->w_cursor.lnum < curwin->w_botline) |
321 { | |
322 if (((long)curwin->w_cursor.lnum | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
323 >= (long)curwin->w_botline - *so_ptr |
7 | 324 #ifdef FEAT_FOLDING |
325 || hasAnyFolding(curwin) | |
326 #endif | |
327 )) | |
1744 | 328 { |
7 | 329 lineoff_T loff; |
330 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
331 // Cursor is (a few lines) above botline, check if there are |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
332 // 'scrolloff' window lines below the cursor. If not, need to |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
333 // scroll. |
7 | 334 n = curwin->w_empty_rows; |
335 loff.lnum = curwin->w_cursor.lnum; | |
336 #ifdef FEAT_FOLDING | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
337 // In a fold go to its last line. |
7 | 338 (void)hasFolding(loff.lnum, NULL, &loff.lnum); |
339 #endif | |
340 #ifdef FEAT_DIFF | |
341 loff.fill = 0; | |
342 n += curwin->w_filler_rows; | |
343 #endif | |
344 loff.height = 0; | |
345 while (loff.lnum < curwin->w_botline | |
346 #ifdef FEAT_DIFF | |
347 && (loff.lnum + 1 < curwin->w_botline || loff.fill == 0) | |
348 #endif | |
349 ) | |
350 { | |
351 n += loff.height; | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
352 if (n >= *so_ptr) |
7 | 353 break; |
354 botline_forw(&loff); | |
355 } | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
356 if (n >= *so_ptr) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
357 // sufficient context, no need to scroll |
7 | 358 check_botline = FALSE; |
1744 | 359 } |
360 else | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
361 // sufficient context, no need to scroll |
1744 | 362 check_botline = FALSE; |
7 | 363 } |
364 if (check_botline) | |
365 { | |
366 #ifdef FEAT_FOLDING | |
367 if (hasAnyFolding(curwin)) | |
368 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
369 // Count the number of logical lines between the cursor and |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
370 // botline - scrolloff (approximation of how much will be |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
371 // scrolled). |
7 | 372 line_count = 0; |
373 for (lnum = curwin->w_cursor.lnum; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
374 lnum >= curwin->w_botline - *so_ptr; --lnum) |
7 | 375 { |
376 ++line_count; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
377 // stop at end of file or when we know we are far off |
7 | 378 if (lnum <= 0 || line_count > curwin->w_height + 1) |
379 break; | |
380 (void)hasFolding(lnum, &lnum, NULL); | |
381 } | |
382 } | |
383 else | |
384 #endif | |
385 line_count = curwin->w_cursor.lnum - curwin->w_botline | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
386 + 1 + *so_ptr; |
7 | 387 if (line_count <= curwin->w_height + 1) |
532 | 388 scroll_cursor_bot(scrolljump_value(), FALSE); |
7 | 389 else |
390 scroll_cursor_halfway(FALSE); | |
391 } | |
392 } | |
393 } | |
394 curwin->w_valid |= VALID_TOPLINE; | |
395 | |
396 /* | |
397 * Need to redraw when topline changed. | |
398 */ | |
399 if (curwin->w_topline != old_topline | |
400 #ifdef FEAT_DIFF | |
401 || curwin->w_topfill != old_topfill | |
402 #endif | |
403 ) | |
404 { | |
3318 | 405 dollar_vcol = -1; |
740 | 406 if (curwin->w_skipcol != 0) |
7 | 407 { |
408 curwin->w_skipcol = 0; | |
409 redraw_later(NOT_VALID); | |
410 } | |
411 else | |
412 redraw_later(VALID); | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
413 // May need to set w_skipcol when cursor in w_topline. |
7 | 414 if (curwin->w_cursor.lnum == curwin->w_topline) |
415 validate_cursor(); | |
416 } | |
417 | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
418 *so_ptr = save_so; |
7 | 419 } |
420 | |
421 /* | |
532 | 422 * Return the scrolljump value to use for the current window. |
423 * When 'scrolljump' is positive use it as-is. | |
424 * When 'scrolljump' is negative use it as a percentage of the window height. | |
425 */ | |
426 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
427 scrolljump_value(void) |
532 | 428 { |
429 if (p_sj >= 0) | |
430 return (int)p_sj; | |
431 return (curwin->w_height * -p_sj) / 100; | |
432 } | |
433 | |
434 /* | |
7 | 435 * Return TRUE when there are not 'scrolloff' lines above the cursor for the |
436 * current window. | |
437 */ | |
438 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
439 check_top_offset(void) |
7 | 440 { |
441 lineoff_T loff; | |
442 int n; | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
443 long so = get_scrolloff_value(); |
7 | 444 |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
445 if (curwin->w_cursor.lnum < curwin->w_topline + so |
7 | 446 #ifdef FEAT_FOLDING |
447 || hasAnyFolding(curwin) | |
448 #endif | |
449 ) | |
450 { | |
451 loff.lnum = curwin->w_cursor.lnum; | |
452 #ifdef FEAT_DIFF | |
453 loff.fill = 0; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
454 n = curwin->w_topfill; // always have this context |
7 | 455 #else |
456 n = 0; | |
457 #endif | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
458 // Count the visible screen lines above the cursor line. |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
459 while (n < so) |
7 | 460 { |
461 topline_back(&loff); | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
462 // Stop when included a line above the window. |
7 | 463 if (loff.lnum < curwin->w_topline |
464 #ifdef FEAT_DIFF | |
465 || (loff.lnum == curwin->w_topline && loff.fill > 0) | |
466 #endif | |
467 ) | |
468 break; | |
469 n += loff.height; | |
470 } | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
471 if (n < so) |
7 | 472 return TRUE; |
473 } | |
474 return FALSE; | |
475 } | |
476 | |
477 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
478 update_curswant(void) |
7 | 479 { |
480 if (curwin->w_set_curswant) | |
481 { | |
482 validate_virtcol(); | |
483 curwin->w_curswant = curwin->w_virtcol; | |
484 curwin->w_set_curswant = FALSE; | |
485 } | |
486 } | |
487 | |
488 /* | |
489 * Check if the cursor has moved. Set the w_valid flag accordingly. | |
490 */ | |
491 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
492 check_cursor_moved(win_T *wp) |
7 | 493 { |
494 if (wp->w_cursor.lnum != wp->w_valid_cursor.lnum) | |
495 { | |
496 wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL | |
497 |VALID_CHEIGHT|VALID_CROW|VALID_TOPLINE); | |
498 wp->w_valid_cursor = wp->w_cursor; | |
499 wp->w_valid_leftcol = wp->w_leftcol; | |
500 } | |
501 else if (wp->w_cursor.col != wp->w_valid_cursor.col | |
502 || wp->w_leftcol != wp->w_valid_leftcol | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
503 || wp->w_cursor.coladd != wp->w_valid_cursor.coladd) |
7 | 504 { |
505 wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL); | |
506 wp->w_valid_cursor.col = wp->w_cursor.col; | |
507 wp->w_valid_leftcol = wp->w_leftcol; | |
508 wp->w_valid_cursor.coladd = wp->w_cursor.coladd; | |
509 } | |
510 } | |
511 | |
512 /* | |
513 * Call this function when some window settings have changed, which require | |
514 * the cursor position, botline and topline to be recomputed and the window to | |
515 * be redrawn. E.g, when changing the 'wrap' option or folding. | |
516 */ | |
517 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
518 changed_window_setting(void) |
7 | 519 { |
520 changed_window_setting_win(curwin); | |
521 } | |
522 | |
523 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
524 changed_window_setting_win(win_T *wp) |
7 | 525 { |
526 wp->w_lines_valid = 0; | |
527 changed_line_abv_curs_win(wp); | |
528 wp->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP|VALID_TOPLINE); | |
529 redraw_win_later(wp, NOT_VALID); | |
530 } | |
531 | |
532 /* | |
533 * Set wp->w_topline to a certain number. | |
534 */ | |
535 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
536 set_topline(win_T *wp, linenr_T lnum) |
7 | 537 { |
25717
d3f992bc6ef8
patch 8.2.3394: filler lines are wrong when changing text in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
538 #ifdef FEAT_DIFF |
d3f992bc6ef8
patch 8.2.3394: filler lines are wrong when changing text in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
539 linenr_T prev_topline = wp->w_topline; |
d3f992bc6ef8
patch 8.2.3394: filler lines are wrong when changing text in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
540 #endif |
d3f992bc6ef8
patch 8.2.3394: filler lines are wrong when changing text in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
541 |
7 | 542 #ifdef FEAT_FOLDING |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
543 // go to first of folded lines |
7 | 544 (void)hasFoldingWin(wp, lnum, &lnum, NULL, TRUE, NULL); |
545 #endif | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
546 // Approximate the value of w_botline |
7 | 547 wp->w_botline += lnum - wp->w_topline; |
23306
90ea5037a7e3
patch 8.2.2198: ml_get error when resizing window and using text property
Bram Moolenaar <Bram@vim.org>
parents:
23213
diff
changeset
|
548 if (wp->w_botline > wp->w_buffer->b_ml.ml_line_count + 1) |
90ea5037a7e3
patch 8.2.2198: ml_get error when resizing window and using text property
Bram Moolenaar <Bram@vim.org>
parents:
23213
diff
changeset
|
549 wp->w_botline = wp->w_buffer->b_ml.ml_line_count + 1; |
7 | 550 wp->w_topline = lnum; |
1744 | 551 wp->w_topline_was_set = TRUE; |
7 | 552 #ifdef FEAT_DIFF |
25717
d3f992bc6ef8
patch 8.2.3394: filler lines are wrong when changing text in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
553 if (lnum != prev_topline) |
d3f992bc6ef8
patch 8.2.3394: filler lines are wrong when changing text in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
554 // Keep the filler lines when the topline didn't change. |
d3f992bc6ef8
patch 8.2.3394: filler lines are wrong when changing text in diff mode
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
555 wp->w_topfill = 0; |
7 | 556 #endif |
557 wp->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_TOPLINE); | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
558 // Don't set VALID_TOPLINE here, 'scrolloff' needs to be checked. |
7 | 559 redraw_later(VALID); |
560 } | |
561 | |
562 /* | |
563 * Call this function when the length of the cursor line (in screen | |
564 * characters) has changed, and the change is before the cursor. | |
565 * Need to take care of w_botline separately! | |
566 */ | |
567 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
568 changed_cline_bef_curs(void) |
7 | 569 { |
570 curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL | |
571 |VALID_CHEIGHT|VALID_TOPLINE); | |
572 } | |
573 | |
574 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
575 changed_cline_bef_curs_win(win_T *wp) |
7 | 576 { |
577 wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL | |
578 |VALID_CHEIGHT|VALID_TOPLINE); | |
579 } | |
580 | |
581 /* | |
582 * Call this function when the length of a line (in screen characters) above | |
583 * the cursor have changed. | |
584 * Need to take care of w_botline separately! | |
585 */ | |
586 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
587 changed_line_abv_curs(void) |
7 | 588 { |
589 curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL|VALID_CROW | |
590 |VALID_CHEIGHT|VALID_TOPLINE); | |
591 } | |
592 | |
593 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
594 changed_line_abv_curs_win(win_T *wp) |
7 | 595 { |
596 wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL|VALID_CROW | |
597 |VALID_CHEIGHT|VALID_TOPLINE); | |
598 } | |
599 | |
600 /* | |
601 * Make sure the value of curwin->w_botline is valid. | |
602 */ | |
603 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
604 validate_botline(void) |
7 | 605 { |
23306
90ea5037a7e3
patch 8.2.2198: ml_get error when resizing window and using text property
Bram Moolenaar <Bram@vim.org>
parents:
23213
diff
changeset
|
606 validate_botline_win(curwin); |
90ea5037a7e3
patch 8.2.2198: ml_get error when resizing window and using text property
Bram Moolenaar <Bram@vim.org>
parents:
23213
diff
changeset
|
607 } |
90ea5037a7e3
patch 8.2.2198: ml_get error when resizing window and using text property
Bram Moolenaar <Bram@vim.org>
parents:
23213
diff
changeset
|
608 |
90ea5037a7e3
patch 8.2.2198: ml_get error when resizing window and using text property
Bram Moolenaar <Bram@vim.org>
parents:
23213
diff
changeset
|
609 /* |
90ea5037a7e3
patch 8.2.2198: ml_get error when resizing window and using text property
Bram Moolenaar <Bram@vim.org>
parents:
23213
diff
changeset
|
610 * Make sure the value of wp->w_botline is valid. |
90ea5037a7e3
patch 8.2.2198: ml_get error when resizing window and using text property
Bram Moolenaar <Bram@vim.org>
parents:
23213
diff
changeset
|
611 */ |
90ea5037a7e3
patch 8.2.2198: ml_get error when resizing window and using text property
Bram Moolenaar <Bram@vim.org>
parents:
23213
diff
changeset
|
612 void |
90ea5037a7e3
patch 8.2.2198: ml_get error when resizing window and using text property
Bram Moolenaar <Bram@vim.org>
parents:
23213
diff
changeset
|
613 validate_botline_win(win_T *wp) |
90ea5037a7e3
patch 8.2.2198: ml_get error when resizing window and using text property
Bram Moolenaar <Bram@vim.org>
parents:
23213
diff
changeset
|
614 { |
90ea5037a7e3
patch 8.2.2198: ml_get error when resizing window and using text property
Bram Moolenaar <Bram@vim.org>
parents:
23213
diff
changeset
|
615 if (!(wp->w_valid & VALID_BOTLINE)) |
90ea5037a7e3
patch 8.2.2198: ml_get error when resizing window and using text property
Bram Moolenaar <Bram@vim.org>
parents:
23213
diff
changeset
|
616 comp_botline(wp); |
7 | 617 } |
618 | |
619 /* | |
620 * Mark curwin->w_botline as invalid (because of some change in the buffer). | |
621 */ | |
622 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
623 invalidate_botline(void) |
7 | 624 { |
625 curwin->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP); | |
626 } | |
627 | |
628 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
629 invalidate_botline_win(win_T *wp) |
7 | 630 { |
631 wp->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP); | |
632 } | |
633 | |
634 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
635 approximate_botline_win( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
636 win_T *wp) |
7 | 637 { |
638 wp->w_valid &= ~VALID_BOTLINE; | |
639 } | |
640 | |
641 /* | |
642 * Return TRUE if curwin->w_wrow and curwin->w_wcol are valid. | |
643 */ | |
644 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
645 cursor_valid(void) |
7 | 646 { |
647 check_cursor_moved(curwin); | |
648 return ((curwin->w_valid & (VALID_WROW|VALID_WCOL)) == | |
649 (VALID_WROW|VALID_WCOL)); | |
650 } | |
651 | |
652 /* | |
653 * Validate cursor position. Makes sure w_wrow and w_wcol are valid. | |
654 * w_topline must be valid, you may need to call update_topline() first! | |
655 */ | |
656 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
657 validate_cursor(void) |
7 | 658 { |
659 check_cursor_moved(curwin); | |
660 if ((curwin->w_valid & (VALID_WCOL|VALID_WROW)) != (VALID_WCOL|VALID_WROW)) | |
661 curs_columns(TRUE); | |
662 } | |
663 | |
664 #if defined(FEAT_GUI) || defined(PROTO) | |
665 /* | |
666 * validate w_cline_row. | |
667 */ | |
668 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
669 validate_cline_row(void) |
7 | 670 { |
671 /* | |
672 * First make sure that w_topline is valid (after moving the cursor). | |
673 */ | |
674 update_topline(); | |
675 check_cursor_moved(curwin); | |
676 if (!(curwin->w_valid & VALID_CROW)) | |
6441 | 677 curs_rows(curwin); |
7 | 678 } |
679 #endif | |
680 | |
681 /* | |
682 * Compute wp->w_cline_row and wp->w_cline_height, based on the current value | |
2154
7c8c7c95a865
First step in the Vim 7.3 branch. Changed version numbers.
Bram Moolenaar <bram@zimbu.org>
parents:
2082
diff
changeset
|
683 * of wp->w_topline. |
7 | 684 */ |
685 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
686 curs_rows(win_T *wp) |
7 | 687 { |
688 linenr_T lnum; | |
689 int i; | |
690 int all_invalid; | |
691 int valid; | |
692 #ifdef FEAT_FOLDING | |
693 long fold_count; | |
694 #endif | |
695 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
696 // Check if wp->w_lines[].wl_size is invalid |
7 | 697 all_invalid = (!redrawing() |
698 || wp->w_lines_valid == 0 | |
699 || wp->w_lines[0].wl_lnum > wp->w_topline); | |
700 i = 0; | |
701 wp->w_cline_row = 0; | |
702 for (lnum = wp->w_topline; lnum < wp->w_cursor.lnum; ++i) | |
703 { | |
704 valid = FALSE; | |
705 if (!all_invalid && i < wp->w_lines_valid) | |
706 { | |
707 if (wp->w_lines[i].wl_lnum < lnum || !wp->w_lines[i].wl_valid) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
708 continue; // skip changed or deleted lines |
7 | 709 if (wp->w_lines[i].wl_lnum == lnum) |
710 { | |
711 #ifdef FEAT_FOLDING | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
712 // Check for newly inserted lines below this row, in which |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
713 // case we need to check for folded lines. |
7 | 714 if (!wp->w_buffer->b_mod_set |
715 || wp->w_lines[i].wl_lastlnum < wp->w_cursor.lnum | |
716 || wp->w_buffer->b_mod_top | |
717 > wp->w_lines[i].wl_lastlnum + 1) | |
718 #endif | |
719 valid = TRUE; | |
720 } | |
721 else if (wp->w_lines[i].wl_lnum > lnum) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
722 --i; // hold at inserted lines |
7 | 723 } |
724 if (valid | |
725 #ifdef FEAT_DIFF | |
726 && (lnum != wp->w_topline || !wp->w_p_diff) | |
727 #endif | |
728 ) | |
729 { | |
730 #ifdef FEAT_FOLDING | |
731 lnum = wp->w_lines[i].wl_lastlnum + 1; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
732 // Cursor inside folded lines, don't count this row |
7 | 733 if (lnum > wp->w_cursor.lnum) |
734 break; | |
735 #else | |
736 ++lnum; | |
737 #endif | |
738 wp->w_cline_row += wp->w_lines[i].wl_size; | |
739 } | |
740 else | |
741 { | |
742 #ifdef FEAT_FOLDING | |
743 fold_count = foldedCount(wp, lnum, NULL); | |
744 if (fold_count) | |
745 { | |
746 lnum += fold_count; | |
747 if (lnum > wp->w_cursor.lnum) | |
748 break; | |
749 ++wp->w_cline_row; | |
750 } | |
751 else | |
752 #endif | |
753 #ifdef FEAT_DIFF | |
754 if (lnum == wp->w_topline) | |
755 wp->w_cline_row += plines_win_nofill(wp, lnum++, TRUE) | |
756 + wp->w_topfill; | |
757 else | |
758 #endif | |
759 wp->w_cline_row += plines_win(wp, lnum++, TRUE); | |
760 } | |
761 } | |
762 | |
763 check_cursor_moved(wp); | |
764 if (!(wp->w_valid & VALID_CHEIGHT)) | |
765 { | |
766 if (all_invalid | |
767 || i == wp->w_lines_valid | |
768 || (i < wp->w_lines_valid | |
769 && (!wp->w_lines[i].wl_valid | |
770 || wp->w_lines[i].wl_lnum != wp->w_cursor.lnum))) | |
771 { | |
772 #ifdef FEAT_DIFF | |
773 if (wp->w_cursor.lnum == wp->w_topline) | |
774 wp->w_cline_height = plines_win_nofill(wp, wp->w_cursor.lnum, | |
775 TRUE) + wp->w_topfill; | |
776 else | |
777 #endif | |
778 wp->w_cline_height = plines_win(wp, wp->w_cursor.lnum, TRUE); | |
779 #ifdef FEAT_FOLDING | |
780 wp->w_cline_folded = hasFoldingWin(wp, wp->w_cursor.lnum, | |
781 NULL, NULL, TRUE, NULL); | |
782 #endif | |
783 } | |
784 else if (i > wp->w_lines_valid) | |
785 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
786 // a line that is too long to fit on the last screen line |
7 | 787 wp->w_cline_height = 0; |
788 #ifdef FEAT_FOLDING | |
789 wp->w_cline_folded = hasFoldingWin(wp, wp->w_cursor.lnum, | |
790 NULL, NULL, TRUE, NULL); | |
791 #endif | |
792 } | |
793 else | |
794 { | |
795 wp->w_cline_height = wp->w_lines[i].wl_size; | |
796 #ifdef FEAT_FOLDING | |
797 wp->w_cline_folded = wp->w_lines[i].wl_folded; | |
798 #endif | |
799 } | |
800 } | |
801 | |
5764 | 802 redraw_for_cursorline(curwin); |
7 | 803 wp->w_valid |= VALID_CROW|VALID_CHEIGHT; |
804 | |
805 } | |
806 | |
807 /* | |
808 * Validate curwin->w_virtcol only. | |
809 */ | |
810 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
811 validate_virtcol(void) |
7 | 812 { |
813 validate_virtcol_win(curwin); | |
814 } | |
815 | |
816 /* | |
817 * Validate wp->w_virtcol only. | |
818 */ | |
819 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
820 validate_virtcol_win(win_T *wp) |
7 | 821 { |
822 check_cursor_moved(wp); | |
823 if (!(wp->w_valid & VALID_VIRTCOL)) | |
824 { | |
825 getvvcol(wp, &wp->w_cursor, NULL, &(wp->w_virtcol), NULL); | |
826 wp->w_valid |= VALID_VIRTCOL; | |
740 | 827 #ifdef FEAT_SYN_HL |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
828 if (wp->w_p_cuc && !pum_visible()) |
740 | 829 redraw_win_later(wp, SOME_VALID); |
830 #endif | |
7 | 831 } |
832 } | |
833 | |
834 /* | |
835 * Validate curwin->w_cline_height only. | |
836 */ | |
18892
fb2d26bc8ca1
patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
837 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
838 validate_cheight(void) |
7 | 839 { |
840 check_cursor_moved(curwin); | |
841 if (!(curwin->w_valid & VALID_CHEIGHT)) | |
842 { | |
843 #ifdef FEAT_DIFF | |
844 if (curwin->w_cursor.lnum == curwin->w_topline) | |
845 curwin->w_cline_height = plines_nofill(curwin->w_cursor.lnum) | |
846 + curwin->w_topfill; | |
847 else | |
848 #endif | |
849 curwin->w_cline_height = plines(curwin->w_cursor.lnum); | |
850 #ifdef FEAT_FOLDING | |
851 curwin->w_cline_folded = hasFolding(curwin->w_cursor.lnum, NULL, NULL); | |
852 #endif | |
853 curwin->w_valid |= VALID_CHEIGHT; | |
854 } | |
855 } | |
856 | |
857 /* | |
1668 | 858 * Validate w_wcol and w_virtcol only. |
7 | 859 */ |
860 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
861 validate_cursor_col(void) |
7 | 862 { |
863 colnr_T off; | |
864 colnr_T col; | |
2070
4483ee552619
updated for version 7.2.355
Bram Moolenaar <bram@zimbu.org>
parents:
1980
diff
changeset
|
865 int width; |
7 | 866 |
867 validate_virtcol(); | |
868 if (!(curwin->w_valid & VALID_WCOL)) | |
869 { | |
870 col = curwin->w_virtcol; | |
871 off = curwin_col_off(); | |
872 col += off; | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
873 width = curwin->w_width - off + curwin_col_off2(); |
7 | 874 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
875 // long line wrapping, adjust curwin->w_wrow |
1668 | 876 if (curwin->w_p_wrap |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
877 && col >= (colnr_T)curwin->w_width |
2070
4483ee552619
updated for version 7.2.355
Bram Moolenaar <bram@zimbu.org>
parents:
1980
diff
changeset
|
878 && width > 0) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
879 // use same formula as what is used in curs_columns() |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
880 col -= ((col - curwin->w_width) / width + 1) * width; |
1668 | 881 if (col > (int)curwin->w_leftcol) |
882 col -= curwin->w_leftcol; | |
883 else | |
884 col = 0; | |
7 | 885 curwin->w_wcol = col; |
1668 | 886 |
7 | 887 curwin->w_valid |= VALID_WCOL; |
22890
255473b88c8e
patch 8.2.1992: build fails with small features
Bram Moolenaar <Bram@vim.org>
parents:
22886
diff
changeset
|
888 #ifdef FEAT_PROP_POPUP |
22886
38324d4f1c94
patch 8.2.1990: cursor position wrong in terminal popup with finished job
Bram Moolenaar <Bram@vim.org>
parents:
22782
diff
changeset
|
889 curwin->w_flags &= ~WFLAG_WCOL_OFF_ADDED; |
22890
255473b88c8e
patch 8.2.1992: build fails with small features
Bram Moolenaar <Bram@vim.org>
parents:
22886
diff
changeset
|
890 #endif |
7 | 891 } |
892 } | |
893 | |
894 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
895 * Compute offset of a window, occupied by absolute or relative line number, |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
896 * fold column and sign column (these don't move when scrolling horizontally). |
7 | 897 */ |
898 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
899 win_col_off(win_T *wp) |
7 | 900 { |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
901 return (((wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) + 1 : 0) |
7 | 902 #ifdef FEAT_CMDWIN |
903 + (cmdwin_type == 0 || wp != curwin ? 0 : 1) | |
904 #endif | |
905 #ifdef FEAT_FOLDING | |
906 + wp->w_p_fdc | |
907 #endif | |
908 #ifdef FEAT_SIGNS | |
9852
4eea48b76d03
commit https://github.com/vim/vim/commit/95ec9d6a6ab3117d60ff638670a803d43974ba51
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
909 + (signcolumn_on(wp) ? 2 : 0) |
7 | 910 #endif |
911 ); | |
912 } | |
913 | |
914 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
915 curwin_col_off(void) |
7 | 916 { |
917 return win_col_off(curwin); | |
918 } | |
919 | |
920 /* | |
921 * Return the difference in column offset for the second screen line of a | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
922 * wrapped line. It's 8 if 'number' or 'relativenumber' is on and 'n' is in |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
923 * 'cpoptions'. |
7 | 924 */ |
925 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
926 win_col_off2(win_T *wp) |
7 | 927 { |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
928 if ((wp->w_p_nu || wp->w_p_rnu) && vim_strchr(p_cpo, CPO_NUMCOL) != NULL) |
13 | 929 return number_width(wp) + 1; |
7 | 930 return 0; |
931 } | |
932 | |
933 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
934 curwin_col_off2(void) |
7 | 935 { |
936 return win_col_off2(curwin); | |
937 } | |
938 | |
939 /* | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15414
diff
changeset
|
940 * Compute curwin->w_wcol and curwin->w_virtcol. |
7 | 941 * Also updates curwin->w_wrow and curwin->w_cline_row. |
942 * Also updates curwin->w_leftcol. | |
943 */ | |
944 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
945 curs_columns( |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
946 int may_scroll) // when TRUE, may scroll horizontally |
7 | 947 { |
948 int diff; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
949 int extra; // offset for first screen line |
7 | 950 int off_left, off_right; |
951 int n; | |
952 int p_lines; | |
953 int width = 0; | |
954 int textwidth; | |
955 int new_leftcol; | |
956 colnr_T startcol; | |
957 colnr_T endcol; | |
958 colnr_T prev_skipcol; | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
959 long so = get_scrolloff_value(); |
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
960 long siso = get_sidescrolloff_value(); |
7 | 961 |
962 /* | |
963 * First make sure that w_topline is valid (after moving the cursor). | |
964 */ | |
965 update_topline(); | |
966 | |
967 /* | |
968 * Next make sure that w_cline_row is valid. | |
969 */ | |
970 if (!(curwin->w_valid & VALID_CROW)) | |
6441 | 971 curs_rows(curwin); |
7 | 972 |
973 /* | |
974 * Compute the number of virtual columns. | |
975 */ | |
976 #ifdef FEAT_FOLDING | |
977 if (curwin->w_cline_folded) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
978 // In a folded line the cursor is always in the first column |
7 | 979 startcol = curwin->w_virtcol = endcol = curwin->w_leftcol; |
980 else | |
981 #endif | |
982 getvvcol(curwin, &curwin->w_cursor, | |
983 &startcol, &(curwin->w_virtcol), &endcol); | |
984 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
985 // remove '$' from change command when cursor moves onto it |
7 | 986 if (startcol > dollar_vcol) |
3318 | 987 dollar_vcol = -1; |
7 | 988 |
989 extra = curwin_col_off(); | |
990 curwin->w_wcol = curwin->w_virtcol + extra; | |
991 endcol += extra; | |
992 | |
993 /* | |
994 * Now compute w_wrow, counting screen lines from w_cline_row. | |
995 */ | |
996 curwin->w_wrow = curwin->w_cline_row; | |
997 | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
998 textwidth = curwin->w_width - extra; |
7 | 999 if (textwidth <= 0) |
1000 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1001 // No room for text, put cursor in last char of window. |
25172
406ab8d0bc0f
patch 8.2.3122: with 'nowrap' cursor position is unexected in narrow window
Bram Moolenaar <Bram@vim.org>
parents:
23905
diff
changeset
|
1002 // If not wrapping, the last non-empty line. |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1003 curwin->w_wcol = curwin->w_width - 1; |
25172
406ab8d0bc0f
patch 8.2.3122: with 'nowrap' cursor position is unexected in narrow window
Bram Moolenaar <Bram@vim.org>
parents:
23905
diff
changeset
|
1004 if (curwin->w_p_wrap) |
406ab8d0bc0f
patch 8.2.3122: with 'nowrap' cursor position is unexected in narrow window
Bram Moolenaar <Bram@vim.org>
parents:
23905
diff
changeset
|
1005 curwin->w_wrow = curwin->w_height - 1; |
406ab8d0bc0f
patch 8.2.3122: with 'nowrap' cursor position is unexected in narrow window
Bram Moolenaar <Bram@vim.org>
parents:
23905
diff
changeset
|
1006 else |
406ab8d0bc0f
patch 8.2.3122: with 'nowrap' cursor position is unexected in narrow window
Bram Moolenaar <Bram@vim.org>
parents:
23905
diff
changeset
|
1007 curwin->w_wrow = curwin->w_height - 1 - curwin->w_empty_rows; |
7 | 1008 } |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
1009 else if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 1010 { |
1011 width = textwidth + curwin_col_off2(); | |
1012 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1013 // long line wrapping, adjust curwin->w_wrow |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1014 if (curwin->w_wcol >= curwin->w_width) |
7 | 1015 { |
18580
4ac042c8ed98
patch 8.1.2284: compiler warning for unused variable
Bram Moolenaar <Bram@vim.org>
parents:
18574
diff
changeset
|
1016 #ifdef FEAT_LINEBREAK |
18574
8b0114ffde2b
patch 8.1.2281: 'showbreak' cannot be set for one window
Bram Moolenaar <Bram@vim.org>
parents:
18469
diff
changeset
|
1017 char_u *sbr; |
18580
4ac042c8ed98
patch 8.1.2284: compiler warning for unused variable
Bram Moolenaar <Bram@vim.org>
parents:
18574
diff
changeset
|
1018 #endif |
18574
8b0114ffde2b
patch 8.1.2281: 'showbreak' cannot be set for one window
Bram Moolenaar <Bram@vim.org>
parents:
18469
diff
changeset
|
1019 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1020 // this same formula is used in validate_cursor_col() |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1021 n = (curwin->w_wcol - curwin->w_width) / width + 1; |
7 | 1022 curwin->w_wcol -= n * width; |
1023 curwin->w_wrow += n; | |
1024 | |
1025 #ifdef FEAT_LINEBREAK | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1026 // When cursor wraps to first char of next line in Insert |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1027 // mode, the 'showbreak' string isn't shown, backup to first |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1028 // column |
18574
8b0114ffde2b
patch 8.1.2281: 'showbreak' cannot be set for one window
Bram Moolenaar <Bram@vim.org>
parents:
18469
diff
changeset
|
1029 sbr = get_showbreak_value(curwin); |
8b0114ffde2b
patch 8.1.2281: 'showbreak' cannot be set for one window
Bram Moolenaar <Bram@vim.org>
parents:
18469
diff
changeset
|
1030 if (*sbr && *ml_get_cursor() == NUL |
8b0114ffde2b
patch 8.1.2281: 'showbreak' cannot be set for one window
Bram Moolenaar <Bram@vim.org>
parents:
18469
diff
changeset
|
1031 && curwin->w_wcol == (int)vim_strsize(sbr)) |
7 | 1032 curwin->w_wcol = 0; |
1033 #endif | |
1034 } | |
1035 } | |
1036 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1037 // No line wrapping: compute curwin->w_leftcol if scrolling is on and line |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1038 // is not folded. |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1039 // If scrolling is off, curwin->w_leftcol is assumed to be 0 |
3263 | 1040 else if (may_scroll |
7 | 1041 #ifdef FEAT_FOLDING |
1042 && !curwin->w_cline_folded | |
1043 #endif | |
1044 ) | |
1045 { | |
1046 /* | |
1047 * If Cursor is left of the screen, scroll rightwards. | |
1048 * If Cursor is right of the screen, scroll leftwards | |
1049 * If we get closer to the edge than 'sidescrolloff', scroll a little | |
1050 * extra | |
1051 */ | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
1052 off_left = (int)startcol - (int)curwin->w_leftcol - siso; |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1053 off_right = (int)endcol - (int)(curwin->w_leftcol + curwin->w_width |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
1054 - siso) + 1; |
7 | 1055 if (off_left < 0 || off_right > 0) |
1056 { | |
1057 if (off_left < 0) | |
1058 diff = -off_left; | |
1059 else | |
1060 diff = off_right; | |
1061 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1062 // When far off or not enough room on either side, put cursor in |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1063 // middle of window. |
7 | 1064 if (p_ss == 0 || diff >= textwidth / 2 || off_right >= off_left) |
1065 new_leftcol = curwin->w_wcol - extra - textwidth / 2; | |
1066 else | |
1067 { | |
1068 if (diff < p_ss) | |
1069 diff = p_ss; | |
1070 if (off_left < 0) | |
1071 new_leftcol = curwin->w_leftcol - diff; | |
1072 else | |
1073 new_leftcol = curwin->w_leftcol + diff; | |
1074 } | |
1075 if (new_leftcol < 0) | |
1076 new_leftcol = 0; | |
1077 if (new_leftcol != (int)curwin->w_leftcol) | |
1078 { | |
1079 curwin->w_leftcol = new_leftcol; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1080 // screen has to be redrawn with new curwin->w_leftcol |
7 | 1081 redraw_later(NOT_VALID); |
1082 } | |
1083 } | |
1084 curwin->w_wcol -= curwin->w_leftcol; | |
1085 } | |
1086 else if (curwin->w_wcol > (int)curwin->w_leftcol) | |
1087 curwin->w_wcol -= curwin->w_leftcol; | |
1088 else | |
1089 curwin->w_wcol = 0; | |
1090 | |
1091 #ifdef FEAT_DIFF | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1092 // Skip over filler lines. At the top use w_topfill, there |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1093 // may be some filler lines above the window. |
7 | 1094 if (curwin->w_cursor.lnum == curwin->w_topline) |
1095 curwin->w_wrow += curwin->w_topfill; | |
1096 else | |
1097 curwin->w_wrow += diff_check_fill(curwin, curwin->w_cursor.lnum); | |
1098 #endif | |
1099 | |
1100 prev_skipcol = curwin->w_skipcol; | |
1101 | |
1102 p_lines = 0; | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
1103 |
7 | 1104 if ((curwin->w_wrow >= curwin->w_height |
1105 || ((prev_skipcol > 0 | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
1106 || curwin->w_wrow + so >= curwin->w_height) |
7 | 1107 && (p_lines = |
1108 #ifdef FEAT_DIFF | |
1109 plines_win_nofill | |
1110 #else | |
1111 plines_win | |
1112 #endif | |
1113 (curwin, curwin->w_cursor.lnum, FALSE)) | |
1114 - 1 >= curwin->w_height)) | |
1115 && curwin->w_height != 0 | |
1116 && curwin->w_cursor.lnum == curwin->w_topline | |
1117 && width > 0 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
1118 && curwin->w_width != 0) |
7 | 1119 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1120 // Cursor past end of screen. Happens with a single line that does |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1121 // not fit on screen. Find a skipcol to show the text around the |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1122 // cursor. Avoid scrolling all the time. compute value of "extra": |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1123 // 1: Less than 'scrolloff' lines above |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1124 // 2: Less than 'scrolloff' lines below |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1125 // 3: both of them |
7 | 1126 extra = 0; |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
1127 if (curwin->w_skipcol + so * width > curwin->w_virtcol) |
7 | 1128 extra = 1; |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1129 // Compute last display line of the buffer line that we want at the |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1130 // bottom of the window. |
7 | 1131 if (p_lines == 0) |
1132 p_lines = plines_win(curwin, curwin->w_cursor.lnum, FALSE); | |
1133 --p_lines; | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
1134 if (p_lines > curwin->w_wrow + so) |
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
1135 n = curwin->w_wrow + so; |
7 | 1136 else |
1137 n = p_lines; | |
23905
68f506771741
patch 8.2.2495: text jumps up and down when moving the cursor
Bram Moolenaar <Bram@vim.org>
parents:
23306
diff
changeset
|
1138 if ((colnr_T)n >= curwin->w_height + curwin->w_skipcol / width - so) |
7 | 1139 extra += 2; |
1140 | |
23905
68f506771741
patch 8.2.2495: text jumps up and down when moving the cursor
Bram Moolenaar <Bram@vim.org>
parents:
23306
diff
changeset
|
1141 if (extra == 3 || p_lines <= so * 2) |
7 | 1142 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1143 // not enough room for 'scrolloff', put cursor in the middle |
7 | 1144 n = curwin->w_virtcol / width; |
1145 if (n > curwin->w_height / 2) | |
1146 n -= curwin->w_height / 2; | |
1147 else | |
1148 n = 0; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1149 // don't skip more than necessary |
7 | 1150 if (n > p_lines - curwin->w_height + 1) |
1151 n = p_lines - curwin->w_height + 1; | |
1152 curwin->w_skipcol = n * width; | |
1153 } | |
1154 else if (extra == 1) | |
1155 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1156 // less then 'scrolloff' lines above, decrease skipcol |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
1157 extra = (curwin->w_skipcol + so * width - curwin->w_virtcol |
7 | 1158 + width - 1) / width; |
1159 if (extra > 0) | |
1160 { | |
1161 if ((colnr_T)(extra * width) > curwin->w_skipcol) | |
1162 extra = curwin->w_skipcol / width; | |
1163 curwin->w_skipcol -= extra * width; | |
1164 } | |
1165 } | |
1166 else if (extra == 2) | |
1167 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1168 // less then 'scrolloff' lines below, increase skipcol |
7 | 1169 endcol = (n - curwin->w_height + 1) * width; |
1170 while (endcol > curwin->w_virtcol) | |
1171 endcol -= width; | |
1172 if (endcol > curwin->w_skipcol) | |
1173 curwin->w_skipcol = endcol; | |
1174 } | |
1175 | |
1176 curwin->w_wrow -= curwin->w_skipcol / width; | |
1177 if (curwin->w_wrow >= curwin->w_height) | |
1178 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1179 // small window, make sure cursor is in it |
7 | 1180 extra = curwin->w_wrow - curwin->w_height + 1; |
1181 curwin->w_skipcol += extra * width; | |
1182 curwin->w_wrow -= extra; | |
1183 } | |
1184 | |
1185 extra = ((int)prev_skipcol - (int)curwin->w_skipcol) / width; | |
1186 if (extra > 0) | |
1187 win_ins_lines(curwin, 0, extra, FALSE, FALSE); | |
1188 else if (extra < 0) | |
12152
69af108df70e
patch 8.0.0956: scrolling in a terminal window has flicker
Christian Brabandt <cb@256bit.org>
parents:
11258
diff
changeset
|
1189 win_del_lines(curwin, 0, -extra, FALSE, FALSE, 0); |
7 | 1190 } |
1191 else | |
1192 curwin->w_skipcol = 0; | |
1193 if (prev_skipcol != curwin->w_skipcol) | |
1194 redraw_later(NOT_VALID); | |
1195 | |
740 | 1196 #ifdef FEAT_SYN_HL |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1197 // Redraw when w_virtcol changes and 'cursorcolumn' is set |
5749 | 1198 if (curwin->w_p_cuc && (curwin->w_valid & VALID_VIRTCOL) == 0 |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
1199 && !pum_visible()) |
5749 | 1200 redraw_later(SOME_VALID); |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1201 #endif |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
18931
diff
changeset
|
1202 #if defined(FEAT_PROP_POPUP) && defined(FEAT_TERMINAL) |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
18931
diff
changeset
|
1203 if (popup_is_popup(curwin) && curbuf->b_term != NULL) |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
18931
diff
changeset
|
1204 { |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
18931
diff
changeset
|
1205 curwin->w_wrow += popup_top_extra(curwin); |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
18931
diff
changeset
|
1206 curwin->w_wcol += popup_left_extra(curwin); |
22886
38324d4f1c94
patch 8.2.1990: cursor position wrong in terminal popup with finished job
Bram Moolenaar <Bram@vim.org>
parents:
22782
diff
changeset
|
1207 curwin->w_flags |= WFLAG_WCOL_OFF_ADDED + WFLAG_WROW_OFF_ADDED; |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
18931
diff
changeset
|
1208 } |
22886
38324d4f1c94
patch 8.2.1990: cursor position wrong in terminal popup with finished job
Bram Moolenaar <Bram@vim.org>
parents:
22782
diff
changeset
|
1209 else |
38324d4f1c94
patch 8.2.1990: cursor position wrong in terminal popup with finished job
Bram Moolenaar <Bram@vim.org>
parents:
22782
diff
changeset
|
1210 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED + WFLAG_WROW_OFF_ADDED); |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
18931
diff
changeset
|
1211 #endif |
740 | 1212 |
18621
a9bfdc5ea1ec
patch 8.1.2303: cursor in wrong position after horizontal scroll
Bram Moolenaar <Bram@vim.org>
parents:
18580
diff
changeset
|
1213 // now w_leftcol is valid, avoid check_cursor_moved() thinking otherwise |
a9bfdc5ea1ec
patch 8.1.2303: cursor in wrong position after horizontal scroll
Bram Moolenaar <Bram@vim.org>
parents:
18580
diff
changeset
|
1214 curwin->w_valid_leftcol = curwin->w_leftcol; |
a9bfdc5ea1ec
patch 8.1.2303: cursor in wrong position after horizontal scroll
Bram Moolenaar <Bram@vim.org>
parents:
18580
diff
changeset
|
1215 |
7 | 1216 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL; |
1217 } | |
1218 | |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18621
diff
changeset
|
1219 #if (defined(FEAT_EVAL) || defined(FEAT_PROP_POPUP)) || defined(PROTO) |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1220 /* |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1221 * Compute the screen position of text character at "pos" in window "wp" |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1222 * The resulting values are one-based, zero when character is not visible. |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1223 */ |
17863
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1224 void |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1225 textpos2screenpos( |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1226 win_T *wp, |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1227 pos_T *pos, |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1228 int *rowp, // screen row |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1229 int *scolp, // start screen column |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1230 int *ccolp, // cursor screen column |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1231 int *ecolp) // end screen column |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1232 { |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1233 colnr_T scol = 0, ccol = 0, ecol = 0; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1234 int row = 0; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1235 int rowoff = 0; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1236 colnr_T coloff = 0; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1237 |
25312
7a254d0705e2
patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents:
25172
diff
changeset
|
1238 if (pos->lnum >= wp->w_topline && pos->lnum <= wp->w_botline) |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1239 { |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1240 colnr_T off; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1241 colnr_T col; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1242 int width; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1243 |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1244 row = plines_m_win(wp, wp->w_topline, pos->lnum - 1) + 1; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1245 getvcol(wp, pos, &scol, &ccol, &ecol); |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1246 |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1247 // similar to what is done in validate_cursor_col() |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1248 col = scol; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1249 off = win_col_off(wp); |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1250 col += off; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1251 width = wp->w_width - off + win_col_off2(wp); |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1252 |
17863
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1253 // long line wrapping, adjust row |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1254 if (wp->w_p_wrap |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1255 && col >= (colnr_T)wp->w_width |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1256 && width > 0) |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1257 { |
17863
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1258 // use same formula as what is used in curs_columns() |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1259 rowoff = ((col - wp->w_width) / width + 1); |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1260 col -= rowoff * width; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1261 } |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1262 col -= wp->w_leftcol; |
18469
66964658cc3c
patch 8.1.2228: screenpos() returns wrong values when 'number' is set
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
1263 if (col >= wp->w_width) |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1264 col = -1; |
25312
7a254d0705e2
patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents:
25172
diff
changeset
|
1265 if (col >= 0 && row + rowoff <= wp->w_height) |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1266 coloff = col - scol + wp->w_wincol + 1; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1267 else |
25312
7a254d0705e2
patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents:
25172
diff
changeset
|
1268 // character is left, right or below of the window |
7a254d0705e2
patch 8.2.3193: screenpos() is wrong when 'display' is "lastline"
Bram Moolenaar <Bram@vim.org>
parents:
25172
diff
changeset
|
1269 row = rowoff = scol = ccol = ecol = 0; |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1270 } |
23213
477f1b4c6826
patch 8.2.2152: screenpos() does not include the WinBar offset
Bram Moolenaar <Bram@vim.org>
parents:
22890
diff
changeset
|
1271 *rowp = W_WINROW(wp) + row + rowoff; |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1272 *scolp = scol + coloff; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1273 *ccolp = ccol + coloff; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1274 *ecolp = ecol + coloff; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1275 } |
17863
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1276 #endif |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1277 |
17863
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1278 #if defined(FEAT_EVAL) || defined(PROTO) |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1279 /* |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1280 * "screenpos({winid}, {lnum}, {col})" function |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1281 */ |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1282 void |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1283 f_screenpos(typval_T *argvars UNUSED, typval_T *rettv) |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1284 { |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1285 dict_T *dict; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1286 win_T *wp; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1287 pos_T pos; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1288 int row = 0; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1289 int scol = 0, ccol = 0, ecol = 0; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1290 |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1291 if (rettv_dict_alloc(rettv) != OK) |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1292 return; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1293 dict = rettv->vval.v_dict; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1294 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25312
diff
changeset
|
1295 if (in_vim9script() |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25312
diff
changeset
|
1296 && (check_for_number_arg(argvars, 0) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25312
diff
changeset
|
1297 || check_for_number_arg(argvars, 1) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25312
diff
changeset
|
1298 || check_for_number_arg(argvars, 2) == FAIL)) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25312
diff
changeset
|
1299 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25312
diff
changeset
|
1300 |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1301 wp = find_win_by_nr_or_id(&argvars[0]); |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1302 if (wp == NULL) |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1303 return; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1304 |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1305 pos.lnum = tv_get_number(&argvars[1]); |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1306 pos.col = tv_get_number(&argvars[2]) - 1; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1307 pos.coladd = 0; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1308 textpos2screenpos(wp, &pos, &row, &scol, &ccol, &ecol); |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1309 |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1310 dict_add_number(dict, "row", row); |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1311 dict_add_number(dict, "col", scol); |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1312 dict_add_number(dict, "curscol", ccol); |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1313 dict_add_number(dict, "endcol", ecol); |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1314 } |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1315 #endif |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1316 |
7 | 1317 /* |
1318 * Scroll the current window down by "line_count" logical lines. "CTRL-Y" | |
1319 */ | |
1320 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1321 scrolldown( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1322 long line_count, |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1323 int byfold UNUSED) // TRUE: count a closed fold as one line |
7 | 1324 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1325 long done = 0; // total # of physical lines done |
7 | 1326 int wrow; |
1327 int moved = FALSE; | |
1328 | |
1329 #ifdef FEAT_FOLDING | |
1330 linenr_T first; | |
1331 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1332 // Make sure w_topline is at the first of a sequence of folded lines. |
7 | 1333 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
1334 #endif | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1335 validate_cursor(); // w_wrow needs to be valid |
7 | 1336 while (line_count-- > 0) |
1337 { | |
1338 #ifdef FEAT_DIFF | |
1980 | 1339 if (curwin->w_topfill < diff_check(curwin, curwin->w_topline) |
1340 && curwin->w_topfill < curwin->w_height - 1) | |
7 | 1341 { |
1342 ++curwin->w_topfill; | |
1343 ++done; | |
1344 } | |
1345 else | |
1346 #endif | |
1347 { | |
1348 if (curwin->w_topline == 1) | |
1349 break; | |
1350 --curwin->w_topline; | |
1351 #ifdef FEAT_DIFF | |
1352 curwin->w_topfill = 0; | |
1353 #endif | |
1354 #ifdef FEAT_FOLDING | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1355 // A sequence of folded lines only counts for one logical line |
7 | 1356 if (hasFolding(curwin->w_topline, &first, NULL)) |
1357 { | |
1358 ++done; | |
1359 if (!byfold) | |
1360 line_count -= curwin->w_topline - first - 1; | |
1361 curwin->w_botline -= curwin->w_topline - first; | |
1362 curwin->w_topline = first; | |
1363 } | |
1364 else | |
1365 #endif | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
1366 done += PLINES_NOFILL(curwin->w_topline); |
7 | 1367 } |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1368 --curwin->w_botline; // approximate w_botline |
7 | 1369 invalidate_botline(); |
1370 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1371 curwin->w_wrow += done; // keep w_wrow updated |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1372 curwin->w_cline_row += done; // keep w_cline_row updated |
7 | 1373 |
1374 #ifdef FEAT_DIFF | |
1375 if (curwin->w_cursor.lnum == curwin->w_topline) | |
1376 curwin->w_cline_row = 0; | |
1377 check_topfill(curwin, TRUE); | |
1378 #endif | |
1379 | |
1380 /* | |
1381 * Compute the row number of the last row of the cursor line | |
1382 * and move the cursor onto the displayed part of the window. | |
1383 */ | |
1384 wrow = curwin->w_wrow; | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
1385 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 1386 { |
1387 validate_virtcol(); | |
1388 validate_cheight(); | |
1389 wrow += curwin->w_cline_height - 1 - | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1390 curwin->w_virtcol / curwin->w_width; |
7 | 1391 } |
1392 while (wrow >= curwin->w_height && curwin->w_cursor.lnum > 1) | |
1393 { | |
1394 #ifdef FEAT_FOLDING | |
1395 if (hasFolding(curwin->w_cursor.lnum, &first, NULL)) | |
1396 { | |
1397 --wrow; | |
1398 if (first == 1) | |
1399 curwin->w_cursor.lnum = 1; | |
1400 else | |
1401 curwin->w_cursor.lnum = first - 1; | |
1402 } | |
1403 else | |
1404 #endif | |
1405 wrow -= plines(curwin->w_cursor.lnum--); | |
1406 curwin->w_valid &= | |
1407 ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL); | |
1408 moved = TRUE; | |
1409 } | |
1410 if (moved) | |
1411 { | |
1412 #ifdef FEAT_FOLDING | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1413 // Move cursor to first line of closed fold. |
7 | 1414 foldAdjustCursor(); |
1415 #endif | |
1416 coladvance(curwin->w_curswant); | |
1417 } | |
1418 } | |
1419 | |
1420 /* | |
1421 * Scroll the current window up by "line_count" logical lines. "CTRL-E" | |
1422 */ | |
1423 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1424 scrollup( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1425 long line_count, |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1426 int byfold UNUSED) // TRUE: count a closed fold as one line |
7 | 1427 { |
1428 #if defined(FEAT_FOLDING) || defined(FEAT_DIFF) | |
1429 linenr_T lnum; | |
1430 | |
1431 if ( | |
1432 # ifdef FEAT_FOLDING | |
1433 (byfold && hasAnyFolding(curwin)) | |
1434 # ifdef FEAT_DIFF | |
1435 || | |
1436 # endif | |
1437 # endif | |
1438 # ifdef FEAT_DIFF | |
1439 curwin->w_p_diff | |
1440 # endif | |
1441 ) | |
1442 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1443 // count each sequence of folded lines as one logical line |
7 | 1444 lnum = curwin->w_topline; |
1445 while (line_count--) | |
1446 { | |
1447 # ifdef FEAT_DIFF | |
1448 if (curwin->w_topfill > 0) | |
1449 --curwin->w_topfill; | |
1450 else | |
1451 # endif | |
1452 { | |
1453 # ifdef FEAT_FOLDING | |
1454 if (byfold) | |
1455 (void)hasFolding(lnum, NULL, &lnum); | |
1456 # endif | |
1457 if (lnum >= curbuf->b_ml.ml_line_count) | |
1458 break; | |
1459 ++lnum; | |
1460 # ifdef FEAT_DIFF | |
1461 curwin->w_topfill = diff_check_fill(curwin, lnum); | |
1462 # endif | |
1463 } | |
1464 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1465 // approximate w_botline |
7 | 1466 curwin->w_botline += lnum - curwin->w_topline; |
1467 curwin->w_topline = lnum; | |
1468 } | |
1469 else | |
1470 #endif | |
1471 { | |
1472 curwin->w_topline += line_count; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1473 curwin->w_botline += line_count; // approximate w_botline |
7 | 1474 } |
1475 | |
1476 if (curwin->w_topline > curbuf->b_ml.ml_line_count) | |
1477 curwin->w_topline = curbuf->b_ml.ml_line_count; | |
1478 if (curwin->w_botline > curbuf->b_ml.ml_line_count + 1) | |
1479 curwin->w_botline = curbuf->b_ml.ml_line_count + 1; | |
1480 | |
1481 #ifdef FEAT_DIFF | |
1482 check_topfill(curwin, FALSE); | |
1483 #endif | |
1484 | |
1485 #ifdef FEAT_FOLDING | |
1486 if (hasAnyFolding(curwin)) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1487 // Make sure w_topline is at the first of a sequence of folded lines. |
7 | 1488 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
1489 #endif | |
1490 | |
1491 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); | |
1492 if (curwin->w_cursor.lnum < curwin->w_topline) | |
1493 { | |
1494 curwin->w_cursor.lnum = curwin->w_topline; | |
1495 curwin->w_valid &= | |
1496 ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL); | |
1497 coladvance(curwin->w_curswant); | |
1498 } | |
1499 } | |
1500 | |
1501 #ifdef FEAT_DIFF | |
1502 /* | |
1503 * Don't end up with too many filler lines in the window. | |
1504 */ | |
1505 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1506 check_topfill( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1507 win_T *wp, |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1508 int down) // when TRUE scroll down when not enough space |
7 | 1509 { |
1510 int n; | |
1511 | |
1512 if (wp->w_topfill > 0) | |
1513 { | |
1514 n = plines_win_nofill(wp, wp->w_topline, TRUE); | |
1515 if (wp->w_topfill + n > wp->w_height) | |
1516 { | |
1517 if (down && wp->w_topline > 1) | |
1518 { | |
1519 --wp->w_topline; | |
1520 wp->w_topfill = 0; | |
1521 } | |
1522 else | |
1523 { | |
1524 wp->w_topfill = wp->w_height - n; | |
1525 if (wp->w_topfill < 0) | |
1526 wp->w_topfill = 0; | |
1527 } | |
1528 } | |
1529 } | |
1530 } | |
1531 | |
1532 /* | |
1533 * Use as many filler lines as possible for w_topline. Make sure w_topline | |
1534 * is still visible. | |
1535 */ | |
1536 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1537 max_topfill(void) |
7 | 1538 { |
1539 int n; | |
1540 | |
1541 n = plines_nofill(curwin->w_topline); | |
1542 if (n >= curwin->w_height) | |
1543 curwin->w_topfill = 0; | |
1544 else | |
1545 { | |
1546 curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline); | |
1547 if (curwin->w_topfill + n > curwin->w_height) | |
1548 curwin->w_topfill = curwin->w_height - n; | |
1549 } | |
1550 } | |
1551 #endif | |
1552 | |
1553 /* | |
1554 * Scroll the screen one line down, but don't do it if it would move the | |
1555 * cursor off the screen. | |
1556 */ | |
1557 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1558 scrolldown_clamp(void) |
7 | 1559 { |
1560 int end_row; | |
1561 #ifdef FEAT_DIFF | |
1562 int can_fill = (curwin->w_topfill | |
1563 < diff_check_fill(curwin, curwin->w_topline)); | |
1564 #endif | |
1565 | |
1566 if (curwin->w_topline <= 1 | |
1567 #ifdef FEAT_DIFF | |
1568 && !can_fill | |
1569 #endif | |
1570 ) | |
1571 return; | |
1572 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1573 validate_cursor(); // w_wrow needs to be valid |
7 | 1574 |
1575 /* | |
1576 * Compute the row number of the last row of the cursor line | |
1577 * and make sure it doesn't go off the screen. Make sure the cursor | |
1578 * doesn't go past 'scrolloff' lines from the screen end. | |
1579 */ | |
1580 end_row = curwin->w_wrow; | |
1581 #ifdef FEAT_DIFF | |
1582 if (can_fill) | |
1583 ++end_row; | |
1584 else | |
1585 end_row += plines_nofill(curwin->w_topline - 1); | |
1586 #else | |
1587 end_row += plines(curwin->w_topline - 1); | |
1588 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
1589 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 1590 { |
1591 validate_cheight(); | |
1592 validate_virtcol(); | |
1593 end_row += curwin->w_cline_height - 1 - | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1594 curwin->w_virtcol / curwin->w_width; |
7 | 1595 } |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
1596 if (end_row < curwin->w_height - get_scrolloff_value()) |
7 | 1597 { |
1598 #ifdef FEAT_DIFF | |
1599 if (can_fill) | |
1600 { | |
1601 ++curwin->w_topfill; | |
1602 check_topfill(curwin, TRUE); | |
1603 } | |
1604 else | |
1605 { | |
1606 --curwin->w_topline; | |
1607 curwin->w_topfill = 0; | |
1608 } | |
1609 #else | |
1610 --curwin->w_topline; | |
1611 #endif | |
1612 #ifdef FEAT_FOLDING | |
7009 | 1613 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
7 | 1614 #endif |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1615 --curwin->w_botline; // approximate w_botline |
7 | 1616 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); |
1617 } | |
1618 } | |
1619 | |
1620 /* | |
1621 * Scroll the screen one line up, but don't do it if it would move the cursor | |
1622 * off the screen. | |
1623 */ | |
1624 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1625 scrollup_clamp(void) |
7 | 1626 { |
1627 int start_row; | |
1628 | |
1629 if (curwin->w_topline == curbuf->b_ml.ml_line_count | |
1630 #ifdef FEAT_DIFF | |
1631 && curwin->w_topfill == 0 | |
1632 #endif | |
1633 ) | |
1634 return; | |
1635 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1636 validate_cursor(); // w_wrow needs to be valid |
7 | 1637 |
1638 /* | |
1639 * Compute the row number of the first row of the cursor line | |
1640 * and make sure it doesn't go off the screen. Make sure the cursor | |
1641 * doesn't go before 'scrolloff' lines from the screen start. | |
1642 */ | |
1643 #ifdef FEAT_DIFF | |
1644 start_row = curwin->w_wrow - plines_nofill(curwin->w_topline) | |
1645 - curwin->w_topfill; | |
1646 #else | |
1647 start_row = curwin->w_wrow - plines(curwin->w_topline); | |
1648 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
1649 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 1650 { |
1651 validate_virtcol(); | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1652 start_row -= curwin->w_virtcol / curwin->w_width; |
7 | 1653 } |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
1654 if (start_row >= get_scrolloff_value()) |
7 | 1655 { |
1656 #ifdef FEAT_DIFF | |
1657 if (curwin->w_topfill > 0) | |
1658 --curwin->w_topfill; | |
1659 else | |
1660 #endif | |
36 | 1661 { |
1662 #ifdef FEAT_FOLDING | |
1663 (void)hasFolding(curwin->w_topline, NULL, &curwin->w_topline); | |
1664 #endif | |
7 | 1665 ++curwin->w_topline; |
36 | 1666 } |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1667 ++curwin->w_botline; // approximate w_botline |
7 | 1668 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); |
1669 } | |
1670 } | |
1671 | |
1672 /* | |
1673 * Add one line above "lp->lnum". This can be a filler line, a closed fold or | |
1674 * a (wrapped) text line. Uses and sets "lp->fill". | |
1675 * Returns the height of the added line in "lp->height". | |
2082
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
1676 * Lines above the first one are incredibly high: MAXCOL. |
7 | 1677 */ |
1678 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1679 topline_back(lineoff_T *lp) |
7 | 1680 { |
1681 #ifdef FEAT_DIFF | |
1682 if (lp->fill < diff_check_fill(curwin, lp->lnum)) | |
1683 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1684 // Add a filler line. |
7 | 1685 ++lp->fill; |
1686 lp->height = 1; | |
1687 } | |
1688 else | |
1689 #endif | |
1690 { | |
1691 --lp->lnum; | |
1692 #ifdef FEAT_DIFF | |
1693 lp->fill = 0; | |
1694 #endif | |
1695 if (lp->lnum < 1) | |
1696 lp->height = MAXCOL; | |
1697 else | |
1698 #ifdef FEAT_FOLDING | |
1699 if (hasFolding(lp->lnum, &lp->lnum, NULL)) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1700 // Add a closed fold |
7 | 1701 lp->height = 1; |
1702 else | |
1703 #endif | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
1704 lp->height = PLINES_NOFILL(lp->lnum); |
7 | 1705 } |
1706 } | |
1707 | |
1708 /* | |
1709 * Add one line below "lp->lnum". This can be a filler line, a closed fold or | |
1710 * a (wrapped) text line. Uses and sets "lp->fill". | |
1711 * Returns the height of the added line in "lp->height". | |
1712 * Lines below the last one are incredibly high. | |
1713 */ | |
1714 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1715 botline_forw(lineoff_T *lp) |
7 | 1716 { |
1717 #ifdef FEAT_DIFF | |
1718 if (lp->fill < diff_check_fill(curwin, lp->lnum + 1)) | |
1719 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1720 // Add a filler line. |
7 | 1721 ++lp->fill; |
1722 lp->height = 1; | |
1723 } | |
1724 else | |
1725 #endif | |
1726 { | |
1727 ++lp->lnum; | |
1728 #ifdef FEAT_DIFF | |
1729 lp->fill = 0; | |
1730 #endif | |
1731 if (lp->lnum > curbuf->b_ml.ml_line_count) | |
1732 lp->height = MAXCOL; | |
1733 else | |
1734 #ifdef FEAT_FOLDING | |
1735 if (hasFolding(lp->lnum, NULL, &lp->lnum)) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1736 // Add a closed fold |
7 | 1737 lp->height = 1; |
1738 else | |
1739 #endif | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
1740 lp->height = PLINES_NOFILL(lp->lnum); |
7 | 1741 } |
1742 } | |
1743 | |
1744 #ifdef FEAT_DIFF | |
1745 /* | |
1746 * Switch from including filler lines below lp->lnum to including filler | |
1747 * lines above loff.lnum + 1. This keeps pointing to the same line. | |
1748 * When there are no filler lines nothing changes. | |
1749 */ | |
1750 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1751 botline_topline(lineoff_T *lp) |
7 | 1752 { |
1753 if (lp->fill > 0) | |
1754 { | |
1755 ++lp->lnum; | |
1756 lp->fill = diff_check_fill(curwin, lp->lnum) - lp->fill + 1; | |
1757 } | |
1758 } | |
1759 | |
1760 /* | |
1761 * Switch from including filler lines above lp->lnum to including filler | |
1762 * lines below loff.lnum - 1. This keeps pointing to the same line. | |
1763 * When there are no filler lines nothing changes. | |
1764 */ | |
1765 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1766 topline_botline(lineoff_T *lp) |
7 | 1767 { |
1768 if (lp->fill > 0) | |
1769 { | |
1770 lp->fill = diff_check_fill(curwin, lp->lnum) - lp->fill + 1; | |
1771 --lp->lnum; | |
1772 } | |
1773 } | |
1774 #endif | |
1775 | |
1776 /* | |
1777 * Recompute topline to put the cursor at the top of the window. | |
1778 * Scroll at least "min_scroll" lines. | |
1779 * If "always" is TRUE, always set topline (for "zt"). | |
1780 */ | |
1781 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1782 scroll_cursor_top(int min_scroll, int always) |
7 | 1783 { |
1784 int scrolled = 0; | |
1785 int extra = 0; | |
1786 int used; | |
1787 int i; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1788 linenr_T top; // just above displayed lines |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1789 linenr_T bot; // just below displayed lines |
7 | 1790 linenr_T old_topline = curwin->w_topline; |
1791 #ifdef FEAT_DIFF | |
1792 linenr_T old_topfill = curwin->w_topfill; | |
1793 #endif | |
1794 linenr_T new_topline; | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
1795 int off = get_scrolloff_value(); |
7 | 1796 |
1797 if (mouse_dragging > 0) | |
1798 off = mouse_dragging - 1; | |
1799 | |
1800 /* | |
1801 * Decrease topline until: | |
1802 * - it has become 1 | |
1803 * - (part of) the cursor line is moved off the screen or | |
1804 * - moved at least 'scrolljump' lines and | |
1805 * - at least 'scrolloff' lines above and below the cursor | |
1806 */ | |
1807 validate_cheight(); | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1808 used = curwin->w_cline_height; // includes filler lines above |
7 | 1809 if (curwin->w_cursor.lnum < curwin->w_topline) |
1810 scrolled = used; | |
1811 | |
1812 #ifdef FEAT_FOLDING | |
1813 if (hasFolding(curwin->w_cursor.lnum, &top, &bot)) | |
1814 { | |
1815 --top; | |
1816 ++bot; | |
1817 } | |
1818 else | |
1819 #endif | |
1820 { | |
1821 top = curwin->w_cursor.lnum - 1; | |
1822 bot = curwin->w_cursor.lnum + 1; | |
1823 } | |
1824 new_topline = top + 1; | |
1825 | |
1826 #ifdef FEAT_DIFF | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1827 // "used" already contains the number of filler lines above, don't add it |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1828 // again. |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1829 // Hide filler lines above cursor line by adding them to "extra". |
7088
8a58dde655a8
commit https://github.com/vim/vim/commit/a09a2c5857ab854f0870573b5160da1964c905a2
Christian Brabandt <cb@256bit.org>
parents:
7082
diff
changeset
|
1830 extra += diff_check_fill(curwin, curwin->w_cursor.lnum); |
7 | 1831 #endif |
1832 | |
1833 /* | |
1834 * Check if the lines from "top" to "bot" fit in the window. If they do, | |
1835 * set new_topline and advance "top" and "bot" to include more lines. | |
1836 */ | |
1837 while (top > 0) | |
1838 { | |
1839 #ifdef FEAT_FOLDING | |
1840 if (hasFolding(top, &top, NULL)) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1841 // count one logical line for a sequence of folded lines |
7 | 1842 i = 1; |
1843 else | |
1844 #endif | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
1845 i = PLINES_NOFILL(top); |
7 | 1846 used += i; |
1847 if (extra + i <= off && bot < curbuf->b_ml.ml_line_count) | |
1848 { | |
1849 #ifdef FEAT_FOLDING | |
1850 if (hasFolding(bot, NULL, &bot)) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1851 // count one logical line for a sequence of folded lines |
7 | 1852 ++used; |
1853 else | |
1854 #endif | |
1855 used += plines(bot); | |
1856 } | |
1857 if (used > curwin->w_height) | |
1858 break; | |
1859 if (top < curwin->w_topline) | |
1860 scrolled += i; | |
1861 | |
1862 /* | |
1863 * If scrolling is needed, scroll at least 'sj' lines. | |
1864 */ | |
1865 if ((new_topline >= curwin->w_topline || scrolled > min_scroll) | |
1866 && extra >= off) | |
1867 break; | |
1868 | |
1869 extra += i; | |
1870 new_topline = top; | |
1871 --top; | |
1872 ++bot; | |
1873 } | |
1874 | |
1875 /* | |
1876 * If we don't have enough space, put cursor in the middle. | |
1877 * This makes sure we get the same position when using "k" and "j" | |
1878 * in a small window. | |
1879 */ | |
1880 if (used > curwin->w_height) | |
1881 scroll_cursor_halfway(FALSE); | |
1882 else | |
1883 { | |
1884 /* | |
1885 * If "always" is FALSE, only adjust topline to a lower value, higher | |
1886 * value may happen with wrapping lines | |
1887 */ | |
1888 if (new_topline < curwin->w_topline || always) | |
1889 curwin->w_topline = new_topline; | |
1890 if (curwin->w_topline > curwin->w_cursor.lnum) | |
1891 curwin->w_topline = curwin->w_cursor.lnum; | |
1892 #ifdef FEAT_DIFF | |
1893 curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline); | |
1894 if (curwin->w_topfill > 0 && extra > off) | |
1895 { | |
1896 curwin->w_topfill -= extra - off; | |
1897 if (curwin->w_topfill < 0) | |
1898 curwin->w_topfill = 0; | |
1899 } | |
1900 check_topfill(curwin, FALSE); | |
1901 #endif | |
1902 if (curwin->w_topline != old_topline | |
1903 #ifdef FEAT_DIFF | |
1904 || curwin->w_topfill != old_topfill | |
1905 #endif | |
1906 ) | |
1907 curwin->w_valid &= | |
1908 ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); | |
1909 curwin->w_valid |= VALID_TOPLINE; | |
1910 } | |
1911 } | |
1912 | |
1913 /* | |
1914 * Set w_empty_rows and w_filler_rows for window "wp", having used up "used" | |
1915 * screen lines for text lines. | |
1916 */ | |
1917 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1918 set_empty_rows(win_T *wp, int used) |
7 | 1919 { |
1920 #ifdef FEAT_DIFF | |
1921 wp->w_filler_rows = 0; | |
1922 #endif | |
1923 if (used == 0) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1924 wp->w_empty_rows = 0; // single line that doesn't fit |
7 | 1925 else |
1926 { | |
1927 wp->w_empty_rows = wp->w_height - used; | |
1928 #ifdef FEAT_DIFF | |
1929 if (wp->w_botline <= wp->w_buffer->b_ml.ml_line_count) | |
1930 { | |
1931 wp->w_filler_rows = diff_check_fill(wp, wp->w_botline); | |
1932 if (wp->w_empty_rows > wp->w_filler_rows) | |
1933 wp->w_empty_rows -= wp->w_filler_rows; | |
1934 else | |
1935 { | |
1936 wp->w_filler_rows = wp->w_empty_rows; | |
1937 wp->w_empty_rows = 0; | |
1938 } | |
1939 } | |
1940 #endif | |
1941 } | |
1942 } | |
1943 | |
1944 /* | |
1945 * Recompute topline to put the cursor at the bottom of the window. | |
1946 * Scroll at least "min_scroll" lines. | |
1947 * If "set_topbot" is TRUE, set topline and botline first (for "zb"). | |
1948 * This is messy stuff!!! | |
1949 */ | |
1950 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1951 scroll_cursor_bot(int min_scroll, int set_topbot) |
7 | 1952 { |
1953 int used; | |
1954 int scrolled = 0; | |
1955 int extra = 0; | |
1956 int i; | |
1957 linenr_T line_count; | |
1958 linenr_T old_topline = curwin->w_topline; | |
1959 lineoff_T loff; | |
1960 lineoff_T boff; | |
1961 #ifdef FEAT_DIFF | |
1962 int old_topfill = curwin->w_topfill; | |
1963 int fill_below_window; | |
1964 #endif | |
1965 linenr_T old_botline = curwin->w_botline; | |
1966 linenr_T old_valid = curwin->w_valid; | |
1967 int old_empty_rows = curwin->w_empty_rows; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1968 linenr_T cln; // Cursor Line Number |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
1969 long so = get_scrolloff_value(); |
7 | 1970 |
1971 cln = curwin->w_cursor.lnum; | |
1972 if (set_topbot) | |
1973 { | |
1974 used = 0; | |
1975 curwin->w_botline = cln + 1; | |
1976 #ifdef FEAT_DIFF | |
1977 loff.fill = 0; | |
1978 #endif | |
1979 for (curwin->w_topline = curwin->w_botline; | |
1980 curwin->w_topline > 1; | |
1981 curwin->w_topline = loff.lnum) | |
1982 { | |
1983 loff.lnum = curwin->w_topline; | |
1984 topline_back(&loff); | |
2082
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
1985 if (loff.height == MAXCOL || used + loff.height > curwin->w_height) |
7 | 1986 break; |
1987 used += loff.height; | |
1988 #ifdef FEAT_DIFF | |
1989 curwin->w_topfill = loff.fill; | |
1990 #endif | |
1991 } | |
1992 set_empty_rows(curwin, used); | |
1993 curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP; | |
1994 if (curwin->w_topline != old_topline | |
1995 #ifdef FEAT_DIFF | |
1996 || curwin->w_topfill != old_topfill | |
1997 #endif | |
1998 ) | |
1999 curwin->w_valid &= ~(VALID_WROW|VALID_CROW); | |
2000 } | |
2001 else | |
2002 validate_botline(); | |
2003 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2004 // The lines of the cursor line itself are always used. |
7 | 2005 #ifdef FEAT_DIFF |
2006 used = plines_nofill(cln); | |
2007 #else | |
2008 validate_cheight(); | |
2009 used = curwin->w_cline_height; | |
2010 #endif | |
2011 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2012 // If the cursor is below botline, we will at least scroll by the height |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2013 // of the cursor line. Correct for empty lines, which are really part of |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2014 // botline. |
7 | 2015 if (cln >= curwin->w_botline) |
2016 { | |
2017 scrolled = used; | |
2018 if (cln == curwin->w_botline) | |
2019 scrolled -= curwin->w_empty_rows; | |
2020 } | |
2021 | |
2022 /* | |
2023 * Stop counting lines to scroll when | |
2024 * - hitting start of the file | |
2025 * - scrolled nothing or at least 'sj' lines | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
2026 * - at least 'scrolloff' lines below the cursor |
7 | 2027 * - lines between botline and cursor have been counted |
2028 */ | |
2029 #ifdef FEAT_FOLDING | |
2030 if (!hasFolding(curwin->w_cursor.lnum, &loff.lnum, &boff.lnum)) | |
2031 #endif | |
2032 { | |
2033 loff.lnum = cln; | |
2034 boff.lnum = cln; | |
2035 } | |
2036 #ifdef FEAT_DIFF | |
2037 loff.fill = 0; | |
2038 boff.fill = 0; | |
2039 fill_below_window = diff_check_fill(curwin, curwin->w_botline) | |
2040 - curwin->w_filler_rows; | |
2041 #endif | |
2042 | |
2043 while (loff.lnum > 1) | |
2044 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2045 // Stop when scrolled nothing or at least "min_scroll", found "extra" |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2046 // context for 'scrolloff' and counted all lines below the window. |
7 | 2047 if ((((scrolled <= 0 || scrolled >= min_scroll) |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
17863
diff
changeset
|
2048 && extra >= (mouse_dragging > 0 ? mouse_dragging - 1 : so)) |
7 | 2049 || boff.lnum + 1 > curbuf->b_ml.ml_line_count) |
2050 && loff.lnum <= curwin->w_botline | |
2051 #ifdef FEAT_DIFF | |
2052 && (loff.lnum < curwin->w_botline | |
2053 || loff.fill >= fill_below_window) | |
2054 #endif | |
2055 ) | |
2056 break; | |
2057 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2058 // Add one line above |
7 | 2059 topline_back(&loff); |
2082
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2060 if (loff.height == MAXCOL) |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2061 used = MAXCOL; |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2062 else |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2063 used += loff.height; |
7 | 2064 if (used > curwin->w_height) |
2065 break; | |
2066 if (loff.lnum >= curwin->w_botline | |
2067 #ifdef FEAT_DIFF | |
2068 && (loff.lnum > curwin->w_botline | |
2069 || loff.fill <= fill_below_window) | |
2070 #endif | |
2071 ) | |
2072 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2073 // Count screen lines that are below the window. |
7 | 2074 scrolled += loff.height; |
2075 if (loff.lnum == curwin->w_botline | |
2076 #ifdef FEAT_DIFF | |
15064
7b2dcca9e0c1
patch 8.1.0543: Coverity warns for leaking memory and using wrong struct
Bram Moolenaar <Bram@vim.org>
parents:
14873
diff
changeset
|
2077 && loff.fill == 0 |
7 | 2078 #endif |
2079 ) | |
2080 scrolled -= curwin->w_empty_rows; | |
2081 } | |
2082 | |
2083 if (boff.lnum < curbuf->b_ml.ml_line_count) | |
2084 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2085 // Add one line below |
7 | 2086 botline_forw(&boff); |
2087 used += boff.height; | |
2088 if (used > curwin->w_height) | |
2089 break; | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
17863
diff
changeset
|
2090 if (extra < ( mouse_dragging > 0 ? mouse_dragging - 1 : so) |
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
17863
diff
changeset
|
2091 || scrolled < min_scroll) |
7 | 2092 { |
2093 extra += boff.height; | |
2094 if (boff.lnum >= curwin->w_botline | |
2095 #ifdef FEAT_DIFF | |
2096 || (boff.lnum + 1 == curwin->w_botline | |
2097 && boff.fill > curwin->w_filler_rows) | |
2098 #endif | |
2099 ) | |
2100 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2101 // Count screen lines that are below the window. |
7 | 2102 scrolled += boff.height; |
2103 if (boff.lnum == curwin->w_botline | |
2104 #ifdef FEAT_DIFF | |
2105 && boff.fill == 0 | |
2106 #endif | |
2107 ) | |
2108 scrolled -= curwin->w_empty_rows; | |
2109 } | |
2110 } | |
2111 } | |
2112 } | |
2113 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2114 // curwin->w_empty_rows is larger, no need to scroll |
7 | 2115 if (scrolled <= 0) |
2116 line_count = 0; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2117 // more than a screenfull, don't scroll but redraw |
7 | 2118 else if (used > curwin->w_height) |
2119 line_count = used; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2120 // scroll minimal number of lines |
7 | 2121 else |
2122 { | |
2123 line_count = 0; | |
2124 #ifdef FEAT_DIFF | |
2125 boff.fill = curwin->w_topfill; | |
2126 #endif | |
2127 boff.lnum = curwin->w_topline - 1; | |
2128 for (i = 0; i < scrolled && boff.lnum < curwin->w_botline; ) | |
2129 { | |
2130 botline_forw(&boff); | |
2131 i += boff.height; | |
2132 ++line_count; | |
2133 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2134 if (i < scrolled) // below curwin->w_botline, don't scroll |
7 | 2135 line_count = 9999; |
2136 } | |
2137 | |
2138 /* | |
2139 * Scroll up if the cursor is off the bottom of the screen a bit. | |
2140 * Otherwise put it at 1/2 of the screen. | |
2141 */ | |
2142 if (line_count >= curwin->w_height && line_count > min_scroll) | |
2143 scroll_cursor_halfway(FALSE); | |
2144 else | |
2145 scrollup(line_count, TRUE); | |
2146 | |
2147 /* | |
2148 * If topline didn't change we need to restore w_botline and w_empty_rows | |
2149 * (we changed them). | |
2150 * If topline did change, update_screen() will set botline. | |
2151 */ | |
2152 if (curwin->w_topline == old_topline && set_topbot) | |
2153 { | |
2154 curwin->w_botline = old_botline; | |
2155 curwin->w_empty_rows = old_empty_rows; | |
2156 curwin->w_valid = old_valid; | |
2157 } | |
2158 curwin->w_valid |= VALID_TOPLINE; | |
2159 } | |
2160 | |
2161 /* | |
2162 * Recompute topline to put the cursor halfway the window | |
2163 * If "atend" is TRUE, also put it halfway at the end of the file. | |
2164 */ | |
2165 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2166 scroll_cursor_halfway(int atend) |
7 | 2167 { |
2168 int above = 0; | |
2169 linenr_T topline; | |
2170 #ifdef FEAT_DIFF | |
2171 int topfill = 0; | |
2172 #endif | |
2173 int below = 0; | |
2174 int used; | |
2175 lineoff_T loff; | |
2176 lineoff_T boff; | |
5661 | 2177 #ifdef FEAT_DIFF |
5653 | 2178 linenr_T old_topline = curwin->w_topline; |
5661 | 2179 #endif |
7 | 2180 |
22403
3351d2cd3f1f
patch 8.2.1750: popup_setoptions() setting firstline fails if cursorline set
Bram Moolenaar <Bram@vim.org>
parents:
21321
diff
changeset
|
2181 #ifdef FEAT_PROP_POPUP |
3351d2cd3f1f
patch 8.2.1750: popup_setoptions() setting firstline fails if cursorline set
Bram Moolenaar <Bram@vim.org>
parents:
21321
diff
changeset
|
2182 // if the width changed this needs to be updated first |
3351d2cd3f1f
patch 8.2.1750: popup_setoptions() setting firstline fails if cursorline set
Bram Moolenaar <Bram@vim.org>
parents:
21321
diff
changeset
|
2183 may_update_popup_position(); |
3351d2cd3f1f
patch 8.2.1750: popup_setoptions() setting firstline fails if cursorline set
Bram Moolenaar <Bram@vim.org>
parents:
21321
diff
changeset
|
2184 #endif |
7 | 2185 loff.lnum = boff.lnum = curwin->w_cursor.lnum; |
2186 #ifdef FEAT_FOLDING | |
2187 (void)hasFolding(loff.lnum, &loff.lnum, &boff.lnum); | |
2188 #endif | |
2189 #ifdef FEAT_DIFF | |
2190 used = plines_nofill(loff.lnum); | |
2191 loff.fill = 0; | |
2192 boff.fill = 0; | |
2193 #else | |
2194 used = plines(loff.lnum); | |
2195 #endif | |
2196 topline = loff.lnum; | |
2197 while (topline > 1) | |
2198 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2199 if (below <= above) // add a line below the cursor first |
7 | 2200 { |
2201 if (boff.lnum < curbuf->b_ml.ml_line_count) | |
2202 { | |
2203 botline_forw(&boff); | |
2204 used += boff.height; | |
2205 if (used > curwin->w_height) | |
2206 break; | |
2207 below += boff.height; | |
2208 } | |
2209 else | |
2210 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2211 ++below; // count a "~" line |
7 | 2212 if (atend) |
2213 ++used; | |
2214 } | |
2215 } | |
2216 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2217 if (below > above) // add a line above the cursor |
7 | 2218 { |
2219 topline_back(&loff); | |
2082
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2220 if (loff.height == MAXCOL) |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2221 used = MAXCOL; |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2222 else |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2223 used += loff.height; |
7 | 2224 if (used > curwin->w_height) |
2225 break; | |
2226 above += loff.height; | |
2227 topline = loff.lnum; | |
2228 #ifdef FEAT_DIFF | |
2229 topfill = loff.fill; | |
2230 #endif | |
2231 } | |
2232 } | |
2233 #ifdef FEAT_FOLDING | |
2234 if (!hasFolding(topline, &curwin->w_topline, NULL)) | |
2235 #endif | |
2236 curwin->w_topline = topline; | |
2237 #ifdef FEAT_DIFF | |
2238 curwin->w_topfill = topfill; | |
5653 | 2239 if (old_topline > curwin->w_topline + curwin->w_height) |
2240 curwin->w_botfill = FALSE; | |
7 | 2241 check_topfill(curwin, FALSE); |
2242 #endif | |
2243 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); | |
2244 curwin->w_valid |= VALID_TOPLINE; | |
2245 } | |
2246 | |
2247 /* | |
2248 * Correct the cursor position so that it is in a part of the screen at least | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
2249 * 'scrolloff' lines from the top and bottom, if possible. |
7 | 2250 * If not possible, put it at the same position as scroll_cursor_halfway(). |
2251 * When called topline must be valid! | |
2252 */ | |
2253 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2254 cursor_correct(void) |
7 | 2255 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2256 int above = 0; // screen lines above topline |
7 | 2257 linenr_T topline; |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2258 int below = 0; // screen lines below botline |
7 | 2259 linenr_T botline; |
2260 int above_wanted, below_wanted; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2261 linenr_T cln; // Cursor Line Number |
7 | 2262 int max_off; |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
2263 long so = get_scrolloff_value(); |
7 | 2264 |
2265 /* | |
2266 * How many lines we would like to have above/below the cursor depends on | |
2267 * whether the first/last line of the file is on screen. | |
2268 */ | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
2269 above_wanted = so; |
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
2270 below_wanted = so; |
1121 | 2271 if (mouse_dragging > 0) |
7 | 2272 { |
2273 above_wanted = mouse_dragging - 1; | |
2274 below_wanted = mouse_dragging - 1; | |
2275 } | |
2276 if (curwin->w_topline == 1) | |
2277 { | |
2278 above_wanted = 0; | |
2279 max_off = curwin->w_height / 2; | |
2280 if (below_wanted > max_off) | |
2281 below_wanted = max_off; | |
2282 } | |
2283 validate_botline(); | |
2284 if (curwin->w_botline == curbuf->b_ml.ml_line_count + 1 | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
17863
diff
changeset
|
2285 && mouse_dragging == 0) |
7 | 2286 { |
2287 below_wanted = 0; | |
2288 max_off = (curwin->w_height - 1) / 2; | |
2289 if (above_wanted > max_off) | |
2290 above_wanted = max_off; | |
2291 } | |
2292 | |
2293 /* | |
2294 * If there are sufficient file-lines above and below the cursor, we can | |
2295 * return now. | |
2296 */ | |
2297 cln = curwin->w_cursor.lnum; | |
2298 if (cln >= curwin->w_topline + above_wanted | |
2299 && cln < curwin->w_botline - below_wanted | |
2300 #ifdef FEAT_FOLDING | |
2301 && !hasAnyFolding(curwin) | |
2302 #endif | |
2303 ) | |
2304 return; | |
2305 | |
2306 /* | |
2307 * Narrow down the area where the cursor can be put by taking lines from | |
2308 * the top and the bottom until: | |
2309 * - the desired context lines are found | |
2310 * - the lines from the top is past the lines from the bottom | |
2311 */ | |
2312 topline = curwin->w_topline; | |
2313 botline = curwin->w_botline - 1; | |
2314 #ifdef FEAT_DIFF | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2315 // count filler lines as context |
7 | 2316 above = curwin->w_topfill; |
2317 below = curwin->w_filler_rows; | |
2318 #endif | |
2319 while ((above < above_wanted || below < below_wanted) && topline < botline) | |
2320 { | |
2321 if (below < below_wanted && (below <= above || above >= above_wanted)) | |
2322 { | |
2323 #ifdef FEAT_FOLDING | |
2324 if (hasFolding(botline, &botline, NULL)) | |
2325 ++below; | |
2326 else | |
2327 #endif | |
2328 below += plines(botline); | |
2329 --botline; | |
2330 } | |
2331 if (above < above_wanted && (above < below || below >= below_wanted)) | |
2332 { | |
2333 #ifdef FEAT_FOLDING | |
2334 if (hasFolding(topline, NULL, &topline)) | |
2335 ++above; | |
2336 else | |
2337 #endif | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
2338 above += PLINES_NOFILL(topline); |
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
2339 #ifdef FEAT_DIFF |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2340 // Count filler lines below this line as context. |
7 | 2341 if (topline < botline) |
2342 above += diff_check_fill(curwin, topline + 1); | |
2343 #endif | |
2344 ++topline; | |
2345 } | |
2346 } | |
2347 if (topline == botline || botline == 0) | |
2348 curwin->w_cursor.lnum = topline; | |
2349 else if (topline > botline) | |
2350 curwin->w_cursor.lnum = botline; | |
2351 else | |
2352 { | |
2353 if (cln < topline && curwin->w_topline > 1) | |
2354 { | |
2355 curwin->w_cursor.lnum = topline; | |
2356 curwin->w_valid &= | |
2357 ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW); | |
2358 } | |
2359 if (cln > botline && curwin->w_botline <= curbuf->b_ml.ml_line_count) | |
2360 { | |
2361 curwin->w_cursor.lnum = botline; | |
2362 curwin->w_valid &= | |
2363 ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW); | |
2364 } | |
2365 } | |
2366 curwin->w_valid |= VALID_TOPLINE; | |
2367 } | |
2368 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7103
diff
changeset
|
2369 static void get_scroll_overlap(lineoff_T *lp, int dir); |
7 | 2370 |
2371 /* | |
2372 * move screen 'count' pages up or down and update screen | |
2373 * | |
2374 * return FAIL for failure, OK otherwise | |
2375 */ | |
2376 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2377 onepage(int dir, long count) |
7 | 2378 { |
2379 long n; | |
2380 int retval = OK; | |
2381 lineoff_T loff; | |
2382 linenr_T old_topline = curwin->w_topline; | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
2383 long so = get_scrolloff_value(); |
7 | 2384 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2385 if (curbuf->b_ml.ml_line_count == 1) // nothing to do |
7 | 2386 { |
2387 beep_flush(); | |
2388 return FAIL; | |
2389 } | |
2390 | |
2391 for ( ; count > 0; --count) | |
2392 { | |
2393 validate_botline(); | |
2394 /* | |
2395 * It's an error to move a page up when the first line is already on | |
2396 * the screen. It's an error to move a page down when the last line | |
2397 * is on the screen and the topline is 'scrolloff' lines from the | |
2398 * last line. | |
2399 */ | |
2400 if (dir == FORWARD | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
2401 ? ((curwin->w_topline >= curbuf->b_ml.ml_line_count - so) |
7 | 2402 && curwin->w_botline > curbuf->b_ml.ml_line_count) |
2403 : (curwin->w_topline == 1 | |
2404 #ifdef FEAT_DIFF | |
2405 && curwin->w_topfill == | |
2406 diff_check_fill(curwin, curwin->w_topline) | |
2407 #endif | |
2408 )) | |
2409 { | |
2410 beep_flush(); | |
2411 retval = FAIL; | |
2412 break; | |
2413 } | |
2414 | |
2415 #ifdef FEAT_DIFF | |
2416 loff.fill = 0; | |
2417 #endif | |
2418 if (dir == FORWARD) | |
2419 { | |
10349
cf988222b150
commit https://github.com/vim/vim/commit/a1f4cb93ba50ea9e40cd4b1f5592b8a6d1398660
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
2420 if (ONE_WINDOW && p_window > 0 && p_window < Rows - 1) |
7 | 2421 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2422 // Vi compatible scrolling |
164 | 2423 if (p_window <= 2) |
2424 ++curwin->w_topline; | |
2425 else | |
2426 curwin->w_topline += p_window - 2; | |
2427 if (curwin->w_topline > curbuf->b_ml.ml_line_count) | |
2428 curwin->w_topline = curbuf->b_ml.ml_line_count; | |
2429 curwin->w_cursor.lnum = curwin->w_topline; | |
2430 } | |
2431 else if (curwin->w_botline > curbuf->b_ml.ml_line_count) | |
2432 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2433 // at end of file |
7 | 2434 curwin->w_topline = curbuf->b_ml.ml_line_count; |
2435 #ifdef FEAT_DIFF | |
2436 curwin->w_topfill = 0; | |
2437 #endif | |
2438 curwin->w_valid &= ~(VALID_WROW|VALID_CROW); | |
2439 } | |
2440 else | |
2441 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2442 // For the overlap, start with the line just below the window |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2443 // and go upwards. |
7 | 2444 loff.lnum = curwin->w_botline; |
2445 #ifdef FEAT_DIFF | |
2446 loff.fill = diff_check_fill(curwin, loff.lnum) | |
2447 - curwin->w_filler_rows; | |
2448 #endif | |
2449 get_scroll_overlap(&loff, -1); | |
2450 curwin->w_topline = loff.lnum; | |
2451 #ifdef FEAT_DIFF | |
2452 curwin->w_topfill = loff.fill; | |
2453 check_topfill(curwin, FALSE); | |
2454 #endif | |
2455 curwin->w_cursor.lnum = curwin->w_topline; | |
2456 curwin->w_valid &= ~(VALID_WCOL|VALID_CHEIGHT|VALID_WROW| | |
2457 VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); | |
2458 } | |
2459 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2460 else // dir == BACKWARDS |
7 | 2461 { |
2462 #ifdef FEAT_DIFF | |
2463 if (curwin->w_topline == 1) | |
2464 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2465 // Include max number of filler lines |
7 | 2466 max_topfill(); |
2467 continue; | |
2468 } | |
2469 #endif | |
10349
cf988222b150
commit https://github.com/vim/vim/commit/a1f4cb93ba50ea9e40cd4b1f5592b8a6d1398660
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
2470 if (ONE_WINDOW && p_window > 0 && p_window < Rows - 1) |
164 | 2471 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2472 // Vi compatible scrolling (sort of) |
164 | 2473 if (p_window <= 2) |
2474 --curwin->w_topline; | |
2475 else | |
2476 curwin->w_topline -= p_window - 2; | |
2477 if (curwin->w_topline < 1) | |
2478 curwin->w_topline = 1; | |
2479 curwin->w_cursor.lnum = curwin->w_topline + p_window - 1; | |
2480 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
2481 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
2482 continue; | |
2483 } | |
2484 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2485 // Find the line at the top of the window that is going to be the |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2486 // line at the bottom of the window. Make sure this results in |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2487 // the same line as before doing CTRL-F. |
7 | 2488 loff.lnum = curwin->w_topline - 1; |
2489 #ifdef FEAT_DIFF | |
2490 loff.fill = diff_check_fill(curwin, loff.lnum + 1) | |
2491 - curwin->w_topfill; | |
2492 #endif | |
2493 get_scroll_overlap(&loff, 1); | |
2494 | |
2495 if (loff.lnum >= curbuf->b_ml.ml_line_count) | |
2496 { | |
2497 loff.lnum = curbuf->b_ml.ml_line_count; | |
2498 #ifdef FEAT_DIFF | |
2499 loff.fill = 0; | |
2500 } | |
2501 else | |
2502 { | |
2503 botline_topline(&loff); | |
2504 #endif | |
2505 } | |
2506 curwin->w_cursor.lnum = loff.lnum; | |
2507 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2508 // Find the line just above the new topline to get the right line |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2509 // at the bottom of the window. |
7 | 2510 n = 0; |
2511 while (n <= curwin->w_height && loff.lnum >= 1) | |
2512 { | |
2513 topline_back(&loff); | |
2082
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2514 if (loff.height == MAXCOL) |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2515 n = MAXCOL; |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2516 else |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2517 n += loff.height; |
7 | 2518 } |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2519 if (loff.lnum < 1) // at begin of file |
7 | 2520 { |
2521 curwin->w_topline = 1; | |
2522 #ifdef FEAT_DIFF | |
2523 max_topfill(); | |
2524 #endif | |
2525 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); | |
2526 } | |
2527 else | |
2528 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2529 // Go two lines forward again. |
7 | 2530 #ifdef FEAT_DIFF |
2531 topline_botline(&loff); | |
2532 #endif | |
2533 botline_forw(&loff); | |
2534 botline_forw(&loff); | |
2535 #ifdef FEAT_DIFF | |
2536 botline_topline(&loff); | |
2537 #endif | |
2538 #ifdef FEAT_FOLDING | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2539 // We're at the wrong end of a fold now. |
7 | 2540 (void)hasFolding(loff.lnum, &loff.lnum, NULL); |
2541 #endif | |
2542 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2543 // Always scroll at least one line. Avoid getting stuck on |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2544 // very long lines. |
7 | 2545 if (loff.lnum >= curwin->w_topline |
2546 #ifdef FEAT_DIFF | |
2547 && (loff.lnum > curwin->w_topline | |
2548 || loff.fill >= curwin->w_topfill) | |
2549 #endif | |
2550 ) | |
2551 { | |
2552 #ifdef FEAT_DIFF | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2553 // First try using the maximum number of filler lines. If |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2554 // that's not enough, backup one line. |
7 | 2555 loff.fill = curwin->w_topfill; |
2556 if (curwin->w_topfill < diff_check_fill(curwin, | |
2557 curwin->w_topline)) | |
2558 max_topfill(); | |
2559 if (curwin->w_topfill == loff.fill) | |
2560 #endif | |
2561 { | |
2562 --curwin->w_topline; | |
2563 #ifdef FEAT_DIFF | |
2564 curwin->w_topfill = 0; | |
2565 #endif | |
2566 } | |
2567 comp_botline(curwin); | |
2568 curwin->w_cursor.lnum = curwin->w_botline - 1; | |
5764 | 2569 curwin->w_valid &= |
2570 ~(VALID_WCOL|VALID_CHEIGHT|VALID_WROW|VALID_CROW); | |
7 | 2571 } |
2572 else | |
2573 { | |
2574 curwin->w_topline = loff.lnum; | |
2575 #ifdef FEAT_DIFF | |
2576 curwin->w_topfill = loff.fill; | |
2577 check_topfill(curwin, FALSE); | |
2578 #endif | |
2579 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); | |
2580 } | |
2581 } | |
2582 } | |
2583 } | |
2584 #ifdef FEAT_FOLDING | |
2585 foldAdjustCursor(); | |
2586 #endif | |
2587 cursor_correct(); | |
10102
b80ad55d62d8
commit https://github.com/vim/vim/commit/bc54f3f3fed4dc3556df8c46cee6739d211b0eb2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2588 check_cursor_col(); |
161 | 2589 if (retval == OK) |
2590 beginline(BL_SOL | BL_FIX); | |
7 | 2591 curwin->w_valid &= ~(VALID_WCOL|VALID_WROW|VALID_VIRTCOL); |
2592 | |
14317
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2593 if (retval == OK && dir == FORWARD) |
7 | 2594 { |
14317
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2595 // Avoid the screen jumping up and down when 'scrolloff' is non-zero. |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2596 // But make sure we scroll at least one line (happens with mix of long |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2597 // wrapping lines and non-wrapping line). |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2598 if (check_top_offset()) |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2599 { |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2600 scroll_cursor_top(1, FALSE); |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2601 if (curwin->w_topline <= old_topline |
7 | 2602 && old_topline < curbuf->b_ml.ml_line_count) |
14317
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2603 { |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2604 curwin->w_topline = old_topline + 1; |
7 | 2605 #ifdef FEAT_FOLDING |
14317
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2606 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2607 #endif |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2608 } |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2609 } |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2610 #ifdef FEAT_FOLDING |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2611 else if (curwin->w_botline > curbuf->b_ml.ml_line_count) |
7 | 2612 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
2613 #endif | |
2614 } | |
2615 | |
2616 redraw_later(VALID); | |
2617 return retval; | |
2618 } | |
2619 | |
2620 /* | |
2621 * Decide how much overlap to use for page-up or page-down scrolling. | |
2622 * This is symmetric, so that doing both keeps the same lines displayed. | |
2623 * Three lines are examined: | |
2624 * | |
2625 * before CTRL-F after CTRL-F / before CTRL-B | |
2626 * etc. l1 | |
2627 * l1 last but one line ------------ | |
2628 * l2 last text line l2 top text line | |
2629 * ------------- l3 second text line | |
2630 * l3 etc. | |
2631 */ | |
2632 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2633 get_scroll_overlap(lineoff_T *lp, int dir) |
7 | 2634 { |
2635 int h1, h2, h3, h4; | |
2636 int min_height = curwin->w_height - 2; | |
2637 lineoff_T loff0, loff1, loff2; | |
2638 | |
2639 #ifdef FEAT_DIFF | |
2640 if (lp->fill > 0) | |
2641 lp->height = 1; | |
2642 else | |
2643 lp->height = plines_nofill(lp->lnum); | |
2644 #else | |
2645 lp->height = plines(lp->lnum); | |
2646 #endif | |
2647 h1 = lp->height; | |
2648 if (h1 > min_height) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2649 return; // no overlap |
7 | 2650 |
2651 loff0 = *lp; | |
2652 if (dir > 0) | |
2653 botline_forw(lp); | |
2654 else | |
2655 topline_back(lp); | |
2656 h2 = lp->height; | |
3968 | 2657 if (h2 == MAXCOL || h2 + h1 > min_height) |
7 | 2658 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2659 *lp = loff0; // no overlap |
7 | 2660 return; |
2661 } | |
2662 | |
2663 loff1 = *lp; | |
2664 if (dir > 0) | |
2665 botline_forw(lp); | |
2666 else | |
2667 topline_back(lp); | |
2668 h3 = lp->height; | |
3968 | 2669 if (h3 == MAXCOL || h3 + h2 > min_height) |
7 | 2670 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2671 *lp = loff0; // no overlap |
7 | 2672 return; |
2673 } | |
2674 | |
2675 loff2 = *lp; | |
2676 if (dir > 0) | |
2677 botline_forw(lp); | |
2678 else | |
2679 topline_back(lp); | |
2680 h4 = lp->height; | |
3968 | 2681 if (h4 == MAXCOL || h4 + h3 + h2 > min_height || h3 + h2 + h1 > min_height) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2682 *lp = loff1; // 1 line overlap |
7 | 2683 else |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2684 *lp = loff2; // 2 lines overlap |
7 | 2685 return; |
2686 } | |
2687 | |
2688 /* | |
2689 * Scroll 'scroll' lines up or down. | |
2690 */ | |
2691 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2692 halfpage(int flag, linenr_T Prenum) |
7 | 2693 { |
2694 long scrolled = 0; | |
2695 int i; | |
2696 int n; | |
2697 int room; | |
2698 | |
2699 if (Prenum) | |
2700 curwin->w_p_scr = (Prenum > curwin->w_height) ? | |
2701 curwin->w_height : Prenum; | |
2702 n = (curwin->w_p_scr <= curwin->w_height) ? | |
2703 curwin->w_p_scr : curwin->w_height; | |
2704 | |
11258
84f71a8a5f2c
patch 8.0.0515: ml_get errors in silent Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2705 update_topline(); |
7 | 2706 validate_botline(); |
2707 room = curwin->w_empty_rows; | |
2708 #ifdef FEAT_DIFF | |
2709 room += curwin->w_filler_rows; | |
2710 #endif | |
2711 if (flag) | |
2712 { | |
2713 /* | |
2714 * scroll the text up | |
2715 */ | |
2716 while (n > 0 && curwin->w_botline <= curbuf->b_ml.ml_line_count) | |
2717 { | |
2718 #ifdef FEAT_DIFF | |
2719 if (curwin->w_topfill > 0) | |
2720 { | |
2721 i = 1; | |
21321
1421eca61db9
patch 8.2.1211: removed more than dead code
Bram Moolenaar <Bram@vim.org>
parents:
21134
diff
changeset
|
2722 --n; |
7 | 2723 --curwin->w_topfill; |
2724 } | |
2725 else | |
2726 #endif | |
2727 { | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
2728 i = PLINES_NOFILL(curwin->w_topline); |
7 | 2729 n -= i; |
2730 if (n < 0 && scrolled > 0) | |
2731 break; | |
2732 #ifdef FEAT_FOLDING | |
2733 (void)hasFolding(curwin->w_topline, NULL, &curwin->w_topline); | |
2734 #endif | |
2735 ++curwin->w_topline; | |
2736 #ifdef FEAT_DIFF | |
2737 curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline); | |
2738 #endif | |
2739 | |
2740 if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
2741 { | |
2742 ++curwin->w_cursor.lnum; | |
2743 curwin->w_valid &= | |
2744 ~(VALID_VIRTCOL|VALID_CHEIGHT|VALID_WCOL); | |
2745 } | |
2746 } | |
2747 curwin->w_valid &= ~(VALID_CROW|VALID_WROW); | |
2748 scrolled += i; | |
2749 | |
2750 /* | |
2751 * Correct w_botline for changed w_topline. | |
2752 * Won't work when there are filler lines. | |
2753 */ | |
2754 #ifdef FEAT_DIFF | |
2755 if (curwin->w_p_diff) | |
2756 curwin->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP); | |
2757 else | |
2758 #endif | |
2759 { | |
2760 room += i; | |
2761 do | |
2762 { | |
2763 i = plines(curwin->w_botline); | |
2764 if (i > room) | |
2765 break; | |
2766 #ifdef FEAT_FOLDING | |
2767 (void)hasFolding(curwin->w_botline, NULL, | |
2768 &curwin->w_botline); | |
2769 #endif | |
2770 ++curwin->w_botline; | |
2771 room -= i; | |
2772 } while (curwin->w_botline <= curbuf->b_ml.ml_line_count); | |
2773 } | |
2774 } | |
2775 | |
2776 /* | |
2777 * When hit bottom of the file: move cursor down. | |
2778 */ | |
2779 if (n > 0) | |
2780 { | |
2781 # ifdef FEAT_FOLDING | |
2782 if (hasAnyFolding(curwin)) | |
2783 { | |
2784 while (--n >= 0 | |
2785 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
2786 { | |
2787 (void)hasFolding(curwin->w_cursor.lnum, NULL, | |
2788 &curwin->w_cursor.lnum); | |
2789 ++curwin->w_cursor.lnum; | |
2790 } | |
2791 } | |
2792 else | |
2793 # endif | |
2794 curwin->w_cursor.lnum += n; | |
2795 check_cursor_lnum(); | |
2796 } | |
2797 } | |
2798 else | |
2799 { | |
2800 /* | |
2801 * scroll the text down | |
2802 */ | |
2803 while (n > 0 && curwin->w_topline > 1) | |
2804 { | |
2805 #ifdef FEAT_DIFF | |
2806 if (curwin->w_topfill < diff_check_fill(curwin, curwin->w_topline)) | |
2807 { | |
2808 i = 1; | |
16042
7952be788a49
patch 8.1.1026: unused condition
Bram Moolenaar <Bram@vim.org>
parents:
15713
diff
changeset
|
2809 --n; |
7 | 2810 ++curwin->w_topfill; |
2811 } | |
2812 else | |
2813 #endif | |
2814 { | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
2815 i = PLINES_NOFILL(curwin->w_topline - 1); |
7 | 2816 n -= i; |
2817 if (n < 0 && scrolled > 0) | |
2818 break; | |
2819 --curwin->w_topline; | |
2820 #ifdef FEAT_FOLDING | |
2821 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); | |
2822 #endif | |
2823 #ifdef FEAT_DIFF | |
2824 curwin->w_topfill = 0; | |
2825 #endif | |
2826 } | |
2827 curwin->w_valid &= ~(VALID_CROW|VALID_WROW| | |
2828 VALID_BOTLINE|VALID_BOTLINE_AP); | |
2829 scrolled += i; | |
2830 if (curwin->w_cursor.lnum > 1) | |
2831 { | |
2832 --curwin->w_cursor.lnum; | |
2833 curwin->w_valid &= ~(VALID_VIRTCOL|VALID_CHEIGHT|VALID_WCOL); | |
2834 } | |
2835 } | |
16042
7952be788a49
patch 8.1.1026: unused condition
Bram Moolenaar <Bram@vim.org>
parents:
15713
diff
changeset
|
2836 |
7 | 2837 /* |
2838 * When hit top of the file: move cursor up. | |
2839 */ | |
2840 if (n > 0) | |
2841 { | |
2842 if (curwin->w_cursor.lnum <= (linenr_T)n) | |
2843 curwin->w_cursor.lnum = 1; | |
2844 else | |
2845 # ifdef FEAT_FOLDING | |
2846 if (hasAnyFolding(curwin)) | |
2847 { | |
2848 while (--n >= 0 && curwin->w_cursor.lnum > 1) | |
2849 { | |
2850 --curwin->w_cursor.lnum; | |
2851 (void)hasFolding(curwin->w_cursor.lnum, | |
2852 &curwin->w_cursor.lnum, NULL); | |
2853 } | |
2854 } | |
2855 else | |
2856 # endif | |
2857 curwin->w_cursor.lnum -= n; | |
2858 } | |
2859 } | |
2860 # ifdef FEAT_FOLDING | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2861 // Move cursor to first line of closed fold. |
7 | 2862 foldAdjustCursor(); |
2863 # endif | |
2864 #ifdef FEAT_DIFF | |
2865 check_topfill(curwin, !flag); | |
2866 #endif | |
2867 cursor_correct(); | |
2868 beginline(BL_SOL | BL_FIX); | |
2869 redraw_later(VALID); | |
2870 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2871 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2872 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2873 do_check_cursorbind(void) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2874 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2875 linenr_T line = curwin->w_cursor.lnum; |
3415 | 2876 colnr_T col = curwin->w_cursor.col; |
2877 colnr_T coladd = curwin->w_cursor.coladd; | |
3433 | 2878 colnr_T curswant = curwin->w_curswant; |
2879 int set_curswant = curwin->w_set_curswant; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2880 win_T *old_curwin = curwin; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2881 buf_T *old_curbuf = curbuf; |
2693 | 2882 int restart_edit_save; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2883 int old_VIsual_select = VIsual_select; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2884 int old_VIsual_active = VIsual_active; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2885 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2886 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2887 * loop through the cursorbound windows |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2888 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2889 VIsual_select = VIsual_active = 0; |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2890 FOR_ALL_WINDOWS(curwin) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2891 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2892 curbuf = curwin->w_buffer; |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2893 // skip original window and windows with 'noscrollbind' |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2894 if (curwin != old_curwin && curwin->w_p_crb) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2895 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2896 # ifdef FEAT_DIFF |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2897 if (curwin->w_p_diff) |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10102
diff
changeset
|
2898 curwin->w_cursor.lnum = |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10102
diff
changeset
|
2899 diff_get_corresponding_line(old_curbuf, line); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2900 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2901 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2902 curwin->w_cursor.lnum = line; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2903 curwin->w_cursor.col = col; |
3415 | 2904 curwin->w_cursor.coladd = coladd; |
3433 | 2905 curwin->w_curswant = curswant; |
2906 curwin->w_set_curswant = set_curswant; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2907 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2908 // Make sure the cursor is in a valid position. Temporarily set |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2909 // "restart_edit" to allow the cursor to be beyond the EOL. |
2693 | 2910 restart_edit_save = restart_edit; |
2911 restart_edit = TRUE; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2912 check_cursor(); |
10607
e39300d3d2cf
patch 8.0.0193: accidentally removed #ifdef
Christian Brabandt <cb@256bit.org>
parents:
10597
diff
changeset
|
2913 # ifdef FEAT_SYN_HL |
10597
472bff31a20a
patch 8.0.0188: redrawing for 'cursorbind' is inefficient
Christian Brabandt <cb@256bit.org>
parents:
10585
diff
changeset
|
2914 if (curwin->w_p_cul || curwin->w_p_cuc) |
10583
f91c0376f2c6
patch 8.0.0181: with cursorbind set cursor column highlighting is off
Christian Brabandt <cb@256bit.org>
parents:
10349
diff
changeset
|
2915 validate_cursor(); |
10607
e39300d3d2cf
patch 8.0.0193: accidentally removed #ifdef
Christian Brabandt <cb@256bit.org>
parents:
10597
diff
changeset
|
2916 # endif |
2693 | 2917 restart_edit = restart_edit_save; |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2918 // Correct cursor for multi-byte character. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2919 if (has_mbyte) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2920 mb_adjust_cursor(); |
10597
472bff31a20a
patch 8.0.0188: redrawing for 'cursorbind' is inefficient
Christian Brabandt <cb@256bit.org>
parents:
10585
diff
changeset
|
2921 redraw_later(VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2922 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2923 // Only scroll when 'scrollbind' hasn't done this. |
2688 | 2924 if (!curwin->w_p_scb) |
2925 update_topline(); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2926 curwin->w_redr_status = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2927 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2928 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2929 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2930 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2931 * reset current-window |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2932 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2933 VIsual_select = old_VIsual_select; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2934 VIsual_active = old_VIsual_active; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2935 curwin = old_curwin; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2936 curbuf = old_curbuf; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2937 } |