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