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