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