Mercurial > vim
annotate src/move.c @ 18342:fedab77fee7b
Added tag v8.1.2165 for changeset a9d518b1271b9f9d104a50f21fdccca8b2fcdda0
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 16 Oct 2019 22:30:05 +0200 |
parents | 08f1dd29550e |
children | 9f51d0cef8da |
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 | |
17863
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1182 #if (defined(FEAT_EVAL) || defined(FEAT_TEXT_PROP)) || defined(PROTO) |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
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 */ |
17863
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1187 void |
17292
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 |
17863
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1216 // long line wrapping, adjust row |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
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 { |
17863
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1221 // use same formula as what is used in curs_columns() |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
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 } |
17863
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1239 #endif |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1240 |
17863
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1241 #if defined(FEAT_EVAL) || defined(PROTO) |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1242 /* |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1243 * "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
|
1244 */ |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1245 void |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1246 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
|
1247 { |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1248 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
|
1249 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
|
1250 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
|
1251 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
|
1252 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
|
1253 |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1254 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
|
1255 return; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1256 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
|
1257 |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1258 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
|
1259 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
|
1260 return; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1261 |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1262 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
|
1263 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
|
1264 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
|
1265 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
|
1266 |
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, "row", row); |
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, "col", scol); |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1269 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
|
1270 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
|
1271 } |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1272 #endif |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1273 |
7 | 1274 /* |
1275 * Scroll the current window down by "line_count" logical lines. "CTRL-Y" | |
1276 */ | |
1277 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1278 scrolldown( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1279 long line_count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1280 int byfold UNUSED) /* TRUE: count a closed fold as one line */ |
7 | 1281 { |
1282 long done = 0; /* total # of physical lines done */ | |
1283 int wrow; | |
1284 int moved = FALSE; | |
1285 | |
1286 #ifdef FEAT_FOLDING | |
1287 linenr_T first; | |
1288 | |
1289 /* Make sure w_topline is at the first of a sequence of folded lines. */ | |
1290 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); | |
1291 #endif | |
1292 validate_cursor(); /* w_wrow needs to be valid */ | |
1293 while (line_count-- > 0) | |
1294 { | |
1295 #ifdef FEAT_DIFF | |
1980 | 1296 if (curwin->w_topfill < diff_check(curwin, curwin->w_topline) |
1297 && curwin->w_topfill < curwin->w_height - 1) | |
7 | 1298 { |
1299 ++curwin->w_topfill; | |
1300 ++done; | |
1301 } | |
1302 else | |
1303 #endif | |
1304 { | |
1305 if (curwin->w_topline == 1) | |
1306 break; | |
1307 --curwin->w_topline; | |
1308 #ifdef FEAT_DIFF | |
1309 curwin->w_topfill = 0; | |
1310 #endif | |
1311 #ifdef FEAT_FOLDING | |
1312 /* A sequence of folded lines only counts for one logical line */ | |
1313 if (hasFolding(curwin->w_topline, &first, NULL)) | |
1314 { | |
1315 ++done; | |
1316 if (!byfold) | |
1317 line_count -= curwin->w_topline - first - 1; | |
1318 curwin->w_botline -= curwin->w_topline - first; | |
1319 curwin->w_topline = first; | |
1320 } | |
1321 else | |
1322 #endif | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
1323 done += PLINES_NOFILL(curwin->w_topline); |
7 | 1324 } |
1325 --curwin->w_botline; /* approximate w_botline */ | |
1326 invalidate_botline(); | |
1327 } | |
1328 curwin->w_wrow += done; /* keep w_wrow updated */ | |
1329 curwin->w_cline_row += done; /* keep w_cline_row updated */ | |
1330 | |
1331 #ifdef FEAT_DIFF | |
1332 if (curwin->w_cursor.lnum == curwin->w_topline) | |
1333 curwin->w_cline_row = 0; | |
1334 check_topfill(curwin, TRUE); | |
1335 #endif | |
1336 | |
1337 /* | |
1338 * Compute the row number of the last row of the cursor line | |
1339 * and move the cursor onto the displayed part of the window. | |
1340 */ | |
1341 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
|
1342 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 1343 { |
1344 validate_virtcol(); | |
1345 validate_cheight(); | |
1346 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
|
1347 curwin->w_virtcol / curwin->w_width; |
7 | 1348 } |
1349 while (wrow >= curwin->w_height && curwin->w_cursor.lnum > 1) | |
1350 { | |
1351 #ifdef FEAT_FOLDING | |
1352 if (hasFolding(curwin->w_cursor.lnum, &first, NULL)) | |
1353 { | |
1354 --wrow; | |
1355 if (first == 1) | |
1356 curwin->w_cursor.lnum = 1; | |
1357 else | |
1358 curwin->w_cursor.lnum = first - 1; | |
1359 } | |
1360 else | |
1361 #endif | |
1362 wrow -= plines(curwin->w_cursor.lnum--); | |
1363 curwin->w_valid &= | |
1364 ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL); | |
1365 moved = TRUE; | |
1366 } | |
1367 if (moved) | |
1368 { | |
1369 #ifdef FEAT_FOLDING | |
1370 /* Move cursor to first line of closed fold. */ | |
1371 foldAdjustCursor(); | |
1372 #endif | |
1373 coladvance(curwin->w_curswant); | |
1374 } | |
1375 } | |
1376 | |
1377 /* | |
1378 * Scroll the current window up by "line_count" logical lines. "CTRL-E" | |
1379 */ | |
1380 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1381 scrollup( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1382 long line_count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1383 int byfold UNUSED) /* TRUE: count a closed fold as one line */ |
7 | 1384 { |
1385 #if defined(FEAT_FOLDING) || defined(FEAT_DIFF) | |
1386 linenr_T lnum; | |
1387 | |
1388 if ( | |
1389 # ifdef FEAT_FOLDING | |
1390 (byfold && hasAnyFolding(curwin)) | |
1391 # ifdef FEAT_DIFF | |
1392 || | |
1393 # endif | |
1394 # endif | |
1395 # ifdef FEAT_DIFF | |
1396 curwin->w_p_diff | |
1397 # endif | |
1398 ) | |
1399 { | |
1400 /* count each sequence of folded lines as one logical line */ | |
1401 lnum = curwin->w_topline; | |
1402 while (line_count--) | |
1403 { | |
1404 # ifdef FEAT_DIFF | |
1405 if (curwin->w_topfill > 0) | |
1406 --curwin->w_topfill; | |
1407 else | |
1408 # endif | |
1409 { | |
1410 # ifdef FEAT_FOLDING | |
1411 if (byfold) | |
1412 (void)hasFolding(lnum, NULL, &lnum); | |
1413 # endif | |
1414 if (lnum >= curbuf->b_ml.ml_line_count) | |
1415 break; | |
1416 ++lnum; | |
1417 # ifdef FEAT_DIFF | |
1418 curwin->w_topfill = diff_check_fill(curwin, lnum); | |
1419 # endif | |
1420 } | |
1421 } | |
1422 /* approximate w_botline */ | |
1423 curwin->w_botline += lnum - curwin->w_topline; | |
1424 curwin->w_topline = lnum; | |
1425 } | |
1426 else | |
1427 #endif | |
1428 { | |
1429 curwin->w_topline += line_count; | |
1430 curwin->w_botline += line_count; /* approximate w_botline */ | |
1431 } | |
1432 | |
1433 if (curwin->w_topline > curbuf->b_ml.ml_line_count) | |
1434 curwin->w_topline = curbuf->b_ml.ml_line_count; | |
1435 if (curwin->w_botline > curbuf->b_ml.ml_line_count + 1) | |
1436 curwin->w_botline = curbuf->b_ml.ml_line_count + 1; | |
1437 | |
1438 #ifdef FEAT_DIFF | |
1439 check_topfill(curwin, FALSE); | |
1440 #endif | |
1441 | |
1442 #ifdef FEAT_FOLDING | |
1443 if (hasAnyFolding(curwin)) | |
1444 /* Make sure w_topline is at the first of a sequence of folded lines. */ | |
1445 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); | |
1446 #endif | |
1447 | |
1448 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); | |
1449 if (curwin->w_cursor.lnum < curwin->w_topline) | |
1450 { | |
1451 curwin->w_cursor.lnum = curwin->w_topline; | |
1452 curwin->w_valid &= | |
1453 ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL); | |
1454 coladvance(curwin->w_curswant); | |
1455 } | |
1456 } | |
1457 | |
1458 #ifdef FEAT_DIFF | |
1459 /* | |
1460 * Don't end up with too many filler lines in the window. | |
1461 */ | |
1462 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1463 check_topfill( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1464 win_T *wp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1465 int down) /* when TRUE scroll down when not enough space */ |
7 | 1466 { |
1467 int n; | |
1468 | |
1469 if (wp->w_topfill > 0) | |
1470 { | |
1471 n = plines_win_nofill(wp, wp->w_topline, TRUE); | |
1472 if (wp->w_topfill + n > wp->w_height) | |
1473 { | |
1474 if (down && wp->w_topline > 1) | |
1475 { | |
1476 --wp->w_topline; | |
1477 wp->w_topfill = 0; | |
1478 } | |
1479 else | |
1480 { | |
1481 wp->w_topfill = wp->w_height - n; | |
1482 if (wp->w_topfill < 0) | |
1483 wp->w_topfill = 0; | |
1484 } | |
1485 } | |
1486 } | |
1487 } | |
1488 | |
1489 /* | |
1490 * Use as many filler lines as possible for w_topline. Make sure w_topline | |
1491 * is still visible. | |
1492 */ | |
1493 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1494 max_topfill(void) |
7 | 1495 { |
1496 int n; | |
1497 | |
1498 n = plines_nofill(curwin->w_topline); | |
1499 if (n >= curwin->w_height) | |
1500 curwin->w_topfill = 0; | |
1501 else | |
1502 { | |
1503 curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline); | |
1504 if (curwin->w_topfill + n > curwin->w_height) | |
1505 curwin->w_topfill = curwin->w_height - n; | |
1506 } | |
1507 } | |
1508 #endif | |
1509 | |
1510 /* | |
1511 * Scroll the screen one line down, but don't do it if it would move the | |
1512 * cursor off the screen. | |
1513 */ | |
1514 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1515 scrolldown_clamp(void) |
7 | 1516 { |
1517 int end_row; | |
1518 #ifdef FEAT_DIFF | |
1519 int can_fill = (curwin->w_topfill | |
1520 < diff_check_fill(curwin, curwin->w_topline)); | |
1521 #endif | |
1522 | |
1523 if (curwin->w_topline <= 1 | |
1524 #ifdef FEAT_DIFF | |
1525 && !can_fill | |
1526 #endif | |
1527 ) | |
1528 return; | |
1529 | |
1530 validate_cursor(); /* w_wrow needs to be valid */ | |
1531 | |
1532 /* | |
1533 * Compute the row number of the last row of the cursor line | |
1534 * and make sure it doesn't go off the screen. Make sure the cursor | |
1535 * doesn't go past 'scrolloff' lines from the screen end. | |
1536 */ | |
1537 end_row = curwin->w_wrow; | |
1538 #ifdef FEAT_DIFF | |
1539 if (can_fill) | |
1540 ++end_row; | |
1541 else | |
1542 end_row += plines_nofill(curwin->w_topline - 1); | |
1543 #else | |
1544 end_row += plines(curwin->w_topline - 1); | |
1545 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
1546 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 1547 { |
1548 validate_cheight(); | |
1549 validate_virtcol(); | |
1550 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
|
1551 curwin->w_virtcol / curwin->w_width; |
7 | 1552 } |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
1553 if (end_row < curwin->w_height - get_scrolloff_value()) |
7 | 1554 { |
1555 #ifdef FEAT_DIFF | |
1556 if (can_fill) | |
1557 { | |
1558 ++curwin->w_topfill; | |
1559 check_topfill(curwin, TRUE); | |
1560 } | |
1561 else | |
1562 { | |
1563 --curwin->w_topline; | |
1564 curwin->w_topfill = 0; | |
1565 } | |
1566 #else | |
1567 --curwin->w_topline; | |
1568 #endif | |
1569 #ifdef FEAT_FOLDING | |
7009 | 1570 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
7 | 1571 #endif |
1572 --curwin->w_botline; /* approximate w_botline */ | |
1573 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); | |
1574 } | |
1575 } | |
1576 | |
1577 /* | |
1578 * Scroll the screen one line up, but don't do it if it would move the cursor | |
1579 * off the screen. | |
1580 */ | |
1581 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1582 scrollup_clamp(void) |
7 | 1583 { |
1584 int start_row; | |
1585 | |
1586 if (curwin->w_topline == curbuf->b_ml.ml_line_count | |
1587 #ifdef FEAT_DIFF | |
1588 && curwin->w_topfill == 0 | |
1589 #endif | |
1590 ) | |
1591 return; | |
1592 | |
1593 validate_cursor(); /* w_wrow needs to be valid */ | |
1594 | |
1595 /* | |
1596 * Compute the row number of the first row of the cursor line | |
1597 * and make sure it doesn't go off the screen. Make sure the cursor | |
1598 * doesn't go before 'scrolloff' lines from the screen start. | |
1599 */ | |
1600 #ifdef FEAT_DIFF | |
1601 start_row = curwin->w_wrow - plines_nofill(curwin->w_topline) | |
1602 - curwin->w_topfill; | |
1603 #else | |
1604 start_row = curwin->w_wrow - plines(curwin->w_topline); | |
1605 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
1606 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 1607 { |
1608 validate_virtcol(); | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1609 start_row -= curwin->w_virtcol / curwin->w_width; |
7 | 1610 } |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
1611 if (start_row >= get_scrolloff_value()) |
7 | 1612 { |
1613 #ifdef FEAT_DIFF | |
1614 if (curwin->w_topfill > 0) | |
1615 --curwin->w_topfill; | |
1616 else | |
1617 #endif | |
36 | 1618 { |
1619 #ifdef FEAT_FOLDING | |
1620 (void)hasFolding(curwin->w_topline, NULL, &curwin->w_topline); | |
1621 #endif | |
7 | 1622 ++curwin->w_topline; |
36 | 1623 } |
7 | 1624 ++curwin->w_botline; /* approximate w_botline */ |
1625 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); | |
1626 } | |
1627 } | |
1628 | |
1629 /* | |
1630 * Add one line above "lp->lnum". This can be a filler line, a closed fold or | |
1631 * a (wrapped) text line. Uses and sets "lp->fill". | |
1632 * 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
|
1633 * Lines above the first one are incredibly high: MAXCOL. |
7 | 1634 */ |
1635 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1636 topline_back(lineoff_T *lp) |
7 | 1637 { |
1638 #ifdef FEAT_DIFF | |
1639 if (lp->fill < diff_check_fill(curwin, lp->lnum)) | |
1640 { | |
1641 /* Add a filler line. */ | |
1642 ++lp->fill; | |
1643 lp->height = 1; | |
1644 } | |
1645 else | |
1646 #endif | |
1647 { | |
1648 --lp->lnum; | |
1649 #ifdef FEAT_DIFF | |
1650 lp->fill = 0; | |
1651 #endif | |
1652 if (lp->lnum < 1) | |
1653 lp->height = MAXCOL; | |
1654 else | |
1655 #ifdef FEAT_FOLDING | |
1656 if (hasFolding(lp->lnum, &lp->lnum, NULL)) | |
1657 /* Add a closed fold */ | |
1658 lp->height = 1; | |
1659 else | |
1660 #endif | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
1661 lp->height = PLINES_NOFILL(lp->lnum); |
7 | 1662 } |
1663 } | |
1664 | |
1665 /* | |
1666 * Add one line below "lp->lnum". This can be a filler line, a closed fold or | |
1667 * a (wrapped) text line. Uses and sets "lp->fill". | |
1668 * Returns the height of the added line in "lp->height". | |
1669 * Lines below the last one are incredibly high. | |
1670 */ | |
1671 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1672 botline_forw(lineoff_T *lp) |
7 | 1673 { |
1674 #ifdef FEAT_DIFF | |
1675 if (lp->fill < diff_check_fill(curwin, lp->lnum + 1)) | |
1676 { | |
1677 /* Add a filler line. */ | |
1678 ++lp->fill; | |
1679 lp->height = 1; | |
1680 } | |
1681 else | |
1682 #endif | |
1683 { | |
1684 ++lp->lnum; | |
1685 #ifdef FEAT_DIFF | |
1686 lp->fill = 0; | |
1687 #endif | |
1688 if (lp->lnum > curbuf->b_ml.ml_line_count) | |
1689 lp->height = MAXCOL; | |
1690 else | |
1691 #ifdef FEAT_FOLDING | |
1692 if (hasFolding(lp->lnum, NULL, &lp->lnum)) | |
1693 /* Add a closed fold */ | |
1694 lp->height = 1; | |
1695 else | |
1696 #endif | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
1697 lp->height = PLINES_NOFILL(lp->lnum); |
7 | 1698 } |
1699 } | |
1700 | |
1701 #ifdef FEAT_DIFF | |
1702 /* | |
1703 * Switch from including filler lines below lp->lnum to including filler | |
1704 * lines above loff.lnum + 1. This keeps pointing to the same line. | |
1705 * When there are no filler lines nothing changes. | |
1706 */ | |
1707 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1708 botline_topline(lineoff_T *lp) |
7 | 1709 { |
1710 if (lp->fill > 0) | |
1711 { | |
1712 ++lp->lnum; | |
1713 lp->fill = diff_check_fill(curwin, lp->lnum) - lp->fill + 1; | |
1714 } | |
1715 } | |
1716 | |
1717 /* | |
1718 * Switch from including filler lines above lp->lnum to including filler | |
1719 * lines below loff.lnum - 1. This keeps pointing to the same line. | |
1720 * When there are no filler lines nothing changes. | |
1721 */ | |
1722 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1723 topline_botline(lineoff_T *lp) |
7 | 1724 { |
1725 if (lp->fill > 0) | |
1726 { | |
1727 lp->fill = diff_check_fill(curwin, lp->lnum) - lp->fill + 1; | |
1728 --lp->lnum; | |
1729 } | |
1730 } | |
1731 #endif | |
1732 | |
1733 /* | |
1734 * Recompute topline to put the cursor at the top of the window. | |
1735 * Scroll at least "min_scroll" lines. | |
1736 * If "always" is TRUE, always set topline (for "zt"). | |
1737 */ | |
1738 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1739 scroll_cursor_top(int min_scroll, int always) |
7 | 1740 { |
1741 int scrolled = 0; | |
1742 int extra = 0; | |
1743 int used; | |
1744 int i; | |
1745 linenr_T top; /* just above displayed lines */ | |
1746 linenr_T bot; /* just below displayed lines */ | |
1747 linenr_T old_topline = curwin->w_topline; | |
1748 #ifdef FEAT_DIFF | |
1749 linenr_T old_topfill = curwin->w_topfill; | |
1750 #endif | |
1751 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
|
1752 int off = get_scrolloff_value(); |
7 | 1753 |
1754 #ifdef FEAT_MOUSE | |
1755 if (mouse_dragging > 0) | |
1756 off = mouse_dragging - 1; | |
1757 #endif | |
1758 | |
1759 /* | |
1760 * Decrease topline until: | |
1761 * - it has become 1 | |
1762 * - (part of) the cursor line is moved off the screen or | |
1763 * - moved at least 'scrolljump' lines and | |
1764 * - at least 'scrolloff' lines above and below the cursor | |
1765 */ | |
1766 validate_cheight(); | |
7082
ad4c039349f6
commit https://github.com/vim/vim/commit/cf619daa8e0ef9a335f27f65eb74e422a17d4f92
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1767 used = curwin->w_cline_height; /* includes filler lines above */ |
7 | 1768 if (curwin->w_cursor.lnum < curwin->w_topline) |
1769 scrolled = used; | |
1770 | |
1771 #ifdef FEAT_FOLDING | |
1772 if (hasFolding(curwin->w_cursor.lnum, &top, &bot)) | |
1773 { | |
1774 --top; | |
1775 ++bot; | |
1776 } | |
1777 else | |
1778 #endif | |
1779 { | |
1780 top = curwin->w_cursor.lnum - 1; | |
1781 bot = curwin->w_cursor.lnum + 1; | |
1782 } | |
1783 new_topline = top + 1; | |
1784 | |
1785 #ifdef FEAT_DIFF | |
7088
8a58dde655a8
commit https://github.com/vim/vim/commit/a09a2c5857ab854f0870573b5160da1964c905a2
Christian Brabandt <cb@256bit.org>
parents:
7082
diff
changeset
|
1786 /* "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
|
1787 * again. |
7088
8a58dde655a8
commit https://github.com/vim/vim/commit/a09a2c5857ab854f0870573b5160da1964c905a2
Christian Brabandt <cb@256bit.org>
parents:
7082
diff
changeset
|
1788 * 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
|
1789 extra += diff_check_fill(curwin, curwin->w_cursor.lnum); |
7 | 1790 #endif |
1791 | |
1792 /* | |
1793 * Check if the lines from "top" to "bot" fit in the window. If they do, | |
1794 * set new_topline and advance "top" and "bot" to include more lines. | |
1795 */ | |
1796 while (top > 0) | |
1797 { | |
1798 #ifdef FEAT_FOLDING | |
1799 if (hasFolding(top, &top, NULL)) | |
1800 /* count one logical line for a sequence of folded lines */ | |
1801 i = 1; | |
1802 else | |
1803 #endif | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
1804 i = PLINES_NOFILL(top); |
7 | 1805 used += i; |
1806 if (extra + i <= off && bot < curbuf->b_ml.ml_line_count) | |
1807 { | |
1808 #ifdef FEAT_FOLDING | |
1809 if (hasFolding(bot, NULL, &bot)) | |
1810 /* count one logical line for a sequence of folded lines */ | |
1811 ++used; | |
1812 else | |
1813 #endif | |
1814 used += plines(bot); | |
1815 } | |
1816 if (used > curwin->w_height) | |
1817 break; | |
1818 if (top < curwin->w_topline) | |
1819 scrolled += i; | |
1820 | |
1821 /* | |
1822 * If scrolling is needed, scroll at least 'sj' lines. | |
1823 */ | |
1824 if ((new_topline >= curwin->w_topline || scrolled > min_scroll) | |
1825 && extra >= off) | |
1826 break; | |
1827 | |
1828 extra += i; | |
1829 new_topline = top; | |
1830 --top; | |
1831 ++bot; | |
1832 } | |
1833 | |
1834 /* | |
1835 * If we don't have enough space, put cursor in the middle. | |
1836 * This makes sure we get the same position when using "k" and "j" | |
1837 * in a small window. | |
1838 */ | |
1839 if (used > curwin->w_height) | |
1840 scroll_cursor_halfway(FALSE); | |
1841 else | |
1842 { | |
1843 /* | |
1844 * If "always" is FALSE, only adjust topline to a lower value, higher | |
1845 * value may happen with wrapping lines | |
1846 */ | |
1847 if (new_topline < curwin->w_topline || always) | |
1848 curwin->w_topline = new_topline; | |
1849 if (curwin->w_topline > curwin->w_cursor.lnum) | |
1850 curwin->w_topline = curwin->w_cursor.lnum; | |
1851 #ifdef FEAT_DIFF | |
1852 curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline); | |
1853 if (curwin->w_topfill > 0 && extra > off) | |
1854 { | |
1855 curwin->w_topfill -= extra - off; | |
1856 if (curwin->w_topfill < 0) | |
1857 curwin->w_topfill = 0; | |
1858 } | |
1859 check_topfill(curwin, FALSE); | |
1860 #endif | |
1861 if (curwin->w_topline != old_topline | |
1862 #ifdef FEAT_DIFF | |
1863 || curwin->w_topfill != old_topfill | |
1864 #endif | |
1865 ) | |
1866 curwin->w_valid &= | |
1867 ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); | |
1868 curwin->w_valid |= VALID_TOPLINE; | |
1869 } | |
1870 } | |
1871 | |
1872 /* | |
1873 * Set w_empty_rows and w_filler_rows for window "wp", having used up "used" | |
1874 * screen lines for text lines. | |
1875 */ | |
1876 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1877 set_empty_rows(win_T *wp, int used) |
7 | 1878 { |
1879 #ifdef FEAT_DIFF | |
1880 wp->w_filler_rows = 0; | |
1881 #endif | |
1882 if (used == 0) | |
1883 wp->w_empty_rows = 0; /* single line that doesn't fit */ | |
1884 else | |
1885 { | |
1886 wp->w_empty_rows = wp->w_height - used; | |
1887 #ifdef FEAT_DIFF | |
1888 if (wp->w_botline <= wp->w_buffer->b_ml.ml_line_count) | |
1889 { | |
1890 wp->w_filler_rows = diff_check_fill(wp, wp->w_botline); | |
1891 if (wp->w_empty_rows > wp->w_filler_rows) | |
1892 wp->w_empty_rows -= wp->w_filler_rows; | |
1893 else | |
1894 { | |
1895 wp->w_filler_rows = wp->w_empty_rows; | |
1896 wp->w_empty_rows = 0; | |
1897 } | |
1898 } | |
1899 #endif | |
1900 } | |
1901 } | |
1902 | |
1903 /* | |
1904 * Recompute topline to put the cursor at the bottom of the window. | |
1905 * Scroll at least "min_scroll" lines. | |
1906 * If "set_topbot" is TRUE, set topline and botline first (for "zb"). | |
1907 * This is messy stuff!!! | |
1908 */ | |
1909 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1910 scroll_cursor_bot(int min_scroll, int set_topbot) |
7 | 1911 { |
1912 int used; | |
1913 int scrolled = 0; | |
1914 int extra = 0; | |
1915 int i; | |
1916 linenr_T line_count; | |
1917 linenr_T old_topline = curwin->w_topline; | |
1918 lineoff_T loff; | |
1919 lineoff_T boff; | |
1920 #ifdef FEAT_DIFF | |
1921 int old_topfill = curwin->w_topfill; | |
1922 int fill_below_window; | |
1923 #endif | |
1924 linenr_T old_botline = curwin->w_botline; | |
1925 linenr_T old_valid = curwin->w_valid; | |
1926 int old_empty_rows = curwin->w_empty_rows; | |
1927 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
|
1928 long so = get_scrolloff_value(); |
7 | 1929 |
1930 cln = curwin->w_cursor.lnum; | |
1931 if (set_topbot) | |
1932 { | |
1933 used = 0; | |
1934 curwin->w_botline = cln + 1; | |
1935 #ifdef FEAT_DIFF | |
1936 loff.fill = 0; | |
1937 #endif | |
1938 for (curwin->w_topline = curwin->w_botline; | |
1939 curwin->w_topline > 1; | |
1940 curwin->w_topline = loff.lnum) | |
1941 { | |
1942 loff.lnum = curwin->w_topline; | |
1943 topline_back(&loff); | |
2082
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
1944 if (loff.height == MAXCOL || used + loff.height > curwin->w_height) |
7 | 1945 break; |
1946 used += loff.height; | |
1947 #ifdef FEAT_DIFF | |
1948 curwin->w_topfill = loff.fill; | |
1949 #endif | |
1950 } | |
1951 set_empty_rows(curwin, used); | |
1952 curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP; | |
1953 if (curwin->w_topline != old_topline | |
1954 #ifdef FEAT_DIFF | |
1955 || curwin->w_topfill != old_topfill | |
1956 #endif | |
1957 ) | |
1958 curwin->w_valid &= ~(VALID_WROW|VALID_CROW); | |
1959 } | |
1960 else | |
1961 validate_botline(); | |
1962 | |
1963 /* The lines of the cursor line itself are always used. */ | |
1964 #ifdef FEAT_DIFF | |
1965 used = plines_nofill(cln); | |
1966 #else | |
1967 validate_cheight(); | |
1968 used = curwin->w_cline_height; | |
1969 #endif | |
1970 | |
1971 /* If the cursor is below botline, we will at least scroll by the height | |
1972 * of the cursor line. Correct for empty lines, which are really part of | |
1973 * botline. */ | |
1974 if (cln >= curwin->w_botline) | |
1975 { | |
1976 scrolled = used; | |
1977 if (cln == curwin->w_botline) | |
1978 scrolled -= curwin->w_empty_rows; | |
1979 } | |
1980 | |
1981 /* | |
1982 * Stop counting lines to scroll when | |
1983 * - hitting start of the file | |
1984 * - 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
|
1985 * - at least 'scrolloff' lines below the cursor |
7 | 1986 * - lines between botline and cursor have been counted |
1987 */ | |
1988 #ifdef FEAT_FOLDING | |
1989 if (!hasFolding(curwin->w_cursor.lnum, &loff.lnum, &boff.lnum)) | |
1990 #endif | |
1991 { | |
1992 loff.lnum = cln; | |
1993 boff.lnum = cln; | |
1994 } | |
1995 #ifdef FEAT_DIFF | |
1996 loff.fill = 0; | |
1997 boff.fill = 0; | |
1998 fill_below_window = diff_check_fill(curwin, curwin->w_botline) | |
1999 - curwin->w_filler_rows; | |
2000 #endif | |
2001 | |
2002 while (loff.lnum > 1) | |
2003 { | |
2004 /* Stop when scrolled nothing or at least "min_scroll", found "extra" | |
2005 * context for 'scrolloff' and counted all lines below the window. */ | |
2006 if ((((scrolled <= 0 || scrolled >= min_scroll) | |
2007 && extra >= ( | |
2008 #ifdef FEAT_MOUSE | |
1121 | 2009 mouse_dragging > 0 ? mouse_dragging - 1 : |
7 | 2010 #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
|
2011 so)) |
7 | 2012 || boff.lnum + 1 > curbuf->b_ml.ml_line_count) |
2013 && loff.lnum <= curwin->w_botline | |
2014 #ifdef FEAT_DIFF | |
2015 && (loff.lnum < curwin->w_botline | |
2016 || loff.fill >= fill_below_window) | |
2017 #endif | |
2018 ) | |
2019 break; | |
2020 | |
2021 /* Add one line above */ | |
2022 topline_back(&loff); | |
2082
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2023 if (loff.height == MAXCOL) |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2024 used = MAXCOL; |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2025 else |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2026 used += loff.height; |
7 | 2027 if (used > curwin->w_height) |
2028 break; | |
2029 if (loff.lnum >= curwin->w_botline | |
2030 #ifdef FEAT_DIFF | |
2031 && (loff.lnum > curwin->w_botline | |
2032 || loff.fill <= fill_below_window) | |
2033 #endif | |
2034 ) | |
2035 { | |
2036 /* Count screen lines that are below the window. */ | |
2037 scrolled += loff.height; | |
2038 if (loff.lnum == curwin->w_botline | |
2039 #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
|
2040 && loff.fill == 0 |
7 | 2041 #endif |
2042 ) | |
2043 scrolled -= curwin->w_empty_rows; | |
2044 } | |
2045 | |
2046 if (boff.lnum < curbuf->b_ml.ml_line_count) | |
2047 { | |
2048 /* Add one line below */ | |
2049 botline_forw(&boff); | |
2050 used += boff.height; | |
2051 if (used > curwin->w_height) | |
2052 break; | |
2053 if (extra < ( | |
2054 #ifdef FEAT_MOUSE | |
2055 mouse_dragging > 0 ? mouse_dragging - 1 : | |
2056 #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
|
2057 so) || scrolled < min_scroll) |
7 | 2058 { |
2059 extra += boff.height; | |
2060 if (boff.lnum >= curwin->w_botline | |
2061 #ifdef FEAT_DIFF | |
2062 || (boff.lnum + 1 == curwin->w_botline | |
2063 && boff.fill > curwin->w_filler_rows) | |
2064 #endif | |
2065 ) | |
2066 { | |
2067 /* Count screen lines that are below the window. */ | |
2068 scrolled += boff.height; | |
2069 if (boff.lnum == curwin->w_botline | |
2070 #ifdef FEAT_DIFF | |
2071 && boff.fill == 0 | |
2072 #endif | |
2073 ) | |
2074 scrolled -= curwin->w_empty_rows; | |
2075 } | |
2076 } | |
2077 } | |
2078 } | |
2079 | |
2080 /* curwin->w_empty_rows is larger, no need to scroll */ | |
2081 if (scrolled <= 0) | |
2082 line_count = 0; | |
2083 /* more than a screenfull, don't scroll but redraw */ | |
2084 else if (used > curwin->w_height) | |
2085 line_count = used; | |
2086 /* scroll minimal number of lines */ | |
2087 else | |
2088 { | |
2089 line_count = 0; | |
2090 #ifdef FEAT_DIFF | |
2091 boff.fill = curwin->w_topfill; | |
2092 #endif | |
2093 boff.lnum = curwin->w_topline - 1; | |
2094 for (i = 0; i < scrolled && boff.lnum < curwin->w_botline; ) | |
2095 { | |
2096 botline_forw(&boff); | |
2097 i += boff.height; | |
2098 ++line_count; | |
2099 } | |
2100 if (i < scrolled) /* below curwin->w_botline, don't scroll */ | |
2101 line_count = 9999; | |
2102 } | |
2103 | |
2104 /* | |
2105 * Scroll up if the cursor is off the bottom of the screen a bit. | |
2106 * Otherwise put it at 1/2 of the screen. | |
2107 */ | |
2108 if (line_count >= curwin->w_height && line_count > min_scroll) | |
2109 scroll_cursor_halfway(FALSE); | |
2110 else | |
2111 scrollup(line_count, TRUE); | |
2112 | |
2113 /* | |
2114 * If topline didn't change we need to restore w_botline and w_empty_rows | |
2115 * (we changed them). | |
2116 * If topline did change, update_screen() will set botline. | |
2117 */ | |
2118 if (curwin->w_topline == old_topline && set_topbot) | |
2119 { | |
2120 curwin->w_botline = old_botline; | |
2121 curwin->w_empty_rows = old_empty_rows; | |
2122 curwin->w_valid = old_valid; | |
2123 } | |
2124 curwin->w_valid |= VALID_TOPLINE; | |
2125 } | |
2126 | |
2127 /* | |
2128 * Recompute topline to put the cursor halfway the window | |
2129 * If "atend" is TRUE, also put it halfway at the end of the file. | |
2130 */ | |
2131 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2132 scroll_cursor_halfway(int atend) |
7 | 2133 { |
2134 int above = 0; | |
2135 linenr_T topline; | |
2136 #ifdef FEAT_DIFF | |
2137 int topfill = 0; | |
2138 #endif | |
2139 int below = 0; | |
2140 int used; | |
2141 lineoff_T loff; | |
2142 lineoff_T boff; | |
5661 | 2143 #ifdef FEAT_DIFF |
5653 | 2144 linenr_T old_topline = curwin->w_topline; |
5661 | 2145 #endif |
7 | 2146 |
2147 loff.lnum = boff.lnum = curwin->w_cursor.lnum; | |
2148 #ifdef FEAT_FOLDING | |
2149 (void)hasFolding(loff.lnum, &loff.lnum, &boff.lnum); | |
2150 #endif | |
2151 #ifdef FEAT_DIFF | |
2152 used = plines_nofill(loff.lnum); | |
2153 loff.fill = 0; | |
2154 boff.fill = 0; | |
2155 #else | |
2156 used = plines(loff.lnum); | |
2157 #endif | |
2158 topline = loff.lnum; | |
2159 while (topline > 1) | |
2160 { | |
2161 if (below <= above) /* add a line below the cursor first */ | |
2162 { | |
2163 if (boff.lnum < curbuf->b_ml.ml_line_count) | |
2164 { | |
2165 botline_forw(&boff); | |
2166 used += boff.height; | |
2167 if (used > curwin->w_height) | |
2168 break; | |
2169 below += boff.height; | |
2170 } | |
2171 else | |
2172 { | |
2173 ++below; /* count a "~" line */ | |
2174 if (atend) | |
2175 ++used; | |
2176 } | |
2177 } | |
2178 | |
2179 if (below > above) /* add a line above the cursor */ | |
2180 { | |
2181 topline_back(&loff); | |
2082
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2182 if (loff.height == MAXCOL) |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2183 used = MAXCOL; |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2184 else |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2185 used += loff.height; |
7 | 2186 if (used > curwin->w_height) |
2187 break; | |
2188 above += loff.height; | |
2189 topline = loff.lnum; | |
2190 #ifdef FEAT_DIFF | |
2191 topfill = loff.fill; | |
2192 #endif | |
2193 } | |
2194 } | |
2195 #ifdef FEAT_FOLDING | |
2196 if (!hasFolding(topline, &curwin->w_topline, NULL)) | |
2197 #endif | |
2198 curwin->w_topline = topline; | |
2199 #ifdef FEAT_DIFF | |
2200 curwin->w_topfill = topfill; | |
5653 | 2201 if (old_topline > curwin->w_topline + curwin->w_height) |
2202 curwin->w_botfill = FALSE; | |
7 | 2203 check_topfill(curwin, FALSE); |
2204 #endif | |
2205 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); | |
2206 curwin->w_valid |= VALID_TOPLINE; | |
2207 } | |
2208 | |
2209 /* | |
2210 * 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
|
2211 * 'scrolloff' lines from the top and bottom, if possible. |
7 | 2212 * If not possible, put it at the same position as scroll_cursor_halfway(). |
2213 * When called topline must be valid! | |
2214 */ | |
2215 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2216 cursor_correct(void) |
7 | 2217 { |
2218 int above = 0; /* screen lines above topline */ | |
2219 linenr_T topline; | |
2220 int below = 0; /* screen lines below botline */ | |
2221 linenr_T botline; | |
2222 int above_wanted, below_wanted; | |
2223 linenr_T cln; /* Cursor Line Number */ | |
2224 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
|
2225 long so = get_scrolloff_value(); |
7 | 2226 |
2227 /* | |
2228 * How many lines we would like to have above/below the cursor depends on | |
2229 * whether the first/last line of the file is on screen. | |
2230 */ | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
2231 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
|
2232 below_wanted = so; |
7 | 2233 #ifdef FEAT_MOUSE |
1121 | 2234 if (mouse_dragging > 0) |
7 | 2235 { |
2236 above_wanted = mouse_dragging - 1; | |
2237 below_wanted = mouse_dragging - 1; | |
2238 } | |
2239 #endif | |
2240 if (curwin->w_topline == 1) | |
2241 { | |
2242 above_wanted = 0; | |
2243 max_off = curwin->w_height / 2; | |
2244 if (below_wanted > max_off) | |
2245 below_wanted = max_off; | |
2246 } | |
2247 validate_botline(); | |
2248 if (curwin->w_botline == curbuf->b_ml.ml_line_count + 1 | |
2249 #ifdef FEAT_MOUSE | |
1121 | 2250 && mouse_dragging == 0 |
7 | 2251 #endif |
2252 ) | |
2253 { | |
2254 below_wanted = 0; | |
2255 max_off = (curwin->w_height - 1) / 2; | |
2256 if (above_wanted > max_off) | |
2257 above_wanted = max_off; | |
2258 } | |
2259 | |
2260 /* | |
2261 * If there are sufficient file-lines above and below the cursor, we can | |
2262 * return now. | |
2263 */ | |
2264 cln = curwin->w_cursor.lnum; | |
2265 if (cln >= curwin->w_topline + above_wanted | |
2266 && cln < curwin->w_botline - below_wanted | |
2267 #ifdef FEAT_FOLDING | |
2268 && !hasAnyFolding(curwin) | |
2269 #endif | |
2270 ) | |
2271 return; | |
2272 | |
2273 /* | |
2274 * Narrow down the area where the cursor can be put by taking lines from | |
2275 * the top and the bottom until: | |
2276 * - the desired context lines are found | |
2277 * - the lines from the top is past the lines from the bottom | |
2278 */ | |
2279 topline = curwin->w_topline; | |
2280 botline = curwin->w_botline - 1; | |
2281 #ifdef FEAT_DIFF | |
2282 /* count filler lines as context */ | |
2283 above = curwin->w_topfill; | |
2284 below = curwin->w_filler_rows; | |
2285 #endif | |
2286 while ((above < above_wanted || below < below_wanted) && topline < botline) | |
2287 { | |
2288 if (below < below_wanted && (below <= above || above >= above_wanted)) | |
2289 { | |
2290 #ifdef FEAT_FOLDING | |
2291 if (hasFolding(botline, &botline, NULL)) | |
2292 ++below; | |
2293 else | |
2294 #endif | |
2295 below += plines(botline); | |
2296 --botline; | |
2297 } | |
2298 if (above < above_wanted && (above < below || below >= below_wanted)) | |
2299 { | |
2300 #ifdef FEAT_FOLDING | |
2301 if (hasFolding(topline, NULL, &topline)) | |
2302 ++above; | |
2303 else | |
2304 #endif | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
2305 above += PLINES_NOFILL(topline); |
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
2306 #ifdef FEAT_DIFF |
7 | 2307 /* Count filler lines below this line as context. */ |
2308 if (topline < botline) | |
2309 above += diff_check_fill(curwin, topline + 1); | |
2310 #endif | |
2311 ++topline; | |
2312 } | |
2313 } | |
2314 if (topline == botline || botline == 0) | |
2315 curwin->w_cursor.lnum = topline; | |
2316 else if (topline > botline) | |
2317 curwin->w_cursor.lnum = botline; | |
2318 else | |
2319 { | |
2320 if (cln < topline && curwin->w_topline > 1) | |
2321 { | |
2322 curwin->w_cursor.lnum = topline; | |
2323 curwin->w_valid &= | |
2324 ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW); | |
2325 } | |
2326 if (cln > botline && curwin->w_botline <= curbuf->b_ml.ml_line_count) | |
2327 { | |
2328 curwin->w_cursor.lnum = botline; | |
2329 curwin->w_valid &= | |
2330 ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW); | |
2331 } | |
2332 } | |
2333 curwin->w_valid |= VALID_TOPLINE; | |
2334 } | |
2335 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7103
diff
changeset
|
2336 static void get_scroll_overlap(lineoff_T *lp, int dir); |
7 | 2337 |
2338 /* | |
2339 * move screen 'count' pages up or down and update screen | |
2340 * | |
2341 * return FAIL for failure, OK otherwise | |
2342 */ | |
2343 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2344 onepage(int dir, long count) |
7 | 2345 { |
2346 long n; | |
2347 int retval = OK; | |
2348 lineoff_T loff; | |
2349 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
|
2350 long so = get_scrolloff_value(); |
7 | 2351 |
2352 if (curbuf->b_ml.ml_line_count == 1) /* nothing to do */ | |
2353 { | |
2354 beep_flush(); | |
2355 return FAIL; | |
2356 } | |
2357 | |
2358 for ( ; count > 0; --count) | |
2359 { | |
2360 validate_botline(); | |
2361 /* | |
2362 * It's an error to move a page up when the first line is already on | |
2363 * the screen. It's an error to move a page down when the last line | |
2364 * is on the screen and the topline is 'scrolloff' lines from the | |
2365 * last line. | |
2366 */ | |
2367 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
|
2368 ? ((curwin->w_topline >= curbuf->b_ml.ml_line_count - so) |
7 | 2369 && curwin->w_botline > curbuf->b_ml.ml_line_count) |
2370 : (curwin->w_topline == 1 | |
2371 #ifdef FEAT_DIFF | |
2372 && curwin->w_topfill == | |
2373 diff_check_fill(curwin, curwin->w_topline) | |
2374 #endif | |
2375 )) | |
2376 { | |
2377 beep_flush(); | |
2378 retval = FAIL; | |
2379 break; | |
2380 } | |
2381 | |
2382 #ifdef FEAT_DIFF | |
2383 loff.fill = 0; | |
2384 #endif | |
2385 if (dir == FORWARD) | |
2386 { | |
10349
cf988222b150
commit https://github.com/vim/vim/commit/a1f4cb93ba50ea9e40cd4b1f5592b8a6d1398660
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
2387 if (ONE_WINDOW && p_window > 0 && p_window < Rows - 1) |
7 | 2388 { |
164 | 2389 /* Vi compatible scrolling */ |
2390 if (p_window <= 2) | |
2391 ++curwin->w_topline; | |
2392 else | |
2393 curwin->w_topline += p_window - 2; | |
2394 if (curwin->w_topline > curbuf->b_ml.ml_line_count) | |
2395 curwin->w_topline = curbuf->b_ml.ml_line_count; | |
2396 curwin->w_cursor.lnum = curwin->w_topline; | |
2397 } | |
2398 else if (curwin->w_botline > curbuf->b_ml.ml_line_count) | |
2399 { | |
2400 /* at end of file */ | |
7 | 2401 curwin->w_topline = curbuf->b_ml.ml_line_count; |
2402 #ifdef FEAT_DIFF | |
2403 curwin->w_topfill = 0; | |
2404 #endif | |
2405 curwin->w_valid &= ~(VALID_WROW|VALID_CROW); | |
2406 } | |
2407 else | |
2408 { | |
2409 /* For the overlap, start with the line just below the window | |
2410 * and go upwards. */ | |
2411 loff.lnum = curwin->w_botline; | |
2412 #ifdef FEAT_DIFF | |
2413 loff.fill = diff_check_fill(curwin, loff.lnum) | |
2414 - curwin->w_filler_rows; | |
2415 #endif | |
2416 get_scroll_overlap(&loff, -1); | |
2417 curwin->w_topline = loff.lnum; | |
2418 #ifdef FEAT_DIFF | |
2419 curwin->w_topfill = loff.fill; | |
2420 check_topfill(curwin, FALSE); | |
2421 #endif | |
2422 curwin->w_cursor.lnum = curwin->w_topline; | |
2423 curwin->w_valid &= ~(VALID_WCOL|VALID_CHEIGHT|VALID_WROW| | |
2424 VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); | |
2425 } | |
2426 } | |
2427 else /* dir == BACKWARDS */ | |
2428 { | |
2429 #ifdef FEAT_DIFF | |
2430 if (curwin->w_topline == 1) | |
2431 { | |
2432 /* Include max number of filler lines */ | |
2433 max_topfill(); | |
2434 continue; | |
2435 } | |
2436 #endif | |
10349
cf988222b150
commit https://github.com/vim/vim/commit/a1f4cb93ba50ea9e40cd4b1f5592b8a6d1398660
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
2437 if (ONE_WINDOW && p_window > 0 && p_window < Rows - 1) |
164 | 2438 { |
2439 /* Vi compatible scrolling (sort of) */ | |
2440 if (p_window <= 2) | |
2441 --curwin->w_topline; | |
2442 else | |
2443 curwin->w_topline -= p_window - 2; | |
2444 if (curwin->w_topline < 1) | |
2445 curwin->w_topline = 1; | |
2446 curwin->w_cursor.lnum = curwin->w_topline + p_window - 1; | |
2447 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
2448 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
2449 continue; | |
2450 } | |
2451 | |
7 | 2452 /* Find the line at the top of the window that is going to be the |
2453 * line at the bottom of the window. Make sure this results in | |
2454 * the same line as before doing CTRL-F. */ | |
2455 loff.lnum = curwin->w_topline - 1; | |
2456 #ifdef FEAT_DIFF | |
2457 loff.fill = diff_check_fill(curwin, loff.lnum + 1) | |
2458 - curwin->w_topfill; | |
2459 #endif | |
2460 get_scroll_overlap(&loff, 1); | |
2461 | |
2462 if (loff.lnum >= curbuf->b_ml.ml_line_count) | |
2463 { | |
2464 loff.lnum = curbuf->b_ml.ml_line_count; | |
2465 #ifdef FEAT_DIFF | |
2466 loff.fill = 0; | |
2467 } | |
2468 else | |
2469 { | |
2470 botline_topline(&loff); | |
2471 #endif | |
2472 } | |
2473 curwin->w_cursor.lnum = loff.lnum; | |
2474 | |
2475 /* Find the line just above the new topline to get the right line | |
2476 * at the bottom of the window. */ | |
2477 n = 0; | |
2478 while (n <= curwin->w_height && loff.lnum >= 1) | |
2479 { | |
2480 topline_back(&loff); | |
2082
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2481 if (loff.height == MAXCOL) |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2482 n = MAXCOL; |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2483 else |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2484 n += loff.height; |
7 | 2485 } |
2082
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2486 if (loff.lnum < 1) /* at begin of file */ |
7 | 2487 { |
2488 curwin->w_topline = 1; | |
2489 #ifdef FEAT_DIFF | |
2490 max_topfill(); | |
2491 #endif | |
2492 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); | |
2493 } | |
2494 else | |
2495 { | |
2496 /* Go two lines forward again. */ | |
2497 #ifdef FEAT_DIFF | |
2498 topline_botline(&loff); | |
2499 #endif | |
2500 botline_forw(&loff); | |
2501 botline_forw(&loff); | |
2502 #ifdef FEAT_DIFF | |
2503 botline_topline(&loff); | |
2504 #endif | |
2505 #ifdef FEAT_FOLDING | |
2506 /* We're at the wrong end of a fold now. */ | |
2507 (void)hasFolding(loff.lnum, &loff.lnum, NULL); | |
2508 #endif | |
2509 | |
2510 /* Always scroll at least one line. Avoid getting stuck on | |
2511 * very long lines. */ | |
2512 if (loff.lnum >= curwin->w_topline | |
2513 #ifdef FEAT_DIFF | |
2514 && (loff.lnum > curwin->w_topline | |
2515 || loff.fill >= curwin->w_topfill) | |
2516 #endif | |
2517 ) | |
2518 { | |
2519 #ifdef FEAT_DIFF | |
2520 /* First try using the maximum number of filler lines. If | |
2521 * that's not enough, backup one line. */ | |
2522 loff.fill = curwin->w_topfill; | |
2523 if (curwin->w_topfill < diff_check_fill(curwin, | |
2524 curwin->w_topline)) | |
2525 max_topfill(); | |
2526 if (curwin->w_topfill == loff.fill) | |
2527 #endif | |
2528 { | |
2529 --curwin->w_topline; | |
2530 #ifdef FEAT_DIFF | |
2531 curwin->w_topfill = 0; | |
2532 #endif | |
2533 } | |
2534 comp_botline(curwin); | |
2535 curwin->w_cursor.lnum = curwin->w_botline - 1; | |
5764 | 2536 curwin->w_valid &= |
2537 ~(VALID_WCOL|VALID_CHEIGHT|VALID_WROW|VALID_CROW); | |
7 | 2538 } |
2539 else | |
2540 { | |
2541 curwin->w_topline = loff.lnum; | |
2542 #ifdef FEAT_DIFF | |
2543 curwin->w_topfill = loff.fill; | |
2544 check_topfill(curwin, FALSE); | |
2545 #endif | |
2546 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); | |
2547 } | |
2548 } | |
2549 } | |
2550 } | |
2551 #ifdef FEAT_FOLDING | |
2552 foldAdjustCursor(); | |
2553 #endif | |
2554 cursor_correct(); | |
10102
b80ad55d62d8
commit https://github.com/vim/vim/commit/bc54f3f3fed4dc3556df8c46cee6739d211b0eb2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2555 check_cursor_col(); |
161 | 2556 if (retval == OK) |
2557 beginline(BL_SOL | BL_FIX); | |
7 | 2558 curwin->w_valid &= ~(VALID_WCOL|VALID_WROW|VALID_VIRTCOL); |
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 if (retval == OK && dir == FORWARD) |
7 | 2561 { |
14317
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2562 // 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
|
2563 // 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
|
2564 // 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
|
2565 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
|
2566 { |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2567 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
|
2568 if (curwin->w_topline <= old_topline |
7 | 2569 && 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
|
2570 { |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2571 curwin->w_topline = old_topline + 1; |
7 | 2572 #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
|
2573 (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
|
2574 #endif |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2575 } |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2576 } |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2577 #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
|
2578 else if (curwin->w_botline > curbuf->b_ml.ml_line_count) |
7 | 2579 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
2580 #endif | |
2581 } | |
2582 | |
2583 redraw_later(VALID); | |
2584 return retval; | |
2585 } | |
2586 | |
2587 /* | |
2588 * Decide how much overlap to use for page-up or page-down scrolling. | |
2589 * This is symmetric, so that doing both keeps the same lines displayed. | |
2590 * Three lines are examined: | |
2591 * | |
2592 * before CTRL-F after CTRL-F / before CTRL-B | |
2593 * etc. l1 | |
2594 * l1 last but one line ------------ | |
2595 * l2 last text line l2 top text line | |
2596 * ------------- l3 second text line | |
2597 * l3 etc. | |
2598 */ | |
2599 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2600 get_scroll_overlap(lineoff_T *lp, int dir) |
7 | 2601 { |
2602 int h1, h2, h3, h4; | |
2603 int min_height = curwin->w_height - 2; | |
2604 lineoff_T loff0, loff1, loff2; | |
2605 | |
2606 #ifdef FEAT_DIFF | |
2607 if (lp->fill > 0) | |
2608 lp->height = 1; | |
2609 else | |
2610 lp->height = plines_nofill(lp->lnum); | |
2611 #else | |
2612 lp->height = plines(lp->lnum); | |
2613 #endif | |
2614 h1 = lp->height; | |
2615 if (h1 > min_height) | |
2616 return; /* no overlap */ | |
2617 | |
2618 loff0 = *lp; | |
2619 if (dir > 0) | |
2620 botline_forw(lp); | |
2621 else | |
2622 topline_back(lp); | |
2623 h2 = lp->height; | |
3968 | 2624 if (h2 == MAXCOL || h2 + h1 > min_height) |
7 | 2625 { |
2626 *lp = loff0; /* no overlap */ | |
2627 return; | |
2628 } | |
2629 | |
2630 loff1 = *lp; | |
2631 if (dir > 0) | |
2632 botline_forw(lp); | |
2633 else | |
2634 topline_back(lp); | |
2635 h3 = lp->height; | |
3968 | 2636 if (h3 == MAXCOL || h3 + h2 > min_height) |
7 | 2637 { |
2638 *lp = loff0; /* no overlap */ | |
2639 return; | |
2640 } | |
2641 | |
2642 loff2 = *lp; | |
2643 if (dir > 0) | |
2644 botline_forw(lp); | |
2645 else | |
2646 topline_back(lp); | |
2647 h4 = lp->height; | |
3968 | 2648 if (h4 == MAXCOL || h4 + h3 + h2 > min_height || h3 + h2 + h1 > min_height) |
7 | 2649 *lp = loff1; /* 1 line overlap */ |
2650 else | |
2651 *lp = loff2; /* 2 lines overlap */ | |
2652 return; | |
2653 } | |
2654 | |
2655 /* | |
2656 * Scroll 'scroll' lines up or down. | |
2657 */ | |
2658 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2659 halfpage(int flag, linenr_T Prenum) |
7 | 2660 { |
2661 long scrolled = 0; | |
2662 int i; | |
2663 int n; | |
2664 int room; | |
2665 | |
2666 if (Prenum) | |
2667 curwin->w_p_scr = (Prenum > curwin->w_height) ? | |
2668 curwin->w_height : Prenum; | |
2669 n = (curwin->w_p_scr <= curwin->w_height) ? | |
2670 curwin->w_p_scr : curwin->w_height; | |
2671 | |
11258
84f71a8a5f2c
patch 8.0.0515: ml_get errors in silent Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2672 update_topline(); |
7 | 2673 validate_botline(); |
2674 room = curwin->w_empty_rows; | |
2675 #ifdef FEAT_DIFF | |
2676 room += curwin->w_filler_rows; | |
2677 #endif | |
2678 if (flag) | |
2679 { | |
2680 /* | |
2681 * scroll the text up | |
2682 */ | |
2683 while (n > 0 && curwin->w_botline <= curbuf->b_ml.ml_line_count) | |
2684 { | |
2685 #ifdef FEAT_DIFF | |
2686 if (curwin->w_topfill > 0) | |
2687 { | |
2688 i = 1; | |
2689 if (--n < 0 && scrolled > 0) | |
2690 break; | |
2691 --curwin->w_topfill; | |
2692 } | |
2693 else | |
2694 #endif | |
2695 { | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
2696 i = PLINES_NOFILL(curwin->w_topline); |
7 | 2697 n -= i; |
2698 if (n < 0 && scrolled > 0) | |
2699 break; | |
2700 #ifdef FEAT_FOLDING | |
2701 (void)hasFolding(curwin->w_topline, NULL, &curwin->w_topline); | |
2702 #endif | |
2703 ++curwin->w_topline; | |
2704 #ifdef FEAT_DIFF | |
2705 curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline); | |
2706 #endif | |
2707 | |
2708 if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
2709 { | |
2710 ++curwin->w_cursor.lnum; | |
2711 curwin->w_valid &= | |
2712 ~(VALID_VIRTCOL|VALID_CHEIGHT|VALID_WCOL); | |
2713 } | |
2714 } | |
2715 curwin->w_valid &= ~(VALID_CROW|VALID_WROW); | |
2716 scrolled += i; | |
2717 | |
2718 /* | |
2719 * Correct w_botline for changed w_topline. | |
2720 * Won't work when there are filler lines. | |
2721 */ | |
2722 #ifdef FEAT_DIFF | |
2723 if (curwin->w_p_diff) | |
2724 curwin->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP); | |
2725 else | |
2726 #endif | |
2727 { | |
2728 room += i; | |
2729 do | |
2730 { | |
2731 i = plines(curwin->w_botline); | |
2732 if (i > room) | |
2733 break; | |
2734 #ifdef FEAT_FOLDING | |
2735 (void)hasFolding(curwin->w_botline, NULL, | |
2736 &curwin->w_botline); | |
2737 #endif | |
2738 ++curwin->w_botline; | |
2739 room -= i; | |
2740 } while (curwin->w_botline <= curbuf->b_ml.ml_line_count); | |
2741 } | |
2742 } | |
2743 | |
2744 /* | |
2745 * When hit bottom of the file: move cursor down. | |
2746 */ | |
2747 if (n > 0) | |
2748 { | |
2749 # ifdef FEAT_FOLDING | |
2750 if (hasAnyFolding(curwin)) | |
2751 { | |
2752 while (--n >= 0 | |
2753 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
2754 { | |
2755 (void)hasFolding(curwin->w_cursor.lnum, NULL, | |
2756 &curwin->w_cursor.lnum); | |
2757 ++curwin->w_cursor.lnum; | |
2758 } | |
2759 } | |
2760 else | |
2761 # endif | |
2762 curwin->w_cursor.lnum += n; | |
2763 check_cursor_lnum(); | |
2764 } | |
2765 } | |
2766 else | |
2767 { | |
2768 /* | |
2769 * scroll the text down | |
2770 */ | |
2771 while (n > 0 && curwin->w_topline > 1) | |
2772 { | |
2773 #ifdef FEAT_DIFF | |
2774 if (curwin->w_topfill < diff_check_fill(curwin, curwin->w_topline)) | |
2775 { | |
2776 i = 1; | |
16042
7952be788a49
patch 8.1.1026: unused condition
Bram Moolenaar <Bram@vim.org>
parents:
15713
diff
changeset
|
2777 --n; |
7 | 2778 ++curwin->w_topfill; |
2779 } | |
2780 else | |
2781 #endif | |
2782 { | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
2783 i = PLINES_NOFILL(curwin->w_topline - 1); |
7 | 2784 n -= i; |
2785 if (n < 0 && scrolled > 0) | |
2786 break; | |
2787 --curwin->w_topline; | |
2788 #ifdef FEAT_FOLDING | |
2789 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); | |
2790 #endif | |
2791 #ifdef FEAT_DIFF | |
2792 curwin->w_topfill = 0; | |
2793 #endif | |
2794 } | |
2795 curwin->w_valid &= ~(VALID_CROW|VALID_WROW| | |
2796 VALID_BOTLINE|VALID_BOTLINE_AP); | |
2797 scrolled += i; | |
2798 if (curwin->w_cursor.lnum > 1) | |
2799 { | |
2800 --curwin->w_cursor.lnum; | |
2801 curwin->w_valid &= ~(VALID_VIRTCOL|VALID_CHEIGHT|VALID_WCOL); | |
2802 } | |
2803 } | |
16042
7952be788a49
patch 8.1.1026: unused condition
Bram Moolenaar <Bram@vim.org>
parents:
15713
diff
changeset
|
2804 |
7 | 2805 /* |
2806 * When hit top of the file: move cursor up. | |
2807 */ | |
2808 if (n > 0) | |
2809 { | |
2810 if (curwin->w_cursor.lnum <= (linenr_T)n) | |
2811 curwin->w_cursor.lnum = 1; | |
2812 else | |
2813 # ifdef FEAT_FOLDING | |
2814 if (hasAnyFolding(curwin)) | |
2815 { | |
2816 while (--n >= 0 && curwin->w_cursor.lnum > 1) | |
2817 { | |
2818 --curwin->w_cursor.lnum; | |
2819 (void)hasFolding(curwin->w_cursor.lnum, | |
2820 &curwin->w_cursor.lnum, NULL); | |
2821 } | |
2822 } | |
2823 else | |
2824 # endif | |
2825 curwin->w_cursor.lnum -= n; | |
2826 } | |
2827 } | |
2828 # ifdef FEAT_FOLDING | |
2829 /* Move cursor to first line of closed fold. */ | |
2830 foldAdjustCursor(); | |
2831 # endif | |
2832 #ifdef FEAT_DIFF | |
2833 check_topfill(curwin, !flag); | |
2834 #endif | |
2835 cursor_correct(); | |
2836 beginline(BL_SOL | BL_FIX); | |
2837 redraw_later(VALID); | |
2838 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2839 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2840 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2841 do_check_cursorbind(void) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2842 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2843 linenr_T line = curwin->w_cursor.lnum; |
3415 | 2844 colnr_T col = curwin->w_cursor.col; |
2845 colnr_T coladd = curwin->w_cursor.coladd; | |
3433 | 2846 colnr_T curswant = curwin->w_curswant; |
2847 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
|
2848 win_T *old_curwin = curwin; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2849 buf_T *old_curbuf = curbuf; |
2693 | 2850 int restart_edit_save; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2851 int old_VIsual_select = VIsual_select; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2852 int old_VIsual_active = VIsual_active; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2853 |
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 * loop through the cursorbound windows |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2856 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2857 VIsual_select = VIsual_active = 0; |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2858 FOR_ALL_WINDOWS(curwin) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2859 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2860 curbuf = curwin->w_buffer; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2861 /* skip original window and windows with 'noscrollbind' */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2862 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
|
2863 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2864 # ifdef FEAT_DIFF |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2865 if (curwin->w_p_diff) |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10102
diff
changeset
|
2866 curwin->w_cursor.lnum = |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10102
diff
changeset
|
2867 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
|
2868 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2869 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2870 curwin->w_cursor.lnum = line; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2871 curwin->w_cursor.col = col; |
3415 | 2872 curwin->w_cursor.coladd = coladd; |
3433 | 2873 curwin->w_curswant = curswant; |
2874 curwin->w_set_curswant = set_curswant; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2875 |
2693 | 2876 /* Make sure the cursor is in a valid position. Temporarily set |
2877 * "restart_edit" to allow the cursor to be beyond the EOL. */ | |
2878 restart_edit_save = restart_edit; | |
2879 restart_edit = TRUE; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2880 check_cursor(); |
10607
e39300d3d2cf
patch 8.0.0193: accidentally removed #ifdef
Christian Brabandt <cb@256bit.org>
parents:
10597
diff
changeset
|
2881 # ifdef FEAT_SYN_HL |
10597
472bff31a20a
patch 8.0.0188: redrawing for 'cursorbind' is inefficient
Christian Brabandt <cb@256bit.org>
parents:
10585
diff
changeset
|
2882 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
|
2883 validate_cursor(); |
10607
e39300d3d2cf
patch 8.0.0193: accidentally removed #ifdef
Christian Brabandt <cb@256bit.org>
parents:
10597
diff
changeset
|
2884 # endif |
2693 | 2885 restart_edit = restart_edit_save; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2886 /* Correct cursor for multi-byte character. */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2887 if (has_mbyte) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2888 mb_adjust_cursor(); |
10597
472bff31a20a
patch 8.0.0188: redrawing for 'cursorbind' is inefficient
Christian Brabandt <cb@256bit.org>
parents:
10585
diff
changeset
|
2889 redraw_later(VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2890 |
2688 | 2891 /* Only scroll when 'scrollbind' hasn't done this. */ |
2892 if (!curwin->w_p_scb) | |
2893 update_topline(); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2894 curwin->w_redr_status = TRUE; |
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 |
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 * reset current-window |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2900 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2901 VIsual_select = old_VIsual_select; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2902 VIsual_active = old_VIsual_active; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2903 curwin = old_curwin; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2904 curbuf = old_curbuf; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2905 } |