Mercurial > vim
annotate src/move.c @ 22886:38324d4f1c94 v8.2.1990
patch 8.2.1990: cursor position wrong in terminal popup with finished job
Commit: https://github.com/vim/vim/commit/6a07644db30cb5f3d0c6dc5eb2c348b6289da553
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Nov 15 20:32:58 2020 +0100
patch 8.2.1990: cursor position wrong in terminal popup with finished job
Problem: Cursor position wrong in terminal popup with finished job.
Solution: Only add the top and left offset when not done already.
(closes #7298)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 15 Nov 2020 20:45:03 +0100 |
parents | 53b996eb5e76 |
children | 255473b88c8e |
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; |
22886
38324d4f1c94
patch 8.2.1990: cursor position wrong in terminal popup with finished job
Bram Moolenaar <Bram@vim.org>
parents:
22782
diff
changeset
|
871 curwin->w_flags &= ~WFLAG_WCOL_OFF_ADDED; |
7 | 872 } |
873 } | |
874 | |
875 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
876 * 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
|
877 * fold column and sign column (these don't move when scrolling horizontally). |
7 | 878 */ |
879 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
880 win_col_off(win_T *wp) |
7 | 881 { |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
882 return (((wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) + 1 : 0) |
7 | 883 #ifdef FEAT_CMDWIN |
884 + (cmdwin_type == 0 || wp != curwin ? 0 : 1) | |
885 #endif | |
886 #ifdef FEAT_FOLDING | |
887 + wp->w_p_fdc | |
888 #endif | |
889 #ifdef FEAT_SIGNS | |
9852
4eea48b76d03
commit https://github.com/vim/vim/commit/95ec9d6a6ab3117d60ff638670a803d43974ba51
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
890 + (signcolumn_on(wp) ? 2 : 0) |
7 | 891 #endif |
892 ); | |
893 } | |
894 | |
895 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
896 curwin_col_off(void) |
7 | 897 { |
898 return win_col_off(curwin); | |
899 } | |
900 | |
901 /* | |
902 * 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
|
903 * 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
|
904 * 'cpoptions'. |
7 | 905 */ |
906 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
907 win_col_off2(win_T *wp) |
7 | 908 { |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
909 if ((wp->w_p_nu || wp->w_p_rnu) && vim_strchr(p_cpo, CPO_NUMCOL) != NULL) |
13 | 910 return number_width(wp) + 1; |
7 | 911 return 0; |
912 } | |
913 | |
914 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
915 curwin_col_off2(void) |
7 | 916 { |
917 return win_col_off2(curwin); | |
918 } | |
919 | |
920 /* | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15414
diff
changeset
|
921 * Compute curwin->w_wcol and curwin->w_virtcol. |
7 | 922 * Also updates curwin->w_wrow and curwin->w_cline_row. |
923 * Also updates curwin->w_leftcol. | |
924 */ | |
925 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
926 curs_columns( |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
927 int may_scroll) // when TRUE, may scroll horizontally |
7 | 928 { |
929 int diff; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
930 int extra; // offset for first screen line |
7 | 931 int off_left, off_right; |
932 int n; | |
933 int p_lines; | |
934 int width = 0; | |
935 int textwidth; | |
936 int new_leftcol; | |
937 colnr_T startcol; | |
938 colnr_T endcol; | |
939 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
|
940 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
|
941 long siso = get_sidescrolloff_value(); |
7 | 942 |
943 /* | |
944 * First make sure that w_topline is valid (after moving the cursor). | |
945 */ | |
946 update_topline(); | |
947 | |
948 /* | |
949 * Next make sure that w_cline_row is valid. | |
950 */ | |
951 if (!(curwin->w_valid & VALID_CROW)) | |
6441 | 952 curs_rows(curwin); |
7 | 953 |
954 /* | |
955 * Compute the number of virtual columns. | |
956 */ | |
957 #ifdef FEAT_FOLDING | |
958 if (curwin->w_cline_folded) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
959 // In a folded line the cursor is always in the first column |
7 | 960 startcol = curwin->w_virtcol = endcol = curwin->w_leftcol; |
961 else | |
962 #endif | |
963 getvvcol(curwin, &curwin->w_cursor, | |
964 &startcol, &(curwin->w_virtcol), &endcol); | |
965 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
966 // remove '$' from change command when cursor moves onto it |
7 | 967 if (startcol > dollar_vcol) |
3318 | 968 dollar_vcol = -1; |
7 | 969 |
970 extra = curwin_col_off(); | |
971 curwin->w_wcol = curwin->w_virtcol + extra; | |
972 endcol += extra; | |
973 | |
974 /* | |
975 * Now compute w_wrow, counting screen lines from w_cline_row. | |
976 */ | |
977 curwin->w_wrow = curwin->w_cline_row; | |
978 | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
979 textwidth = curwin->w_width - extra; |
7 | 980 if (textwidth <= 0) |
981 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
982 // 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
|
983 curwin->w_wcol = curwin->w_width - 1; |
7 | 984 curwin->w_wrow = curwin->w_height - 1; |
985 } | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
986 else if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 987 { |
988 width = textwidth + curwin_col_off2(); | |
989 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
990 // 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
|
991 if (curwin->w_wcol >= curwin->w_width) |
7 | 992 { |
18580
4ac042c8ed98
patch 8.1.2284: compiler warning for unused variable
Bram Moolenaar <Bram@vim.org>
parents:
18574
diff
changeset
|
993 #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
|
994 char_u *sbr; |
18580
4ac042c8ed98
patch 8.1.2284: compiler warning for unused variable
Bram Moolenaar <Bram@vim.org>
parents:
18574
diff
changeset
|
995 #endif |
18574
8b0114ffde2b
patch 8.1.2281: 'showbreak' cannot be set for one window
Bram Moolenaar <Bram@vim.org>
parents:
18469
diff
changeset
|
996 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
997 // this same formula is used in validate_cursor_col() |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
998 n = (curwin->w_wcol - curwin->w_width) / width + 1; |
7 | 999 curwin->w_wcol -= n * width; |
1000 curwin->w_wrow += n; | |
1001 | |
1002 #ifdef FEAT_LINEBREAK | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1003 // 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
|
1004 // 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
|
1005 // column |
18574
8b0114ffde2b
patch 8.1.2281: 'showbreak' cannot be set for one window
Bram Moolenaar <Bram@vim.org>
parents:
18469
diff
changeset
|
1006 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
|
1007 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
|
1008 && curwin->w_wcol == (int)vim_strsize(sbr)) |
7 | 1009 curwin->w_wcol = 0; |
1010 #endif | |
1011 } | |
1012 } | |
1013 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1014 // 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
|
1015 // is not folded. |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1016 // If scrolling is off, curwin->w_leftcol is assumed to be 0 |
3263 | 1017 else if (may_scroll |
7 | 1018 #ifdef FEAT_FOLDING |
1019 && !curwin->w_cline_folded | |
1020 #endif | |
1021 ) | |
1022 { | |
1023 /* | |
1024 * If Cursor is left of the screen, scroll rightwards. | |
1025 * If Cursor is right of the screen, scroll leftwards | |
1026 * If we get closer to the edge than 'sidescrolloff', scroll a little | |
1027 * extra | |
1028 */ | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
1029 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
|
1030 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
|
1031 - siso) + 1; |
7 | 1032 if (off_left < 0 || off_right > 0) |
1033 { | |
1034 if (off_left < 0) | |
1035 diff = -off_left; | |
1036 else | |
1037 diff = off_right; | |
1038 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1039 // 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
|
1040 // middle of window. |
7 | 1041 if (p_ss == 0 || diff >= textwidth / 2 || off_right >= off_left) |
1042 new_leftcol = curwin->w_wcol - extra - textwidth / 2; | |
1043 else | |
1044 { | |
1045 if (diff < p_ss) | |
1046 diff = p_ss; | |
1047 if (off_left < 0) | |
1048 new_leftcol = curwin->w_leftcol - diff; | |
1049 else | |
1050 new_leftcol = curwin->w_leftcol + diff; | |
1051 } | |
1052 if (new_leftcol < 0) | |
1053 new_leftcol = 0; | |
1054 if (new_leftcol != (int)curwin->w_leftcol) | |
1055 { | |
1056 curwin->w_leftcol = new_leftcol; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1057 // screen has to be redrawn with new curwin->w_leftcol |
7 | 1058 redraw_later(NOT_VALID); |
1059 } | |
1060 } | |
1061 curwin->w_wcol -= curwin->w_leftcol; | |
1062 } | |
1063 else if (curwin->w_wcol > (int)curwin->w_leftcol) | |
1064 curwin->w_wcol -= curwin->w_leftcol; | |
1065 else | |
1066 curwin->w_wcol = 0; | |
1067 | |
1068 #ifdef FEAT_DIFF | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1069 // 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
|
1070 // may be some filler lines above the window. |
7 | 1071 if (curwin->w_cursor.lnum == curwin->w_topline) |
1072 curwin->w_wrow += curwin->w_topfill; | |
1073 else | |
1074 curwin->w_wrow += diff_check_fill(curwin, curwin->w_cursor.lnum); | |
1075 #endif | |
1076 | |
1077 prev_skipcol = curwin->w_skipcol; | |
1078 | |
1079 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
|
1080 |
7 | 1081 if ((curwin->w_wrow >= curwin->w_height |
1082 || ((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
|
1083 || curwin->w_wrow + so >= curwin->w_height) |
7 | 1084 && (p_lines = |
1085 #ifdef FEAT_DIFF | |
1086 plines_win_nofill | |
1087 #else | |
1088 plines_win | |
1089 #endif | |
1090 (curwin, curwin->w_cursor.lnum, FALSE)) | |
1091 - 1 >= curwin->w_height)) | |
1092 && curwin->w_height != 0 | |
1093 && curwin->w_cursor.lnum == curwin->w_topline | |
1094 && width > 0 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
1095 && curwin->w_width != 0) |
7 | 1096 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1097 // 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
|
1098 // 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
|
1099 // 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
|
1100 // 1: Less than 'scrolloff' lines above |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1101 // 2: Less than 'scrolloff' lines below |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1102 // 3: both of them |
7 | 1103 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
|
1104 if (curwin->w_skipcol + so * width > curwin->w_virtcol) |
7 | 1105 extra = 1; |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1106 // 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
|
1107 // bottom of the window. |
7 | 1108 if (p_lines == 0) |
1109 p_lines = plines_win(curwin, curwin->w_cursor.lnum, FALSE); | |
1110 --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
|
1111 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
|
1112 n = curwin->w_wrow + so; |
7 | 1113 else |
1114 n = p_lines; | |
1115 if ((colnr_T)n >= curwin->w_height + curwin->w_skipcol / width) | |
1116 extra += 2; | |
1117 | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
1118 if (extra == 3 || p_lines < so * 2) |
7 | 1119 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1120 // not enough room for 'scrolloff', put cursor in the middle |
7 | 1121 n = curwin->w_virtcol / width; |
1122 if (n > curwin->w_height / 2) | |
1123 n -= curwin->w_height / 2; | |
1124 else | |
1125 n = 0; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1126 // don't skip more than necessary |
7 | 1127 if (n > p_lines - curwin->w_height + 1) |
1128 n = p_lines - curwin->w_height + 1; | |
1129 curwin->w_skipcol = n * width; | |
1130 } | |
1131 else if (extra == 1) | |
1132 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1133 // 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
|
1134 extra = (curwin->w_skipcol + so * width - curwin->w_virtcol |
7 | 1135 + width - 1) / width; |
1136 if (extra > 0) | |
1137 { | |
1138 if ((colnr_T)(extra * width) > curwin->w_skipcol) | |
1139 extra = curwin->w_skipcol / width; | |
1140 curwin->w_skipcol -= extra * width; | |
1141 } | |
1142 } | |
1143 else if (extra == 2) | |
1144 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1145 // less then 'scrolloff' lines below, increase skipcol |
7 | 1146 endcol = (n - curwin->w_height + 1) * width; |
1147 while (endcol > curwin->w_virtcol) | |
1148 endcol -= width; | |
1149 if (endcol > curwin->w_skipcol) | |
1150 curwin->w_skipcol = endcol; | |
1151 } | |
1152 | |
1153 curwin->w_wrow -= curwin->w_skipcol / width; | |
1154 if (curwin->w_wrow >= curwin->w_height) | |
1155 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1156 // small window, make sure cursor is in it |
7 | 1157 extra = curwin->w_wrow - curwin->w_height + 1; |
1158 curwin->w_skipcol += extra * width; | |
1159 curwin->w_wrow -= extra; | |
1160 } | |
1161 | |
1162 extra = ((int)prev_skipcol - (int)curwin->w_skipcol) / width; | |
1163 if (extra > 0) | |
1164 win_ins_lines(curwin, 0, extra, FALSE, FALSE); | |
1165 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
|
1166 win_del_lines(curwin, 0, -extra, FALSE, FALSE, 0); |
7 | 1167 } |
1168 else | |
1169 curwin->w_skipcol = 0; | |
1170 if (prev_skipcol != curwin->w_skipcol) | |
1171 redraw_later(NOT_VALID); | |
1172 | |
740 | 1173 #ifdef FEAT_SYN_HL |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1174 // Redraw when w_virtcol changes and 'cursorcolumn' is set |
5749 | 1175 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
|
1176 && !pum_visible()) |
5749 | 1177 redraw_later(SOME_VALID); |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1178 #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
|
1179 #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
|
1180 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
|
1181 { |
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 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
|
1183 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
|
1184 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
|
1185 } |
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 else |
38324d4f1c94
patch 8.2.1990: cursor position wrong in terminal popup with finished job
Bram Moolenaar <Bram@vim.org>
parents:
22782
diff
changeset
|
1187 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
|
1188 #endif |
740 | 1189 |
18621
a9bfdc5ea1ec
patch 8.1.2303: cursor in wrong position after horizontal scroll
Bram Moolenaar <Bram@vim.org>
parents:
18580
diff
changeset
|
1190 // 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
|
1191 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
|
1192 |
7 | 1193 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL; |
1194 } | |
1195 | |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18621
diff
changeset
|
1196 #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
|
1197 /* |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1198 * 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
|
1199 * 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
|
1200 */ |
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
|
1201 void |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1202 textpos2screenpos( |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1203 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
|
1204 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
|
1205 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
|
1206 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
|
1207 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
|
1208 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
|
1209 { |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1210 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
|
1211 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
|
1212 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
|
1213 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
|
1214 |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1215 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
|
1216 { |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1217 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
|
1218 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
|
1219 int width; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1220 |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1221 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
|
1222 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
|
1223 |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1224 // 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
|
1225 col = scol; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1226 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
|
1227 col += off; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1228 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
|
1229 |
17863
08f1dd29550e
patch 8.1.1928: popup windows don't move with the text when making changes
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1230 // 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
|
1231 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
|
1232 && 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
|
1233 && width > 0) |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1234 { |
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
|
1235 // 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
|
1236 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
|
1237 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
|
1238 } |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1239 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
|
1240 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
|
1241 col = -1; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1242 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
|
1243 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
|
1244 else |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1245 // 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
|
1246 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
|
1247 } |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1248 *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
|
1249 *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
|
1250 *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
|
1251 *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
|
1252 } |
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
|
1253 #endif |
17292
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 #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
|
1256 /* |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1257 * "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
|
1258 */ |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1259 void |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1260 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
|
1261 { |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1262 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
|
1263 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
|
1264 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
|
1265 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
|
1266 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
|
1267 |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1268 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
|
1269 return; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1270 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
|
1271 |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1272 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
|
1273 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
|
1274 return; |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1275 |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1276 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
|
1277 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
|
1278 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
|
1279 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
|
1280 |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1281 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
|
1282 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
|
1283 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
|
1284 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
|
1285 } |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1286 #endif |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1287 |
7 | 1288 /* |
1289 * Scroll the current window down by "line_count" logical lines. "CTRL-Y" | |
1290 */ | |
1291 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1292 scrolldown( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1293 long line_count, |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1294 int byfold UNUSED) // TRUE: count a closed fold as one line |
7 | 1295 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1296 long done = 0; // total # of physical lines done |
7 | 1297 int wrow; |
1298 int moved = FALSE; | |
1299 | |
1300 #ifdef FEAT_FOLDING | |
1301 linenr_T first; | |
1302 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1303 // Make sure w_topline is at the first of a sequence of folded lines. |
7 | 1304 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
1305 #endif | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1306 validate_cursor(); // w_wrow needs to be valid |
7 | 1307 while (line_count-- > 0) |
1308 { | |
1309 #ifdef FEAT_DIFF | |
1980 | 1310 if (curwin->w_topfill < diff_check(curwin, curwin->w_topline) |
1311 && curwin->w_topfill < curwin->w_height - 1) | |
7 | 1312 { |
1313 ++curwin->w_topfill; | |
1314 ++done; | |
1315 } | |
1316 else | |
1317 #endif | |
1318 { | |
1319 if (curwin->w_topline == 1) | |
1320 break; | |
1321 --curwin->w_topline; | |
1322 #ifdef FEAT_DIFF | |
1323 curwin->w_topfill = 0; | |
1324 #endif | |
1325 #ifdef FEAT_FOLDING | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1326 // A sequence of folded lines only counts for one logical line |
7 | 1327 if (hasFolding(curwin->w_topline, &first, NULL)) |
1328 { | |
1329 ++done; | |
1330 if (!byfold) | |
1331 line_count -= curwin->w_topline - first - 1; | |
1332 curwin->w_botline -= curwin->w_topline - first; | |
1333 curwin->w_topline = first; | |
1334 } | |
1335 else | |
1336 #endif | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
1337 done += PLINES_NOFILL(curwin->w_topline); |
7 | 1338 } |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1339 --curwin->w_botline; // approximate w_botline |
7 | 1340 invalidate_botline(); |
1341 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1342 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
|
1343 curwin->w_cline_row += done; // keep w_cline_row updated |
7 | 1344 |
1345 #ifdef FEAT_DIFF | |
1346 if (curwin->w_cursor.lnum == curwin->w_topline) | |
1347 curwin->w_cline_row = 0; | |
1348 check_topfill(curwin, TRUE); | |
1349 #endif | |
1350 | |
1351 /* | |
1352 * Compute the row number of the last row of the cursor line | |
1353 * and move the cursor onto the displayed part of the window. | |
1354 */ | |
1355 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
|
1356 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 1357 { |
1358 validate_virtcol(); | |
1359 validate_cheight(); | |
1360 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
|
1361 curwin->w_virtcol / curwin->w_width; |
7 | 1362 } |
1363 while (wrow >= curwin->w_height && curwin->w_cursor.lnum > 1) | |
1364 { | |
1365 #ifdef FEAT_FOLDING | |
1366 if (hasFolding(curwin->w_cursor.lnum, &first, NULL)) | |
1367 { | |
1368 --wrow; | |
1369 if (first == 1) | |
1370 curwin->w_cursor.lnum = 1; | |
1371 else | |
1372 curwin->w_cursor.lnum = first - 1; | |
1373 } | |
1374 else | |
1375 #endif | |
1376 wrow -= plines(curwin->w_cursor.lnum--); | |
1377 curwin->w_valid &= | |
1378 ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL); | |
1379 moved = TRUE; | |
1380 } | |
1381 if (moved) | |
1382 { | |
1383 #ifdef FEAT_FOLDING | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1384 // Move cursor to first line of closed fold. |
7 | 1385 foldAdjustCursor(); |
1386 #endif | |
1387 coladvance(curwin->w_curswant); | |
1388 } | |
1389 } | |
1390 | |
1391 /* | |
1392 * Scroll the current window up by "line_count" logical lines. "CTRL-E" | |
1393 */ | |
1394 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1395 scrollup( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1396 long line_count, |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1397 int byfold UNUSED) // TRUE: count a closed fold as one line |
7 | 1398 { |
1399 #if defined(FEAT_FOLDING) || defined(FEAT_DIFF) | |
1400 linenr_T lnum; | |
1401 | |
1402 if ( | |
1403 # ifdef FEAT_FOLDING | |
1404 (byfold && hasAnyFolding(curwin)) | |
1405 # ifdef FEAT_DIFF | |
1406 || | |
1407 # endif | |
1408 # endif | |
1409 # ifdef FEAT_DIFF | |
1410 curwin->w_p_diff | |
1411 # endif | |
1412 ) | |
1413 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1414 // count each sequence of folded lines as one logical line |
7 | 1415 lnum = curwin->w_topline; |
1416 while (line_count--) | |
1417 { | |
1418 # ifdef FEAT_DIFF | |
1419 if (curwin->w_topfill > 0) | |
1420 --curwin->w_topfill; | |
1421 else | |
1422 # endif | |
1423 { | |
1424 # ifdef FEAT_FOLDING | |
1425 if (byfold) | |
1426 (void)hasFolding(lnum, NULL, &lnum); | |
1427 # endif | |
1428 if (lnum >= curbuf->b_ml.ml_line_count) | |
1429 break; | |
1430 ++lnum; | |
1431 # ifdef FEAT_DIFF | |
1432 curwin->w_topfill = diff_check_fill(curwin, lnum); | |
1433 # endif | |
1434 } | |
1435 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1436 // approximate w_botline |
7 | 1437 curwin->w_botline += lnum - curwin->w_topline; |
1438 curwin->w_topline = lnum; | |
1439 } | |
1440 else | |
1441 #endif | |
1442 { | |
1443 curwin->w_topline += line_count; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1444 curwin->w_botline += line_count; // approximate w_botline |
7 | 1445 } |
1446 | |
1447 if (curwin->w_topline > curbuf->b_ml.ml_line_count) | |
1448 curwin->w_topline = curbuf->b_ml.ml_line_count; | |
1449 if (curwin->w_botline > curbuf->b_ml.ml_line_count + 1) | |
1450 curwin->w_botline = curbuf->b_ml.ml_line_count + 1; | |
1451 | |
1452 #ifdef FEAT_DIFF | |
1453 check_topfill(curwin, FALSE); | |
1454 #endif | |
1455 | |
1456 #ifdef FEAT_FOLDING | |
1457 if (hasAnyFolding(curwin)) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1458 // Make sure w_topline is at the first of a sequence of folded lines. |
7 | 1459 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
1460 #endif | |
1461 | |
1462 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); | |
1463 if (curwin->w_cursor.lnum < curwin->w_topline) | |
1464 { | |
1465 curwin->w_cursor.lnum = curwin->w_topline; | |
1466 curwin->w_valid &= | |
1467 ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL); | |
1468 coladvance(curwin->w_curswant); | |
1469 } | |
1470 } | |
1471 | |
1472 #ifdef FEAT_DIFF | |
1473 /* | |
1474 * Don't end up with too many filler lines in the window. | |
1475 */ | |
1476 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1477 check_topfill( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1478 win_T *wp, |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1479 int down) // when TRUE scroll down when not enough space |
7 | 1480 { |
1481 int n; | |
1482 | |
1483 if (wp->w_topfill > 0) | |
1484 { | |
1485 n = plines_win_nofill(wp, wp->w_topline, TRUE); | |
1486 if (wp->w_topfill + n > wp->w_height) | |
1487 { | |
1488 if (down && wp->w_topline > 1) | |
1489 { | |
1490 --wp->w_topline; | |
1491 wp->w_topfill = 0; | |
1492 } | |
1493 else | |
1494 { | |
1495 wp->w_topfill = wp->w_height - n; | |
1496 if (wp->w_topfill < 0) | |
1497 wp->w_topfill = 0; | |
1498 } | |
1499 } | |
1500 } | |
1501 } | |
1502 | |
1503 /* | |
1504 * Use as many filler lines as possible for w_topline. Make sure w_topline | |
1505 * is still visible. | |
1506 */ | |
1507 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1508 max_topfill(void) |
7 | 1509 { |
1510 int n; | |
1511 | |
1512 n = plines_nofill(curwin->w_topline); | |
1513 if (n >= curwin->w_height) | |
1514 curwin->w_topfill = 0; | |
1515 else | |
1516 { | |
1517 curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline); | |
1518 if (curwin->w_topfill + n > curwin->w_height) | |
1519 curwin->w_topfill = curwin->w_height - n; | |
1520 } | |
1521 } | |
1522 #endif | |
1523 | |
1524 /* | |
1525 * Scroll the screen one line down, but don't do it if it would move the | |
1526 * cursor off the screen. | |
1527 */ | |
1528 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1529 scrolldown_clamp(void) |
7 | 1530 { |
1531 int end_row; | |
1532 #ifdef FEAT_DIFF | |
1533 int can_fill = (curwin->w_topfill | |
1534 < diff_check_fill(curwin, curwin->w_topline)); | |
1535 #endif | |
1536 | |
1537 if (curwin->w_topline <= 1 | |
1538 #ifdef FEAT_DIFF | |
1539 && !can_fill | |
1540 #endif | |
1541 ) | |
1542 return; | |
1543 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1544 validate_cursor(); // w_wrow needs to be valid |
7 | 1545 |
1546 /* | |
1547 * Compute the row number of the last row of the cursor line | |
1548 * and make sure it doesn't go off the screen. Make sure the cursor | |
1549 * doesn't go past 'scrolloff' lines from the screen end. | |
1550 */ | |
1551 end_row = curwin->w_wrow; | |
1552 #ifdef FEAT_DIFF | |
1553 if (can_fill) | |
1554 ++end_row; | |
1555 else | |
1556 end_row += plines_nofill(curwin->w_topline - 1); | |
1557 #else | |
1558 end_row += plines(curwin->w_topline - 1); | |
1559 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
1560 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 1561 { |
1562 validate_cheight(); | |
1563 validate_virtcol(); | |
1564 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
|
1565 curwin->w_virtcol / curwin->w_width; |
7 | 1566 } |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
1567 if (end_row < curwin->w_height - get_scrolloff_value()) |
7 | 1568 { |
1569 #ifdef FEAT_DIFF | |
1570 if (can_fill) | |
1571 { | |
1572 ++curwin->w_topfill; | |
1573 check_topfill(curwin, TRUE); | |
1574 } | |
1575 else | |
1576 { | |
1577 --curwin->w_topline; | |
1578 curwin->w_topfill = 0; | |
1579 } | |
1580 #else | |
1581 --curwin->w_topline; | |
1582 #endif | |
1583 #ifdef FEAT_FOLDING | |
7009 | 1584 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
7 | 1585 #endif |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1586 --curwin->w_botline; // approximate w_botline |
7 | 1587 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); |
1588 } | |
1589 } | |
1590 | |
1591 /* | |
1592 * Scroll the screen one line up, but don't do it if it would move the cursor | |
1593 * off the screen. | |
1594 */ | |
1595 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1596 scrollup_clamp(void) |
7 | 1597 { |
1598 int start_row; | |
1599 | |
1600 if (curwin->w_topline == curbuf->b_ml.ml_line_count | |
1601 #ifdef FEAT_DIFF | |
1602 && curwin->w_topfill == 0 | |
1603 #endif | |
1604 ) | |
1605 return; | |
1606 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1607 validate_cursor(); // w_wrow needs to be valid |
7 | 1608 |
1609 /* | |
1610 * Compute the row number of the first row of the cursor line | |
1611 * and make sure it doesn't go off the screen. Make sure the cursor | |
1612 * doesn't go before 'scrolloff' lines from the screen start. | |
1613 */ | |
1614 #ifdef FEAT_DIFF | |
1615 start_row = curwin->w_wrow - plines_nofill(curwin->w_topline) | |
1616 - curwin->w_topfill; | |
1617 #else | |
1618 start_row = curwin->w_wrow - plines(curwin->w_topline); | |
1619 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
1620 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 1621 { |
1622 validate_virtcol(); | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1623 start_row -= curwin->w_virtcol / curwin->w_width; |
7 | 1624 } |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
1625 if (start_row >= get_scrolloff_value()) |
7 | 1626 { |
1627 #ifdef FEAT_DIFF | |
1628 if (curwin->w_topfill > 0) | |
1629 --curwin->w_topfill; | |
1630 else | |
1631 #endif | |
36 | 1632 { |
1633 #ifdef FEAT_FOLDING | |
1634 (void)hasFolding(curwin->w_topline, NULL, &curwin->w_topline); | |
1635 #endif | |
7 | 1636 ++curwin->w_topline; |
36 | 1637 } |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1638 ++curwin->w_botline; // approximate w_botline |
7 | 1639 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); |
1640 } | |
1641 } | |
1642 | |
1643 /* | |
1644 * Add one line above "lp->lnum". This can be a filler line, a closed fold or | |
1645 * a (wrapped) text line. Uses and sets "lp->fill". | |
1646 * 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
|
1647 * Lines above the first one are incredibly high: MAXCOL. |
7 | 1648 */ |
1649 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1650 topline_back(lineoff_T *lp) |
7 | 1651 { |
1652 #ifdef FEAT_DIFF | |
1653 if (lp->fill < diff_check_fill(curwin, lp->lnum)) | |
1654 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1655 // Add a filler line. |
7 | 1656 ++lp->fill; |
1657 lp->height = 1; | |
1658 } | |
1659 else | |
1660 #endif | |
1661 { | |
1662 --lp->lnum; | |
1663 #ifdef FEAT_DIFF | |
1664 lp->fill = 0; | |
1665 #endif | |
1666 if (lp->lnum < 1) | |
1667 lp->height = MAXCOL; | |
1668 else | |
1669 #ifdef FEAT_FOLDING | |
1670 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
|
1671 // Add a closed fold |
7 | 1672 lp->height = 1; |
1673 else | |
1674 #endif | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
1675 lp->height = PLINES_NOFILL(lp->lnum); |
7 | 1676 } |
1677 } | |
1678 | |
1679 /* | |
1680 * Add one line below "lp->lnum". This can be a filler line, a closed fold or | |
1681 * a (wrapped) text line. Uses and sets "lp->fill". | |
1682 * Returns the height of the added line in "lp->height". | |
1683 * Lines below the last one are incredibly high. | |
1684 */ | |
1685 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1686 botline_forw(lineoff_T *lp) |
7 | 1687 { |
1688 #ifdef FEAT_DIFF | |
1689 if (lp->fill < diff_check_fill(curwin, lp->lnum + 1)) | |
1690 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1691 // Add a filler line. |
7 | 1692 ++lp->fill; |
1693 lp->height = 1; | |
1694 } | |
1695 else | |
1696 #endif | |
1697 { | |
1698 ++lp->lnum; | |
1699 #ifdef FEAT_DIFF | |
1700 lp->fill = 0; | |
1701 #endif | |
1702 if (lp->lnum > curbuf->b_ml.ml_line_count) | |
1703 lp->height = MAXCOL; | |
1704 else | |
1705 #ifdef FEAT_FOLDING | |
1706 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
|
1707 // Add a closed fold |
7 | 1708 lp->height = 1; |
1709 else | |
1710 #endif | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
1711 lp->height = PLINES_NOFILL(lp->lnum); |
7 | 1712 } |
1713 } | |
1714 | |
1715 #ifdef FEAT_DIFF | |
1716 /* | |
1717 * Switch from including filler lines below lp->lnum to including filler | |
1718 * lines above loff.lnum + 1. This keeps pointing to the same line. | |
1719 * When there are no filler lines nothing changes. | |
1720 */ | |
1721 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1722 botline_topline(lineoff_T *lp) |
7 | 1723 { |
1724 if (lp->fill > 0) | |
1725 { | |
1726 ++lp->lnum; | |
1727 lp->fill = diff_check_fill(curwin, lp->lnum) - lp->fill + 1; | |
1728 } | |
1729 } | |
1730 | |
1731 /* | |
1732 * Switch from including filler lines above lp->lnum to including filler | |
1733 * lines below loff.lnum - 1. This keeps pointing to the same line. | |
1734 * When there are no filler lines nothing changes. | |
1735 */ | |
1736 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1737 topline_botline(lineoff_T *lp) |
7 | 1738 { |
1739 if (lp->fill > 0) | |
1740 { | |
1741 lp->fill = diff_check_fill(curwin, lp->lnum) - lp->fill + 1; | |
1742 --lp->lnum; | |
1743 } | |
1744 } | |
1745 #endif | |
1746 | |
1747 /* | |
1748 * Recompute topline to put the cursor at the top of the window. | |
1749 * Scroll at least "min_scroll" lines. | |
1750 * If "always" is TRUE, always set topline (for "zt"). | |
1751 */ | |
1752 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1753 scroll_cursor_top(int min_scroll, int always) |
7 | 1754 { |
1755 int scrolled = 0; | |
1756 int extra = 0; | |
1757 int used; | |
1758 int i; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1759 linenr_T top; // just above displayed lines |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1760 linenr_T bot; // just below displayed lines |
7 | 1761 linenr_T old_topline = curwin->w_topline; |
1762 #ifdef FEAT_DIFF | |
1763 linenr_T old_topfill = curwin->w_topfill; | |
1764 #endif | |
1765 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
|
1766 int off = get_scrolloff_value(); |
7 | 1767 |
1768 if (mouse_dragging > 0) | |
1769 off = mouse_dragging - 1; | |
1770 | |
1771 /* | |
1772 * Decrease topline until: | |
1773 * - it has become 1 | |
1774 * - (part of) the cursor line is moved off the screen or | |
1775 * - moved at least 'scrolljump' lines and | |
1776 * - at least 'scrolloff' lines above and below the cursor | |
1777 */ | |
1778 validate_cheight(); | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1779 used = curwin->w_cline_height; // includes filler lines above |
7 | 1780 if (curwin->w_cursor.lnum < curwin->w_topline) |
1781 scrolled = used; | |
1782 | |
1783 #ifdef FEAT_FOLDING | |
1784 if (hasFolding(curwin->w_cursor.lnum, &top, &bot)) | |
1785 { | |
1786 --top; | |
1787 ++bot; | |
1788 } | |
1789 else | |
1790 #endif | |
1791 { | |
1792 top = curwin->w_cursor.lnum - 1; | |
1793 bot = curwin->w_cursor.lnum + 1; | |
1794 } | |
1795 new_topline = top + 1; | |
1796 | |
1797 #ifdef FEAT_DIFF | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1798 // "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
|
1799 // again. |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1800 // 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
|
1801 extra += diff_check_fill(curwin, curwin->w_cursor.lnum); |
7 | 1802 #endif |
1803 | |
1804 /* | |
1805 * Check if the lines from "top" to "bot" fit in the window. If they do, | |
1806 * set new_topline and advance "top" and "bot" to include more lines. | |
1807 */ | |
1808 while (top > 0) | |
1809 { | |
1810 #ifdef FEAT_FOLDING | |
1811 if (hasFolding(top, &top, NULL)) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1812 // count one logical line for a sequence of folded lines |
7 | 1813 i = 1; |
1814 else | |
1815 #endif | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
1816 i = PLINES_NOFILL(top); |
7 | 1817 used += i; |
1818 if (extra + i <= off && bot < curbuf->b_ml.ml_line_count) | |
1819 { | |
1820 #ifdef FEAT_FOLDING | |
1821 if (hasFolding(bot, NULL, &bot)) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1822 // count one logical line for a sequence of folded lines |
7 | 1823 ++used; |
1824 else | |
1825 #endif | |
1826 used += plines(bot); | |
1827 } | |
1828 if (used > curwin->w_height) | |
1829 break; | |
1830 if (top < curwin->w_topline) | |
1831 scrolled += i; | |
1832 | |
1833 /* | |
1834 * If scrolling is needed, scroll at least 'sj' lines. | |
1835 */ | |
1836 if ((new_topline >= curwin->w_topline || scrolled > min_scroll) | |
1837 && extra >= off) | |
1838 break; | |
1839 | |
1840 extra += i; | |
1841 new_topline = top; | |
1842 --top; | |
1843 ++bot; | |
1844 } | |
1845 | |
1846 /* | |
1847 * If we don't have enough space, put cursor in the middle. | |
1848 * This makes sure we get the same position when using "k" and "j" | |
1849 * in a small window. | |
1850 */ | |
1851 if (used > curwin->w_height) | |
1852 scroll_cursor_halfway(FALSE); | |
1853 else | |
1854 { | |
1855 /* | |
1856 * If "always" is FALSE, only adjust topline to a lower value, higher | |
1857 * value may happen with wrapping lines | |
1858 */ | |
1859 if (new_topline < curwin->w_topline || always) | |
1860 curwin->w_topline = new_topline; | |
1861 if (curwin->w_topline > curwin->w_cursor.lnum) | |
1862 curwin->w_topline = curwin->w_cursor.lnum; | |
1863 #ifdef FEAT_DIFF | |
1864 curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline); | |
1865 if (curwin->w_topfill > 0 && extra > off) | |
1866 { | |
1867 curwin->w_topfill -= extra - off; | |
1868 if (curwin->w_topfill < 0) | |
1869 curwin->w_topfill = 0; | |
1870 } | |
1871 check_topfill(curwin, FALSE); | |
1872 #endif | |
1873 if (curwin->w_topline != old_topline | |
1874 #ifdef FEAT_DIFF | |
1875 || curwin->w_topfill != old_topfill | |
1876 #endif | |
1877 ) | |
1878 curwin->w_valid &= | |
1879 ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); | |
1880 curwin->w_valid |= VALID_TOPLINE; | |
1881 } | |
1882 } | |
1883 | |
1884 /* | |
1885 * Set w_empty_rows and w_filler_rows for window "wp", having used up "used" | |
1886 * screen lines for text lines. | |
1887 */ | |
1888 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1889 set_empty_rows(win_T *wp, int used) |
7 | 1890 { |
1891 #ifdef FEAT_DIFF | |
1892 wp->w_filler_rows = 0; | |
1893 #endif | |
1894 if (used == 0) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1895 wp->w_empty_rows = 0; // single line that doesn't fit |
7 | 1896 else |
1897 { | |
1898 wp->w_empty_rows = wp->w_height - used; | |
1899 #ifdef FEAT_DIFF | |
1900 if (wp->w_botline <= wp->w_buffer->b_ml.ml_line_count) | |
1901 { | |
1902 wp->w_filler_rows = diff_check_fill(wp, wp->w_botline); | |
1903 if (wp->w_empty_rows > wp->w_filler_rows) | |
1904 wp->w_empty_rows -= wp->w_filler_rows; | |
1905 else | |
1906 { | |
1907 wp->w_filler_rows = wp->w_empty_rows; | |
1908 wp->w_empty_rows = 0; | |
1909 } | |
1910 } | |
1911 #endif | |
1912 } | |
1913 } | |
1914 | |
1915 /* | |
1916 * Recompute topline to put the cursor at the bottom of the window. | |
1917 * Scroll at least "min_scroll" lines. | |
1918 * If "set_topbot" is TRUE, set topline and botline first (for "zb"). | |
1919 * This is messy stuff!!! | |
1920 */ | |
1921 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1922 scroll_cursor_bot(int min_scroll, int set_topbot) |
7 | 1923 { |
1924 int used; | |
1925 int scrolled = 0; | |
1926 int extra = 0; | |
1927 int i; | |
1928 linenr_T line_count; | |
1929 linenr_T old_topline = curwin->w_topline; | |
1930 lineoff_T loff; | |
1931 lineoff_T boff; | |
1932 #ifdef FEAT_DIFF | |
1933 int old_topfill = curwin->w_topfill; | |
1934 int fill_below_window; | |
1935 #endif | |
1936 linenr_T old_botline = curwin->w_botline; | |
1937 linenr_T old_valid = curwin->w_valid; | |
1938 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
|
1939 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
|
1940 long so = get_scrolloff_value(); |
7 | 1941 |
1942 cln = curwin->w_cursor.lnum; | |
1943 if (set_topbot) | |
1944 { | |
1945 used = 0; | |
1946 curwin->w_botline = cln + 1; | |
1947 #ifdef FEAT_DIFF | |
1948 loff.fill = 0; | |
1949 #endif | |
1950 for (curwin->w_topline = curwin->w_botline; | |
1951 curwin->w_topline > 1; | |
1952 curwin->w_topline = loff.lnum) | |
1953 { | |
1954 loff.lnum = curwin->w_topline; | |
1955 topline_back(&loff); | |
2082
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
1956 if (loff.height == MAXCOL || used + loff.height > curwin->w_height) |
7 | 1957 break; |
1958 used += loff.height; | |
1959 #ifdef FEAT_DIFF | |
1960 curwin->w_topfill = loff.fill; | |
1961 #endif | |
1962 } | |
1963 set_empty_rows(curwin, used); | |
1964 curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP; | |
1965 if (curwin->w_topline != old_topline | |
1966 #ifdef FEAT_DIFF | |
1967 || curwin->w_topfill != old_topfill | |
1968 #endif | |
1969 ) | |
1970 curwin->w_valid &= ~(VALID_WROW|VALID_CROW); | |
1971 } | |
1972 else | |
1973 validate_botline(); | |
1974 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1975 // The lines of the cursor line itself are always used. |
7 | 1976 #ifdef FEAT_DIFF |
1977 used = plines_nofill(cln); | |
1978 #else | |
1979 validate_cheight(); | |
1980 used = curwin->w_cline_height; | |
1981 #endif | |
1982 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
1983 // 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
|
1984 // 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
|
1985 // botline. |
7 | 1986 if (cln >= curwin->w_botline) |
1987 { | |
1988 scrolled = used; | |
1989 if (cln == curwin->w_botline) | |
1990 scrolled -= curwin->w_empty_rows; | |
1991 } | |
1992 | |
1993 /* | |
1994 * Stop counting lines to scroll when | |
1995 * - hitting start of the file | |
1996 * - 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
|
1997 * - at least 'scrolloff' lines below the cursor |
7 | 1998 * - lines between botline and cursor have been counted |
1999 */ | |
2000 #ifdef FEAT_FOLDING | |
2001 if (!hasFolding(curwin->w_cursor.lnum, &loff.lnum, &boff.lnum)) | |
2002 #endif | |
2003 { | |
2004 loff.lnum = cln; | |
2005 boff.lnum = cln; | |
2006 } | |
2007 #ifdef FEAT_DIFF | |
2008 loff.fill = 0; | |
2009 boff.fill = 0; | |
2010 fill_below_window = diff_check_fill(curwin, curwin->w_botline) | |
2011 - curwin->w_filler_rows; | |
2012 #endif | |
2013 | |
2014 while (loff.lnum > 1) | |
2015 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2016 // 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
|
2017 // context for 'scrolloff' and counted all lines below the window. |
7 | 2018 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
|
2019 && extra >= (mouse_dragging > 0 ? mouse_dragging - 1 : so)) |
7 | 2020 || boff.lnum + 1 > curbuf->b_ml.ml_line_count) |
2021 && loff.lnum <= curwin->w_botline | |
2022 #ifdef FEAT_DIFF | |
2023 && (loff.lnum < curwin->w_botline | |
2024 || loff.fill >= fill_below_window) | |
2025 #endif | |
2026 ) | |
2027 break; | |
2028 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2029 // Add one line above |
7 | 2030 topline_back(&loff); |
2082
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2031 if (loff.height == MAXCOL) |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2032 used = MAXCOL; |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2033 else |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2034 used += loff.height; |
7 | 2035 if (used > curwin->w_height) |
2036 break; | |
2037 if (loff.lnum >= curwin->w_botline | |
2038 #ifdef FEAT_DIFF | |
2039 && (loff.lnum > curwin->w_botline | |
2040 || loff.fill <= fill_below_window) | |
2041 #endif | |
2042 ) | |
2043 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2044 // Count screen lines that are below the window. |
7 | 2045 scrolled += loff.height; |
2046 if (loff.lnum == curwin->w_botline | |
2047 #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
|
2048 && loff.fill == 0 |
7 | 2049 #endif |
2050 ) | |
2051 scrolled -= curwin->w_empty_rows; | |
2052 } | |
2053 | |
2054 if (boff.lnum < curbuf->b_ml.ml_line_count) | |
2055 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2056 // Add one line below |
7 | 2057 botline_forw(&boff); |
2058 used += boff.height; | |
2059 if (used > curwin->w_height) | |
2060 break; | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
17863
diff
changeset
|
2061 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
|
2062 || scrolled < min_scroll) |
7 | 2063 { |
2064 extra += boff.height; | |
2065 if (boff.lnum >= curwin->w_botline | |
2066 #ifdef FEAT_DIFF | |
2067 || (boff.lnum + 1 == curwin->w_botline | |
2068 && boff.fill > curwin->w_filler_rows) | |
2069 #endif | |
2070 ) | |
2071 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2072 // Count screen lines that are below the window. |
7 | 2073 scrolled += boff.height; |
2074 if (boff.lnum == curwin->w_botline | |
2075 #ifdef FEAT_DIFF | |
2076 && boff.fill == 0 | |
2077 #endif | |
2078 ) | |
2079 scrolled -= curwin->w_empty_rows; | |
2080 } | |
2081 } | |
2082 } | |
2083 } | |
2084 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2085 // curwin->w_empty_rows is larger, no need to scroll |
7 | 2086 if (scrolled <= 0) |
2087 line_count = 0; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2088 // more than a screenfull, don't scroll but redraw |
7 | 2089 else if (used > curwin->w_height) |
2090 line_count = used; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2091 // scroll minimal number of lines |
7 | 2092 else |
2093 { | |
2094 line_count = 0; | |
2095 #ifdef FEAT_DIFF | |
2096 boff.fill = curwin->w_topfill; | |
2097 #endif | |
2098 boff.lnum = curwin->w_topline - 1; | |
2099 for (i = 0; i < scrolled && boff.lnum < curwin->w_botline; ) | |
2100 { | |
2101 botline_forw(&boff); | |
2102 i += boff.height; | |
2103 ++line_count; | |
2104 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2105 if (i < scrolled) // below curwin->w_botline, don't scroll |
7 | 2106 line_count = 9999; |
2107 } | |
2108 | |
2109 /* | |
2110 * Scroll up if the cursor is off the bottom of the screen a bit. | |
2111 * Otherwise put it at 1/2 of the screen. | |
2112 */ | |
2113 if (line_count >= curwin->w_height && line_count > min_scroll) | |
2114 scroll_cursor_halfway(FALSE); | |
2115 else | |
2116 scrollup(line_count, TRUE); | |
2117 | |
2118 /* | |
2119 * If topline didn't change we need to restore w_botline and w_empty_rows | |
2120 * (we changed them). | |
2121 * If topline did change, update_screen() will set botline. | |
2122 */ | |
2123 if (curwin->w_topline == old_topline && set_topbot) | |
2124 { | |
2125 curwin->w_botline = old_botline; | |
2126 curwin->w_empty_rows = old_empty_rows; | |
2127 curwin->w_valid = old_valid; | |
2128 } | |
2129 curwin->w_valid |= VALID_TOPLINE; | |
2130 } | |
2131 | |
2132 /* | |
2133 * Recompute topline to put the cursor halfway the window | |
2134 * If "atend" is TRUE, also put it halfway at the end of the file. | |
2135 */ | |
2136 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2137 scroll_cursor_halfway(int atend) |
7 | 2138 { |
2139 int above = 0; | |
2140 linenr_T topline; | |
2141 #ifdef FEAT_DIFF | |
2142 int topfill = 0; | |
2143 #endif | |
2144 int below = 0; | |
2145 int used; | |
2146 lineoff_T loff; | |
2147 lineoff_T boff; | |
5661 | 2148 #ifdef FEAT_DIFF |
5653 | 2149 linenr_T old_topline = curwin->w_topline; |
5661 | 2150 #endif |
7 | 2151 |
22403
3351d2cd3f1f
patch 8.2.1750: popup_setoptions() setting firstline fails if cursorline set
Bram Moolenaar <Bram@vim.org>
parents:
21321
diff
changeset
|
2152 #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
|
2153 // 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
|
2154 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
|
2155 #endif |
7 | 2156 loff.lnum = boff.lnum = curwin->w_cursor.lnum; |
2157 #ifdef FEAT_FOLDING | |
2158 (void)hasFolding(loff.lnum, &loff.lnum, &boff.lnum); | |
2159 #endif | |
2160 #ifdef FEAT_DIFF | |
2161 used = plines_nofill(loff.lnum); | |
2162 loff.fill = 0; | |
2163 boff.fill = 0; | |
2164 #else | |
2165 used = plines(loff.lnum); | |
2166 #endif | |
2167 topline = loff.lnum; | |
2168 while (topline > 1) | |
2169 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2170 if (below <= above) // add a line below the cursor first |
7 | 2171 { |
2172 if (boff.lnum < curbuf->b_ml.ml_line_count) | |
2173 { | |
2174 botline_forw(&boff); | |
2175 used += boff.height; | |
2176 if (used > curwin->w_height) | |
2177 break; | |
2178 below += boff.height; | |
2179 } | |
2180 else | |
2181 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2182 ++below; // count a "~" line |
7 | 2183 if (atend) |
2184 ++used; | |
2185 } | |
2186 } | |
2187 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2188 if (below > above) // add a line above the cursor |
7 | 2189 { |
2190 topline_back(&loff); | |
2082
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2191 if (loff.height == MAXCOL) |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2192 used = MAXCOL; |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2193 else |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2194 used += loff.height; |
7 | 2195 if (used > curwin->w_height) |
2196 break; | |
2197 above += loff.height; | |
2198 topline = loff.lnum; | |
2199 #ifdef FEAT_DIFF | |
2200 topfill = loff.fill; | |
2201 #endif | |
2202 } | |
2203 } | |
2204 #ifdef FEAT_FOLDING | |
2205 if (!hasFolding(topline, &curwin->w_topline, NULL)) | |
2206 #endif | |
2207 curwin->w_topline = topline; | |
2208 #ifdef FEAT_DIFF | |
2209 curwin->w_topfill = topfill; | |
5653 | 2210 if (old_topline > curwin->w_topline + curwin->w_height) |
2211 curwin->w_botfill = FALSE; | |
7 | 2212 check_topfill(curwin, FALSE); |
2213 #endif | |
2214 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); | |
2215 curwin->w_valid |= VALID_TOPLINE; | |
2216 } | |
2217 | |
2218 /* | |
2219 * 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
|
2220 * 'scrolloff' lines from the top and bottom, if possible. |
7 | 2221 * If not possible, put it at the same position as scroll_cursor_halfway(). |
2222 * When called topline must be valid! | |
2223 */ | |
2224 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2225 cursor_correct(void) |
7 | 2226 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2227 int above = 0; // screen lines above topline |
7 | 2228 linenr_T topline; |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2229 int below = 0; // screen lines below botline |
7 | 2230 linenr_T botline; |
2231 int above_wanted, below_wanted; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2232 linenr_T cln; // Cursor Line Number |
7 | 2233 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
|
2234 long so = get_scrolloff_value(); |
7 | 2235 |
2236 /* | |
2237 * How many lines we would like to have above/below the cursor depends on | |
2238 * whether the first/last line of the file is on screen. | |
2239 */ | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
2240 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
|
2241 below_wanted = so; |
1121 | 2242 if (mouse_dragging > 0) |
7 | 2243 { |
2244 above_wanted = mouse_dragging - 1; | |
2245 below_wanted = mouse_dragging - 1; | |
2246 } | |
2247 if (curwin->w_topline == 1) | |
2248 { | |
2249 above_wanted = 0; | |
2250 max_off = curwin->w_height / 2; | |
2251 if (below_wanted > max_off) | |
2252 below_wanted = max_off; | |
2253 } | |
2254 validate_botline(); | |
2255 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
|
2256 && mouse_dragging == 0) |
7 | 2257 { |
2258 below_wanted = 0; | |
2259 max_off = (curwin->w_height - 1) / 2; | |
2260 if (above_wanted > max_off) | |
2261 above_wanted = max_off; | |
2262 } | |
2263 | |
2264 /* | |
2265 * If there are sufficient file-lines above and below the cursor, we can | |
2266 * return now. | |
2267 */ | |
2268 cln = curwin->w_cursor.lnum; | |
2269 if (cln >= curwin->w_topline + above_wanted | |
2270 && cln < curwin->w_botline - below_wanted | |
2271 #ifdef FEAT_FOLDING | |
2272 && !hasAnyFolding(curwin) | |
2273 #endif | |
2274 ) | |
2275 return; | |
2276 | |
2277 /* | |
2278 * Narrow down the area where the cursor can be put by taking lines from | |
2279 * the top and the bottom until: | |
2280 * - the desired context lines are found | |
2281 * - the lines from the top is past the lines from the bottom | |
2282 */ | |
2283 topline = curwin->w_topline; | |
2284 botline = curwin->w_botline - 1; | |
2285 #ifdef FEAT_DIFF | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2286 // count filler lines as context |
7 | 2287 above = curwin->w_topfill; |
2288 below = curwin->w_filler_rows; | |
2289 #endif | |
2290 while ((above < above_wanted || below < below_wanted) && topline < botline) | |
2291 { | |
2292 if (below < below_wanted && (below <= above || above >= above_wanted)) | |
2293 { | |
2294 #ifdef FEAT_FOLDING | |
2295 if (hasFolding(botline, &botline, NULL)) | |
2296 ++below; | |
2297 else | |
2298 #endif | |
2299 below += plines(botline); | |
2300 --botline; | |
2301 } | |
2302 if (above < above_wanted && (above < below || below >= below_wanted)) | |
2303 { | |
2304 #ifdef FEAT_FOLDING | |
2305 if (hasFolding(topline, NULL, &topline)) | |
2306 ++above; | |
2307 else | |
2308 #endif | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
2309 above += PLINES_NOFILL(topline); |
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
2310 #ifdef FEAT_DIFF |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2311 // Count filler lines below this line as context. |
7 | 2312 if (topline < botline) |
2313 above += diff_check_fill(curwin, topline + 1); | |
2314 #endif | |
2315 ++topline; | |
2316 } | |
2317 } | |
2318 if (topline == botline || botline == 0) | |
2319 curwin->w_cursor.lnum = topline; | |
2320 else if (topline > botline) | |
2321 curwin->w_cursor.lnum = botline; | |
2322 else | |
2323 { | |
2324 if (cln < topline && curwin->w_topline > 1) | |
2325 { | |
2326 curwin->w_cursor.lnum = topline; | |
2327 curwin->w_valid &= | |
2328 ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW); | |
2329 } | |
2330 if (cln > botline && curwin->w_botline <= curbuf->b_ml.ml_line_count) | |
2331 { | |
2332 curwin->w_cursor.lnum = botline; | |
2333 curwin->w_valid &= | |
2334 ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW); | |
2335 } | |
2336 } | |
2337 curwin->w_valid |= VALID_TOPLINE; | |
2338 } | |
2339 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7103
diff
changeset
|
2340 static void get_scroll_overlap(lineoff_T *lp, int dir); |
7 | 2341 |
2342 /* | |
2343 * move screen 'count' pages up or down and update screen | |
2344 * | |
2345 * return FAIL for failure, OK otherwise | |
2346 */ | |
2347 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2348 onepage(int dir, long count) |
7 | 2349 { |
2350 long n; | |
2351 int retval = OK; | |
2352 lineoff_T loff; | |
2353 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
|
2354 long so = get_scrolloff_value(); |
7 | 2355 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2356 if (curbuf->b_ml.ml_line_count == 1) // nothing to do |
7 | 2357 { |
2358 beep_flush(); | |
2359 return FAIL; | |
2360 } | |
2361 | |
2362 for ( ; count > 0; --count) | |
2363 { | |
2364 validate_botline(); | |
2365 /* | |
2366 * It's an error to move a page up when the first line is already on | |
2367 * the screen. It's an error to move a page down when the last line | |
2368 * is on the screen and the topline is 'scrolloff' lines from the | |
2369 * last line. | |
2370 */ | |
2371 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
|
2372 ? ((curwin->w_topline >= curbuf->b_ml.ml_line_count - so) |
7 | 2373 && curwin->w_botline > curbuf->b_ml.ml_line_count) |
2374 : (curwin->w_topline == 1 | |
2375 #ifdef FEAT_DIFF | |
2376 && curwin->w_topfill == | |
2377 diff_check_fill(curwin, curwin->w_topline) | |
2378 #endif | |
2379 )) | |
2380 { | |
2381 beep_flush(); | |
2382 retval = FAIL; | |
2383 break; | |
2384 } | |
2385 | |
2386 #ifdef FEAT_DIFF | |
2387 loff.fill = 0; | |
2388 #endif | |
2389 if (dir == FORWARD) | |
2390 { | |
10349
cf988222b150
commit https://github.com/vim/vim/commit/a1f4cb93ba50ea9e40cd4b1f5592b8a6d1398660
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
2391 if (ONE_WINDOW && p_window > 0 && p_window < Rows - 1) |
7 | 2392 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2393 // Vi compatible scrolling |
164 | 2394 if (p_window <= 2) |
2395 ++curwin->w_topline; | |
2396 else | |
2397 curwin->w_topline += p_window - 2; | |
2398 if (curwin->w_topline > curbuf->b_ml.ml_line_count) | |
2399 curwin->w_topline = curbuf->b_ml.ml_line_count; | |
2400 curwin->w_cursor.lnum = curwin->w_topline; | |
2401 } | |
2402 else if (curwin->w_botline > curbuf->b_ml.ml_line_count) | |
2403 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2404 // at end of file |
7 | 2405 curwin->w_topline = curbuf->b_ml.ml_line_count; |
2406 #ifdef FEAT_DIFF | |
2407 curwin->w_topfill = 0; | |
2408 #endif | |
2409 curwin->w_valid &= ~(VALID_WROW|VALID_CROW); | |
2410 } | |
2411 else | |
2412 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2413 // 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
|
2414 // and go upwards. |
7 | 2415 loff.lnum = curwin->w_botline; |
2416 #ifdef FEAT_DIFF | |
2417 loff.fill = diff_check_fill(curwin, loff.lnum) | |
2418 - curwin->w_filler_rows; | |
2419 #endif | |
2420 get_scroll_overlap(&loff, -1); | |
2421 curwin->w_topline = loff.lnum; | |
2422 #ifdef FEAT_DIFF | |
2423 curwin->w_topfill = loff.fill; | |
2424 check_topfill(curwin, FALSE); | |
2425 #endif | |
2426 curwin->w_cursor.lnum = curwin->w_topline; | |
2427 curwin->w_valid &= ~(VALID_WCOL|VALID_CHEIGHT|VALID_WROW| | |
2428 VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); | |
2429 } | |
2430 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2431 else // dir == BACKWARDS |
7 | 2432 { |
2433 #ifdef FEAT_DIFF | |
2434 if (curwin->w_topline == 1) | |
2435 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2436 // Include max number of filler lines |
7 | 2437 max_topfill(); |
2438 continue; | |
2439 } | |
2440 #endif | |
10349
cf988222b150
commit https://github.com/vim/vim/commit/a1f4cb93ba50ea9e40cd4b1f5592b8a6d1398660
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
2441 if (ONE_WINDOW && p_window > 0 && p_window < Rows - 1) |
164 | 2442 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2443 // Vi compatible scrolling (sort of) |
164 | 2444 if (p_window <= 2) |
2445 --curwin->w_topline; | |
2446 else | |
2447 curwin->w_topline -= p_window - 2; | |
2448 if (curwin->w_topline < 1) | |
2449 curwin->w_topline = 1; | |
2450 curwin->w_cursor.lnum = curwin->w_topline + p_window - 1; | |
2451 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
2452 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
2453 continue; | |
2454 } | |
2455 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2456 // 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
|
2457 // 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
|
2458 // the same line as before doing CTRL-F. |
7 | 2459 loff.lnum = curwin->w_topline - 1; |
2460 #ifdef FEAT_DIFF | |
2461 loff.fill = diff_check_fill(curwin, loff.lnum + 1) | |
2462 - curwin->w_topfill; | |
2463 #endif | |
2464 get_scroll_overlap(&loff, 1); | |
2465 | |
2466 if (loff.lnum >= curbuf->b_ml.ml_line_count) | |
2467 { | |
2468 loff.lnum = curbuf->b_ml.ml_line_count; | |
2469 #ifdef FEAT_DIFF | |
2470 loff.fill = 0; | |
2471 } | |
2472 else | |
2473 { | |
2474 botline_topline(&loff); | |
2475 #endif | |
2476 } | |
2477 curwin->w_cursor.lnum = loff.lnum; | |
2478 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2479 // 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
|
2480 // at the bottom of the window. |
7 | 2481 n = 0; |
2482 while (n <= curwin->w_height && loff.lnum >= 1) | |
2483 { | |
2484 topline_back(&loff); | |
2082
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2485 if (loff.height == MAXCOL) |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2486 n = MAXCOL; |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2487 else |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2488 n += loff.height; |
7 | 2489 } |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2490 if (loff.lnum < 1) // at begin of file |
7 | 2491 { |
2492 curwin->w_topline = 1; | |
2493 #ifdef FEAT_DIFF | |
2494 max_topfill(); | |
2495 #endif | |
2496 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); | |
2497 } | |
2498 else | |
2499 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2500 // Go two lines forward again. |
7 | 2501 #ifdef FEAT_DIFF |
2502 topline_botline(&loff); | |
2503 #endif | |
2504 botline_forw(&loff); | |
2505 botline_forw(&loff); | |
2506 #ifdef FEAT_DIFF | |
2507 botline_topline(&loff); | |
2508 #endif | |
2509 #ifdef FEAT_FOLDING | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2510 // We're at the wrong end of a fold now. |
7 | 2511 (void)hasFolding(loff.lnum, &loff.lnum, NULL); |
2512 #endif | |
2513 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2514 // 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
|
2515 // very long lines. |
7 | 2516 if (loff.lnum >= curwin->w_topline |
2517 #ifdef FEAT_DIFF | |
2518 && (loff.lnum > curwin->w_topline | |
2519 || loff.fill >= curwin->w_topfill) | |
2520 #endif | |
2521 ) | |
2522 { | |
2523 #ifdef FEAT_DIFF | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2524 // 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
|
2525 // that's not enough, backup one line. |
7 | 2526 loff.fill = curwin->w_topfill; |
2527 if (curwin->w_topfill < diff_check_fill(curwin, | |
2528 curwin->w_topline)) | |
2529 max_topfill(); | |
2530 if (curwin->w_topfill == loff.fill) | |
2531 #endif | |
2532 { | |
2533 --curwin->w_topline; | |
2534 #ifdef FEAT_DIFF | |
2535 curwin->w_topfill = 0; | |
2536 #endif | |
2537 } | |
2538 comp_botline(curwin); | |
2539 curwin->w_cursor.lnum = curwin->w_botline - 1; | |
5764 | 2540 curwin->w_valid &= |
2541 ~(VALID_WCOL|VALID_CHEIGHT|VALID_WROW|VALID_CROW); | |
7 | 2542 } |
2543 else | |
2544 { | |
2545 curwin->w_topline = loff.lnum; | |
2546 #ifdef FEAT_DIFF | |
2547 curwin->w_topfill = loff.fill; | |
2548 check_topfill(curwin, FALSE); | |
2549 #endif | |
2550 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); | |
2551 } | |
2552 } | |
2553 } | |
2554 } | |
2555 #ifdef FEAT_FOLDING | |
2556 foldAdjustCursor(); | |
2557 #endif | |
2558 cursor_correct(); | |
10102
b80ad55d62d8
commit https://github.com/vim/vim/commit/bc54f3f3fed4dc3556df8c46cee6739d211b0eb2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2559 check_cursor_col(); |
161 | 2560 if (retval == OK) |
2561 beginline(BL_SOL | BL_FIX); | |
7 | 2562 curwin->w_valid &= ~(VALID_WCOL|VALID_WROW|VALID_VIRTCOL); |
2563 | |
14317
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2564 if (retval == OK && dir == FORWARD) |
7 | 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 // 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
|
2567 // 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
|
2568 // 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
|
2569 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
|
2570 { |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2571 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
|
2572 if (curwin->w_topline <= old_topline |
7 | 2573 && 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
|
2574 { |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2575 curwin->w_topline = old_topline + 1; |
7 | 2576 #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
|
2577 (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
|
2578 #endif |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2579 } |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2580 } |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2581 #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
|
2582 else if (curwin->w_botline > curbuf->b_ml.ml_line_count) |
7 | 2583 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
2584 #endif | |
2585 } | |
2586 | |
2587 redraw_later(VALID); | |
2588 return retval; | |
2589 } | |
2590 | |
2591 /* | |
2592 * Decide how much overlap to use for page-up or page-down scrolling. | |
2593 * This is symmetric, so that doing both keeps the same lines displayed. | |
2594 * Three lines are examined: | |
2595 * | |
2596 * before CTRL-F after CTRL-F / before CTRL-B | |
2597 * etc. l1 | |
2598 * l1 last but one line ------------ | |
2599 * l2 last text line l2 top text line | |
2600 * ------------- l3 second text line | |
2601 * l3 etc. | |
2602 */ | |
2603 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2604 get_scroll_overlap(lineoff_T *lp, int dir) |
7 | 2605 { |
2606 int h1, h2, h3, h4; | |
2607 int min_height = curwin->w_height - 2; | |
2608 lineoff_T loff0, loff1, loff2; | |
2609 | |
2610 #ifdef FEAT_DIFF | |
2611 if (lp->fill > 0) | |
2612 lp->height = 1; | |
2613 else | |
2614 lp->height = plines_nofill(lp->lnum); | |
2615 #else | |
2616 lp->height = plines(lp->lnum); | |
2617 #endif | |
2618 h1 = lp->height; | |
2619 if (h1 > min_height) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2620 return; // no overlap |
7 | 2621 |
2622 loff0 = *lp; | |
2623 if (dir > 0) | |
2624 botline_forw(lp); | |
2625 else | |
2626 topline_back(lp); | |
2627 h2 = lp->height; | |
3968 | 2628 if (h2 == MAXCOL || h2 + h1 > min_height) |
7 | 2629 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2630 *lp = loff0; // no overlap |
7 | 2631 return; |
2632 } | |
2633 | |
2634 loff1 = *lp; | |
2635 if (dir > 0) | |
2636 botline_forw(lp); | |
2637 else | |
2638 topline_back(lp); | |
2639 h3 = lp->height; | |
3968 | 2640 if (h3 == MAXCOL || h3 + h2 > min_height) |
7 | 2641 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2642 *lp = loff0; // no overlap |
7 | 2643 return; |
2644 } | |
2645 | |
2646 loff2 = *lp; | |
2647 if (dir > 0) | |
2648 botline_forw(lp); | |
2649 else | |
2650 topline_back(lp); | |
2651 h4 = lp->height; | |
3968 | 2652 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
|
2653 *lp = loff1; // 1 line overlap |
7 | 2654 else |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2655 *lp = loff2; // 2 lines overlap |
7 | 2656 return; |
2657 } | |
2658 | |
2659 /* | |
2660 * Scroll 'scroll' lines up or down. | |
2661 */ | |
2662 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2663 halfpage(int flag, linenr_T Prenum) |
7 | 2664 { |
2665 long scrolled = 0; | |
2666 int i; | |
2667 int n; | |
2668 int room; | |
2669 | |
2670 if (Prenum) | |
2671 curwin->w_p_scr = (Prenum > curwin->w_height) ? | |
2672 curwin->w_height : Prenum; | |
2673 n = (curwin->w_p_scr <= curwin->w_height) ? | |
2674 curwin->w_p_scr : curwin->w_height; | |
2675 | |
11258
84f71a8a5f2c
patch 8.0.0515: ml_get errors in silent Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2676 update_topline(); |
7 | 2677 validate_botline(); |
2678 room = curwin->w_empty_rows; | |
2679 #ifdef FEAT_DIFF | |
2680 room += curwin->w_filler_rows; | |
2681 #endif | |
2682 if (flag) | |
2683 { | |
2684 /* | |
2685 * scroll the text up | |
2686 */ | |
2687 while (n > 0 && curwin->w_botline <= curbuf->b_ml.ml_line_count) | |
2688 { | |
2689 #ifdef FEAT_DIFF | |
2690 if (curwin->w_topfill > 0) | |
2691 { | |
2692 i = 1; | |
21321
1421eca61db9
patch 8.2.1211: removed more than dead code
Bram Moolenaar <Bram@vim.org>
parents:
21134
diff
changeset
|
2693 --n; |
7 | 2694 --curwin->w_topfill; |
2695 } | |
2696 else | |
2697 #endif | |
2698 { | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
2699 i = PLINES_NOFILL(curwin->w_topline); |
7 | 2700 n -= i; |
2701 if (n < 0 && scrolled > 0) | |
2702 break; | |
2703 #ifdef FEAT_FOLDING | |
2704 (void)hasFolding(curwin->w_topline, NULL, &curwin->w_topline); | |
2705 #endif | |
2706 ++curwin->w_topline; | |
2707 #ifdef FEAT_DIFF | |
2708 curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline); | |
2709 #endif | |
2710 | |
2711 if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
2712 { | |
2713 ++curwin->w_cursor.lnum; | |
2714 curwin->w_valid &= | |
2715 ~(VALID_VIRTCOL|VALID_CHEIGHT|VALID_WCOL); | |
2716 } | |
2717 } | |
2718 curwin->w_valid &= ~(VALID_CROW|VALID_WROW); | |
2719 scrolled += i; | |
2720 | |
2721 /* | |
2722 * Correct w_botline for changed w_topline. | |
2723 * Won't work when there are filler lines. | |
2724 */ | |
2725 #ifdef FEAT_DIFF | |
2726 if (curwin->w_p_diff) | |
2727 curwin->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP); | |
2728 else | |
2729 #endif | |
2730 { | |
2731 room += i; | |
2732 do | |
2733 { | |
2734 i = plines(curwin->w_botline); | |
2735 if (i > room) | |
2736 break; | |
2737 #ifdef FEAT_FOLDING | |
2738 (void)hasFolding(curwin->w_botline, NULL, | |
2739 &curwin->w_botline); | |
2740 #endif | |
2741 ++curwin->w_botline; | |
2742 room -= i; | |
2743 } while (curwin->w_botline <= curbuf->b_ml.ml_line_count); | |
2744 } | |
2745 } | |
2746 | |
2747 /* | |
2748 * When hit bottom of the file: move cursor down. | |
2749 */ | |
2750 if (n > 0) | |
2751 { | |
2752 # ifdef FEAT_FOLDING | |
2753 if (hasAnyFolding(curwin)) | |
2754 { | |
2755 while (--n >= 0 | |
2756 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
2757 { | |
2758 (void)hasFolding(curwin->w_cursor.lnum, NULL, | |
2759 &curwin->w_cursor.lnum); | |
2760 ++curwin->w_cursor.lnum; | |
2761 } | |
2762 } | |
2763 else | |
2764 # endif | |
2765 curwin->w_cursor.lnum += n; | |
2766 check_cursor_lnum(); | |
2767 } | |
2768 } | |
2769 else | |
2770 { | |
2771 /* | |
2772 * scroll the text down | |
2773 */ | |
2774 while (n > 0 && curwin->w_topline > 1) | |
2775 { | |
2776 #ifdef FEAT_DIFF | |
2777 if (curwin->w_topfill < diff_check_fill(curwin, curwin->w_topline)) | |
2778 { | |
2779 i = 1; | |
16042
7952be788a49
patch 8.1.1026: unused condition
Bram Moolenaar <Bram@vim.org>
parents:
15713
diff
changeset
|
2780 --n; |
7 | 2781 ++curwin->w_topfill; |
2782 } | |
2783 else | |
2784 #endif | |
2785 { | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
2786 i = PLINES_NOFILL(curwin->w_topline - 1); |
7 | 2787 n -= i; |
2788 if (n < 0 && scrolled > 0) | |
2789 break; | |
2790 --curwin->w_topline; | |
2791 #ifdef FEAT_FOLDING | |
2792 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); | |
2793 #endif | |
2794 #ifdef FEAT_DIFF | |
2795 curwin->w_topfill = 0; | |
2796 #endif | |
2797 } | |
2798 curwin->w_valid &= ~(VALID_CROW|VALID_WROW| | |
2799 VALID_BOTLINE|VALID_BOTLINE_AP); | |
2800 scrolled += i; | |
2801 if (curwin->w_cursor.lnum > 1) | |
2802 { | |
2803 --curwin->w_cursor.lnum; | |
2804 curwin->w_valid &= ~(VALID_VIRTCOL|VALID_CHEIGHT|VALID_WCOL); | |
2805 } | |
2806 } | |
16042
7952be788a49
patch 8.1.1026: unused condition
Bram Moolenaar <Bram@vim.org>
parents:
15713
diff
changeset
|
2807 |
7 | 2808 /* |
2809 * When hit top of the file: move cursor up. | |
2810 */ | |
2811 if (n > 0) | |
2812 { | |
2813 if (curwin->w_cursor.lnum <= (linenr_T)n) | |
2814 curwin->w_cursor.lnum = 1; | |
2815 else | |
2816 # ifdef FEAT_FOLDING | |
2817 if (hasAnyFolding(curwin)) | |
2818 { | |
2819 while (--n >= 0 && curwin->w_cursor.lnum > 1) | |
2820 { | |
2821 --curwin->w_cursor.lnum; | |
2822 (void)hasFolding(curwin->w_cursor.lnum, | |
2823 &curwin->w_cursor.lnum, NULL); | |
2824 } | |
2825 } | |
2826 else | |
2827 # endif | |
2828 curwin->w_cursor.lnum -= n; | |
2829 } | |
2830 } | |
2831 # ifdef FEAT_FOLDING | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2832 // Move cursor to first line of closed fold. |
7 | 2833 foldAdjustCursor(); |
2834 # endif | |
2835 #ifdef FEAT_DIFF | |
2836 check_topfill(curwin, !flag); | |
2837 #endif | |
2838 cursor_correct(); | |
2839 beginline(BL_SOL | BL_FIX); | |
2840 redraw_later(VALID); | |
2841 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2842 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2843 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2844 do_check_cursorbind(void) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2845 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2846 linenr_T line = curwin->w_cursor.lnum; |
3415 | 2847 colnr_T col = curwin->w_cursor.col; |
2848 colnr_T coladd = curwin->w_cursor.coladd; | |
3433 | 2849 colnr_T curswant = curwin->w_curswant; |
2850 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
|
2851 win_T *old_curwin = curwin; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2852 buf_T *old_curbuf = curbuf; |
2693 | 2853 int restart_edit_save; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2854 int old_VIsual_select = VIsual_select; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2855 int old_VIsual_active = VIsual_active; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2856 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2857 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2858 * loop through the cursorbound windows |
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 VIsual_select = VIsual_active = 0; |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2861 FOR_ALL_WINDOWS(curwin) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2862 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2863 curbuf = curwin->w_buffer; |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2864 // 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
|
2865 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
|
2866 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2867 # ifdef FEAT_DIFF |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2868 if (curwin->w_p_diff) |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10102
diff
changeset
|
2869 curwin->w_cursor.lnum = |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10102
diff
changeset
|
2870 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
|
2871 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2872 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2873 curwin->w_cursor.lnum = line; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2874 curwin->w_cursor.col = col; |
3415 | 2875 curwin->w_cursor.coladd = coladd; |
3433 | 2876 curwin->w_curswant = curswant; |
2877 curwin->w_set_curswant = set_curswant; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2878 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2879 // 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
|
2880 // "restart_edit" to allow the cursor to be beyond the EOL. |
2693 | 2881 restart_edit_save = restart_edit; |
2882 restart_edit = TRUE; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2883 check_cursor(); |
10607
e39300d3d2cf
patch 8.0.0193: accidentally removed #ifdef
Christian Brabandt <cb@256bit.org>
parents:
10597
diff
changeset
|
2884 # ifdef FEAT_SYN_HL |
10597
472bff31a20a
patch 8.0.0188: redrawing for 'cursorbind' is inefficient
Christian Brabandt <cb@256bit.org>
parents:
10585
diff
changeset
|
2885 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
|
2886 validate_cursor(); |
10607
e39300d3d2cf
patch 8.0.0193: accidentally removed #ifdef
Christian Brabandt <cb@256bit.org>
parents:
10597
diff
changeset
|
2887 # endif |
2693 | 2888 restart_edit = restart_edit_save; |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2889 // Correct cursor for multi-byte character. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2890 if (has_mbyte) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2891 mb_adjust_cursor(); |
10597
472bff31a20a
patch 8.0.0188: redrawing for 'cursorbind' is inefficient
Christian Brabandt <cb@256bit.org>
parents:
10585
diff
changeset
|
2892 redraw_later(VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2893 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18892
diff
changeset
|
2894 // Only scroll when 'scrollbind' hasn't done this. |
2688 | 2895 if (!curwin->w_p_scb) |
2896 update_topline(); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2897 curwin->w_redr_status = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2898 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2899 } |
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 * reset current-window |
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 VIsual_select = old_VIsual_select; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2905 VIsual_active = old_VIsual_active; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2906 curwin = old_curwin; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2907 curbuf = old_curbuf; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2908 } |