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