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