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