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