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