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