annotate src/move.c @ 32669:448aef880252

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