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