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