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