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