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