blob: 778cda4d4f4f59a4dcd30e4598d6a42843c6726a [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawscreen.c: Code for updating all the windows on the screen.
12 * This is the top level, drawline.c is the middle and screen.c the lower
13 * level.
14 *
15 * update_screen() is the function that updates all windows and status lines.
16 * It is called form the main loop when must_redraw is non-zero. It may be
17 * called from other places when an immediate screen update is needed.
18 *
19 * The part of the buffer that is displayed in a window is set with:
20 * - w_topline (first buffer line in window)
21 * - w_topfill (filler lines above the first line)
22 * - w_leftcol (leftmost window cell in window),
23 * - w_skipcol (skipped window cells of first line)
24 *
25 * Commands that only move the cursor around in a window, do not need to take
26 * action to update the display. The main loop will check if w_topline is
27 * valid and update it (scroll the window) when needed.
28 *
29 * Commands that scroll a window change w_topline and must call
30 * check_cursor() to move the cursor into the visible part of the window, and
Bram Moolenaara4d158b2022-08-14 14:17:45 +010031 * call redraw_later(UPD_VALID) to have the window displayed by update_screen()
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020032 * later.
33 *
34 * Commands that change text in the buffer must call changed_bytes() or
35 * changed_lines() to mark the area that changed and will require updating
36 * later. The main loop will call update_screen(), which will update each
37 * window that shows the changed buffer. This assumes text above the change
38 * can remain displayed as it is. Text after the change may need updating for
39 * scrolling, folding and syntax highlighting.
40 *
41 * Commands that change how a window is displayed (e.g., setting 'list') or
42 * invalidate the contents of a window in another way (e.g., change fold
Bram Moolenaara4d158b2022-08-14 14:17:45 +010043 * settings), must call redraw_later(UPD_NOT_VALID) to have the whole window
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020044 * redisplayed by update_screen() later.
45 *
46 * Commands that change how a buffer is displayed (e.g., setting 'tabstop')
Bram Moolenaara4d158b2022-08-14 14:17:45 +010047 * must call redraw_curbuf_later(UPD_NOT_VALID) to have all the windows for the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020048 * buffer redisplayed by update_screen() later.
49 *
50 * Commands that change highlighting and possibly cause a scroll too must call
Bram Moolenaara4d158b2022-08-14 14:17:45 +010051 * redraw_later(UPD_SOME_VALID) to update the whole window but still use
52 * scrolling to avoid redrawing everything. But the length of displayed lines
53 * must not change, use UPD_NOT_VALID then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020054 *
Bram Moolenaara4d158b2022-08-14 14:17:45 +010055 * Commands that move the window position must call redraw_later(UPD_NOT_VALID).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020056 * TODO: should minimize redrawing by scrolling when possible.
57 *
58 * Commands that change everything (e.g., resizing the screen) must call
Bram Moolenaara4d158b2022-08-14 14:17:45 +010059 * redraw_all_later(UPD_NOT_VALID) or redraw_all_later(UPD_CLEAR).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020060 *
61 * Things that are handled indirectly:
62 * - When messages scroll the screen up, msg_scrolled will be set and
63 * update_screen() called to redraw.
64 */
65
66#include "vim.h"
67
68static void win_update(win_T *wp);
69#ifdef FEAT_STL_OPT
70static void redraw_custom_statusline(win_T *wp);
71#endif
Bram Moolenaare52e0c82020-02-28 22:20:10 +010072#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
73static int did_update_one_window;
74#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020075
76/*
77 * Based on the current value of curwin->w_topline, transfer a screenfull
78 * of stuff from Filemem to ScreenLines[], and update curwin->w_botline.
79 * Return OK when the screen was updated, FAIL if it was not done.
80 */
81 int
82update_screen(int type_arg)
83{
84 int type = type_arg;
85 win_T *wp;
86 static int did_intro = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020087#ifdef FEAT_GUI
Bram Moolenaare52e0c82020-02-28 22:20:10 +010088 int did_one = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020089 int did_undraw = FALSE;
90 int gui_cursor_col = 0;
91 int gui_cursor_row = 0;
92#endif
93 int no_update = FALSE;
Bram Moolenaare0c03c82021-04-23 21:01:34 +020094 int save_pum_will_redraw = pum_will_redraw;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020095
96 // Don't do anything if the screen structures are (not yet) valid.
97 if (!screen_valid(TRUE))
98 return FAIL;
99
Bram Moolenaara4d158b2022-08-14 14:17:45 +0100100 if (type == UPD_VALID_NO_UPDATE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200101 {
102 no_update = TRUE;
103 type = 0;
104 }
105
106#ifdef FEAT_EVAL
107 {
108 buf_T *buf;
109
110 // Before updating the screen, notify any listeners of changed text.
111 FOR_ALL_BUFFERS(buf)
112 invoke_listeners(buf);
113 }
114#endif
115
116#ifdef FEAT_DIFF
117 // May have postponed updating diffs.
118 if (need_diff_redraw)
119 diff_redraw(TRUE);
120#endif
121
122 if (must_redraw)
123 {
124 if (type < must_redraw) // use maximal type
125 type = must_redraw;
126
127 // must_redraw is reset here, so that when we run into some weird
128 // reason to redraw while busy redrawing (e.g., asynchronous
129 // scrolling), or update_topline() in win_update() will cause a
130 // scroll, the screen will be redrawn later or in win_update().
131 must_redraw = 0;
132 }
133
134 // May need to update w_lines[].
Bram Moolenaara4d158b2022-08-14 14:17:45 +0100135 if (curwin->w_lines_valid == 0 && type < UPD_NOT_VALID
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200136#ifdef FEAT_TERMINAL
137 && !term_do_update_window(curwin)
138#endif
139 )
Bram Moolenaara4d158b2022-08-14 14:17:45 +0100140 type = UPD_NOT_VALID;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200141
142 // Postpone the redrawing when it's not needed and when being called
143 // recursively.
144 if (!redrawing() || updating_screen)
145 {
146 redraw_later(type); // remember type for next time
147 must_redraw = type;
Bram Moolenaara4d158b2022-08-14 14:17:45 +0100148 if (type > UPD_INVERTED_ALL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200149 curwin->w_lines_valid = 0; // don't use w_lines[].wl_size now
150 return FAIL;
151 }
152 updating_screen = TRUE;
153
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100154#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200155 // Update popup_mask if needed. This may set w_redraw_top and w_redraw_bot
156 // in some windows.
157 may_update_popup_mask(type);
158#endif
159
160#ifdef FEAT_SYN_HL
161 ++display_tick; // let syntax code know we're in a next round of
162 // display updating
163#endif
164 if (no_update)
165 ++no_win_do_lines_ins;
166
167 // if the screen was scrolled up when displaying a message, scroll it down
168 if (msg_scrolled)
169 {
170 clear_cmdline = TRUE;
Bram Moolenaarf73e5ba2022-08-29 12:41:06 +0100171 if (type != UPD_CLEAR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200172 {
Bram Moolenaarf73e5ba2022-08-29 12:41:06 +0100173 if (msg_scrolled > Rows - 5) // redrawing is faster
Bram Moolenaarb13d3402022-08-29 13:44:28 +0100174 {
Bram Moolenaarf73e5ba2022-08-29 12:41:06 +0100175 type = UPD_NOT_VALID;
Bram Moolenaarb13d3402022-08-29 13:44:28 +0100176 redraw_as_cleared();
177 }
Bram Moolenaarf73e5ba2022-08-29 12:41:06 +0100178 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200179 {
Bram Moolenaarf73e5ba2022-08-29 12:41:06 +0100180 check_for_delay(FALSE);
181 if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, 0, NULL)
182 == FAIL)
Bram Moolenaarb13d3402022-08-29 13:44:28 +0100183 {
Bram Moolenaarf73e5ba2022-08-29 12:41:06 +0100184 type = UPD_NOT_VALID;
Bram Moolenaarb13d3402022-08-29 13:44:28 +0100185 redraw_as_cleared();
186 }
Bram Moolenaarf73e5ba2022-08-29 12:41:06 +0100187 FOR_ALL_WINDOWS(wp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200188 {
Bram Moolenaarf73e5ba2022-08-29 12:41:06 +0100189 if (wp->w_winrow < msg_scrolled)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200190 {
Bram Moolenaarf73e5ba2022-08-29 12:41:06 +0100191 if (W_WINROW(wp) + wp->w_height > msg_scrolled
192 && wp->w_redr_type < UPD_REDRAW_TOP
193 && wp->w_lines_valid > 0
194 && wp->w_topline == wp->w_lines[0].wl_lnum)
195 {
196 wp->w_upd_rows = msg_scrolled - W_WINROW(wp);
197 wp->w_redr_type = UPD_REDRAW_TOP;
198 }
199 else
200 {
201 wp->w_redr_type = UPD_NOT_VALID;
202 if (W_WINROW(wp) + wp->w_height
203 + wp->w_status_height <= msg_scrolled)
204 wp->w_redr_status = TRUE;
205 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200206 }
207 }
Bram Moolenaarf73e5ba2022-08-29 12:41:06 +0100208 if (!no_update)
209 redraw_cmdline = TRUE;
210 redraw_tabline = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200211 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200212 }
213 msg_scrolled = 0;
214 need_wait_return = FALSE;
215 }
216
217 // reset cmdline_row now (may have been changed temporarily)
218 compute_cmdrow();
219
220 // Check for changed highlighting
221 if (need_highlight_changed)
222 highlight_changed();
223
Bram Moolenaara4d158b2022-08-14 14:17:45 +0100224 if (type == UPD_CLEAR) // first clear screen
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200225 {
226 screenclear(); // will reset clear_cmdline
Bram Moolenaara4d158b2022-08-14 14:17:45 +0100227 type = UPD_NOT_VALID;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200228 // must_redraw may be set indirectly, avoid another redraw later
229 must_redraw = 0;
230 }
231
232 if (clear_cmdline) // going to clear cmdline (done below)
233 check_for_delay(FALSE);
234
235#ifdef FEAT_LINEBREAK
236 // Force redraw when width of 'number' or 'relativenumber' column
237 // changes.
Bram Moolenaara4d158b2022-08-14 14:17:45 +0100238 if (curwin->w_redr_type < UPD_NOT_VALID
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200239 && curwin->w_nrwidth != ((curwin->w_p_nu || curwin->w_p_rnu)
240 ? number_width(curwin) : 0))
Bram Moolenaara4d158b2022-08-14 14:17:45 +0100241 curwin->w_redr_type = UPD_NOT_VALID;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200242#endif
243
244 // Only start redrawing if there is really something to do.
Bram Moolenaara4d158b2022-08-14 14:17:45 +0100245 if (type == UPD_INVERTED)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200246 update_curswant();
247 if (curwin->w_redr_type < type
Bram Moolenaara4d158b2022-08-14 14:17:45 +0100248 && !((type == UPD_VALID
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200249 && curwin->w_lines[0].wl_valid
250#ifdef FEAT_DIFF
251 && curwin->w_topfill == curwin->w_old_topfill
252 && curwin->w_botfill == curwin->w_old_botfill
253#endif
254 && curwin->w_topline == curwin->w_lines[0].wl_lnum)
Bram Moolenaara4d158b2022-08-14 14:17:45 +0100255 || (type == UPD_INVERTED
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200256 && VIsual_active
257 && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum
258 && curwin->w_old_visual_mode == VIsual_mode
259 && (curwin->w_valid & VALID_VIRTCOL)
260 && curwin->w_old_curswant == curwin->w_curswant)
261 ))
262 curwin->w_redr_type = type;
263
264 // Redraw the tab pages line if needed.
Bram Moolenaara4d158b2022-08-14 14:17:45 +0100265 if (redraw_tabline || type >= UPD_NOT_VALID)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200266 draw_tabline();
267
268#ifdef FEAT_SYN_HL
269 // Correct stored syntax highlighting info for changes in each displayed
270 // buffer. Each buffer must only be done once.
271 FOR_ALL_WINDOWS(wp)
272 {
273 if (wp->w_buffer->b_mod_set)
274 {
275 win_T *wwp;
276
277 // Check if we already did this buffer.
278 for (wwp = firstwin; wwp != wp; wwp = wwp->w_next)
279 if (wwp->w_buffer == wp->w_buffer)
280 break;
281 if (wwp == wp && syntax_present(wp))
282 syn_stack_apply_changes(wp->w_buffer);
283 }
284 }
285#endif
286
Bram Moolenaare0c03c82021-04-23 21:01:34 +0200287 if (pum_redraw_in_same_position())
288 // Avoid flicker if the popup menu is going to be redrawn in the same
289 // position.
290 pum_will_redraw = TRUE;
291
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200292 // Go from top to bottom through the windows, redrawing the ones that need
293 // it.
294#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
Bram Moolenaare52e0c82020-02-28 22:20:10 +0100295 did_update_one_window = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200296#endif
297#ifdef FEAT_SEARCH_EXTRA
298 screen_search_hl.rm.regprog = NULL;
299#endif
300 FOR_ALL_WINDOWS(wp)
301 {
302 if (wp->w_redr_type != 0)
303 {
304 cursor_off();
Bram Moolenaare52e0c82020-02-28 22:20:10 +0100305#ifdef FEAT_GUI
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200306 if (!did_one)
307 {
308 did_one = TRUE;
Bram Moolenaare52e0c82020-02-28 22:20:10 +0100309
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200310 // Remove the cursor before starting to do anything, because
311 // scrolling may make it difficult to redraw the text under
312 // it.
Bram Moolenaar09f067f2021-04-11 13:29:18 +0200313 // Also remove the cursor if it needs to be hidden due to an
314 // ongoing cursor-less sleep.
315 if (gui.in_use && (wp == curwin || cursor_is_sleeping()))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200316 {
317 gui_cursor_col = gui.cursor_col;
318 gui_cursor_row = gui.cursor_row;
319 gui_undraw_cursor();
320 did_undraw = TRUE;
321 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200322 }
323#endif
324 win_update(wp);
325 }
326
327 // redraw status line after the window to minimize cursor movement
328 if (wp->w_redr_status)
329 {
330 cursor_off();
331 win_redr_status(wp, TRUE); // any popup menu will be redrawn below
332 }
333 }
334#if defined(FEAT_SEARCH_EXTRA)
335 end_search_hl();
336#endif
Bram Moolenaare0c03c82021-04-23 21:01:34 +0200337
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200338 // May need to redraw the popup menu.
Bram Moolenaare0c03c82021-04-23 21:01:34 +0200339 pum_will_redraw = save_pum_will_redraw;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200340 pum_may_redraw();
341
342 // Reset b_mod_set flags. Going through all windows is probably faster
343 // than going through all buffers (there could be many buffers).
344 FOR_ALL_WINDOWS(wp)
345 wp->w_buffer->b_mod_set = FALSE;
346
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100347#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200348 // Display popup windows on top of the windows and command line.
349 update_popups(win_update);
350#endif
351
Bram Moolenaar3194e5b2021-12-13 21:59:09 +0000352#ifdef FEAT_TERMINAL
353 FOR_ALL_WINDOWS(wp)
354 // If this window contains a terminal, after redrawing all windows, the
355 // dirty row range can be reset.
356 term_did_update_window(wp);
357#endif
358
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200359 after_updating_screen(TRUE);
360
361 // Clear or redraw the command line. Done last, because scrolling may
362 // mess up the command line.
363 if (clear_cmdline || redraw_cmdline || redraw_mode)
364 showmode();
365
366 if (no_update)
367 --no_win_do_lines_ins;
368
369 // May put up an introductory message when not editing a file
370 if (!did_intro)
371 maybe_intro_message();
372 did_intro = TRUE;
373
374#ifdef FEAT_GUI
375 // Redraw the cursor and update the scrollbars when all screen updating is
376 // done.
377 if (gui.in_use)
378 {
379 if (did_undraw && !gui_mch_is_blink_off())
380 {
381 mch_disable_flush();
382 out_flush(); // required before updating the cursor
383 mch_enable_flush();
384
385 // Put the GUI position where the cursor was, gui_update_cursor()
386 // uses that.
387 gui.col = gui_cursor_col;
388 gui.row = gui_cursor_row;
389 gui.col = mb_fix_col(gui.col, gui.row);
390 gui_update_cursor(FALSE, FALSE);
391 gui_may_flush();
392 screen_cur_col = gui.col;
393 screen_cur_row = gui.row;
394 }
395 else
396 out_flush();
397 gui_update_scrollbars(FALSE);
398 }
399#endif
400 return OK;
401}
402
403/*
Bram Moolenaarae0f1512021-03-30 22:12:12 +0200404 * Return the row for drawing the statusline and the ruler of window "wp".
405 */
Bram Moolenaar49c51b82021-04-01 16:16:18 +0200406 int
Bram Moolenaarae0f1512021-03-30 22:12:12 +0200407statusline_row(win_T *wp)
408{
409#if defined(FEAT_PROP_POPUP)
410 // If the window is really zero height the winbar isn't displayed.
411 if (wp->w_frame->fr_height == wp->w_status_height && !popup_is_popup(wp))
412 return wp->w_winrow;
413#endif
414 return W_WINROW(wp) + wp->w_height;
415}
416
417/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200418 * Redraw the status line of window wp.
419 *
420 * If inversion is possible we use it. Else '=' characters are used.
421 * If "ignore_pum" is TRUE, also redraw statusline when the popup menu is
422 * displayed.
423 */
Luuk van Baalba936f62022-12-15 13:15:39 +0000424 void
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200425win_redr_status(win_T *wp, int ignore_pum UNUSED)
426{
427 int row;
428 char_u *p;
429 int len;
430 int fillchar;
431 int attr;
432 int this_ru_col;
433 static int busy = FALSE;
434
435 // It's possible to get here recursively when 'statusline' (indirectly)
436 // invokes ":redrawstatus". Simply ignore the call then.
437 if (busy)
438 return;
439 busy = TRUE;
440
Bram Moolenaarae0f1512021-03-30 22:12:12 +0200441 row = statusline_row(wp);
442
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200443 wp->w_redr_status = FALSE;
444 if (wp->w_status_height == 0)
445 {
446 // no status line, can only be last window
447 redraw_cmdline = TRUE;
448 }
449 else if (!redrawing()
450 // don't update status line when popup menu is visible and may be
451 // drawn over it, unless it will be redrawn later
452 || (!ignore_pum && pum_visible()))
453 {
454 // Don't redraw right now, do it later.
455 wp->w_redr_status = TRUE;
456 }
457#ifdef FEAT_STL_OPT
458 else if (*p_stl != NUL || *wp->w_p_stl != NUL)
459 {
460 // redraw custom status line
461 redraw_custom_statusline(wp);
462 }
463#endif
464 else
465 {
466 fillchar = fillchar_status(&attr, wp);
467
468 get_trans_bufname(wp->w_buffer);
469 p = NameBuff;
470 len = (int)STRLEN(p);
471
Bram Moolenaarde05bb22022-01-13 13:08:14 +0000472 if ((bt_help(wp->w_buffer)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200473#ifdef FEAT_QUICKFIX
Bram Moolenaarde05bb22022-01-13 13:08:14 +0000474 || wp->w_p_pvw
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200475#endif
Bram Moolenaarde05bb22022-01-13 13:08:14 +0000476 || bufIsChanged(wp->w_buffer)
477 || wp->w_buffer->b_p_ro)
478 && len < MAXPATHL - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200479 *(p + len++) = ' ';
480 if (bt_help(wp->w_buffer))
481 {
Bram Moolenaar826bfe42021-10-08 18:39:28 +0100482 vim_snprintf((char *)p + len, MAXPATHL - len, "%s", _("[Help]"));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200483 len += (int)STRLEN(p + len);
484 }
485#ifdef FEAT_QUICKFIX
486 if (wp->w_p_pvw)
487 {
Bram Moolenaar826bfe42021-10-08 18:39:28 +0100488 vim_snprintf((char *)p + len, MAXPATHL - len, "%s", _("[Preview]"));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200489 len += (int)STRLEN(p + len);
490 }
491#endif
Bram Moolenaar6d4b2f52022-08-25 15:11:15 +0100492 if (bufIsChanged(wp->w_buffer) && !bt_terminal(wp->w_buffer))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200493 {
Bram Moolenaar826bfe42021-10-08 18:39:28 +0100494 vim_snprintf((char *)p + len, MAXPATHL - len, "%s", "[+]");
495 len += (int)STRLEN(p + len);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200496 }
497 if (wp->w_buffer->b_p_ro)
498 {
Bram Moolenaar826bfe42021-10-08 18:39:28 +0100499 vim_snprintf((char *)p + len, MAXPATHL - len, "%s", _("[RO]"));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200500 len += (int)STRLEN(p + len);
501 }
502
503 this_ru_col = ru_col - (Columns - wp->w_width);
504 if (this_ru_col < (wp->w_width + 1) / 2)
505 this_ru_col = (wp->w_width + 1) / 2;
506 if (this_ru_col <= 1)
507 {
508 p = (char_u *)"<"; // No room for file name!
509 len = 1;
510 }
511 else if (has_mbyte)
512 {
513 int clen = 0, i;
514
515 // Count total number of display cells.
516 clen = mb_string2cells(p, -1);
517
518 // Find first character that will fit.
519 // Going from start to end is much faster for DBCS.
520 for (i = 0; p[i] != NUL && clen >= this_ru_col - 1;
521 i += (*mb_ptr2len)(p + i))
522 clen -= (*mb_ptr2cells)(p + i);
523 len = clen;
524 if (i > 0)
525 {
526 p = p + i - 1;
527 *p = '<';
528 ++len;
529 }
530
531 }
532 else if (len > this_ru_col - 1)
533 {
534 p += len - (this_ru_col - 1);
535 *p = '<';
536 len = this_ru_col - 1;
537 }
538
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200539 screen_puts(p, row, wp->w_wincol, attr);
540 screen_fill(row, row + 1, len + wp->w_wincol,
541 this_ru_col + wp->w_wincol, fillchar, fillchar, attr);
542
543 if (get_keymap_str(wp, (char_u *)"<%s>", NameBuff, MAXPATHL)
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +0000544 && (this_ru_col - len) > (int)(STRLEN(NameBuff) + 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200545 screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff)
546 - 1 + wp->w_wincol), attr);
547
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200548 win_redr_ruler(wp, TRUE, ignore_pum);
Luuk van Baalba936f62022-12-15 13:15:39 +0000549
550 // Draw the 'showcmd' information if 'showcmdloc' == "statusline".
551 if (p_sc && *p_sloc == 's')
552 {
553 int width = MIN(10, this_ru_col - len - 2);
554
555 if (width > 0)
556 screen_puts_len(showcmd_buf, width, row,
557 wp->w_wincol + this_ru_col - width - 1, attr);
558 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200559 }
560
561 /*
562 * May need to draw the character below the vertical separator.
563 */
564 if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing())
565 {
566 if (stl_connected(wp))
567 fillchar = fillchar_status(&attr, wp);
568 else
Bram Moolenaar96ba25a2022-07-04 17:34:33 +0100569 fillchar = fillchar_vsep(&attr, wp);
Bram Moolenaarae0f1512021-03-30 22:12:12 +0200570 screen_putchar(fillchar, row, W_ENDCOL(wp), attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200571 }
572 busy = FALSE;
573}
574
575#ifdef FEAT_STL_OPT
576/*
577 * Redraw the status line according to 'statusline' and take care of any
578 * errors encountered.
579 */
580 static void
581redraw_custom_statusline(win_T *wp)
582{
583 static int entered = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200584
585 // When called recursively return. This can happen when the statusline
586 // contains an expression that triggers a redraw.
587 if (entered)
588 return;
589 entered = TRUE;
590
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200591 win_redr_custom(wp, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200592 entered = FALSE;
593}
594#endif
595
596/*
597 * Show current status info in ruler and various other places
598 * If always is FALSE, only show ruler if position has changed.
599 */
600 void
601showruler(int always)
602{
603 if (!always && !redrawing())
604 return;
605 if (pum_visible())
606 {
607 // Don't redraw right now, do it later.
608 curwin->w_redr_status = TRUE;
609 return;
610 }
611#if defined(FEAT_STL_OPT)
612 if ((*p_stl != NUL || *curwin->w_p_stl != NUL) && curwin->w_status_height)
613 redraw_custom_statusline(curwin);
614 else
615#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200616 win_redr_ruler(curwin, always, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200617
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200618 if (need_maketitle
Bram Moolenaar651fca82021-11-29 20:39:38 +0000619#ifdef FEAT_STL_OPT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200620 || (p_icon && (stl_syntax & STL_IN_ICON))
621 || (p_title && (stl_syntax & STL_IN_TITLE))
Bram Moolenaar651fca82021-11-29 20:39:38 +0000622#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200623 )
624 maketitle();
Bram Moolenaar651fca82021-11-29 20:39:38 +0000625
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200626 // Redraw the tab pages line if needed.
627 if (redraw_tabline)
628 draw_tabline();
629}
630
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200631 void
632win_redr_ruler(win_T *wp, int always, int ignore_pum)
633{
634#define RULER_BUF_LEN 70
635 char_u buffer[RULER_BUF_LEN];
636 int row;
637 int fillchar;
638 int attr;
639 int empty_line = FALSE;
640 colnr_T virtcol;
641 int i;
642 size_t len;
643 int o;
644 int this_ru_col;
645 int off = 0;
646 int width;
647
Bram Moolenaara2a89732022-08-31 14:46:18 +0100648 // If 'ruler' off don't do anything
649 if (!p_ru)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200650 return;
651
652 /*
653 * Check if cursor.lnum is valid, since win_redr_ruler() may be called
654 * after deleting lines, before cursor.lnum is corrected.
655 */
656 if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count)
657 return;
658
659 // Don't draw the ruler while doing insert-completion, it might overwrite
660 // the (long) mode message.
661 if (wp == lastwin && lastwin->w_status_height == 0)
662 if (edit_submode != NULL)
663 return;
664 // Don't draw the ruler when the popup menu is visible, it may overlap.
665 // Except when the popup menu will be redrawn anyway.
666 if (!ignore_pum && pum_visible())
667 return;
668
669#ifdef FEAT_STL_OPT
Bram Moolenaara2a89732022-08-31 14:46:18 +0100670 if (*p_ruf)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200671 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200672 win_redr_custom(wp, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200673 return;
674 }
675#endif
676
677 /*
678 * Check if not in Insert mode and the line is empty (will show "0-1").
679 */
Bram Moolenaar24959102022-05-07 20:01:16 +0100680 if ((State & MODE_INSERT) == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200681 && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL)
682 empty_line = TRUE;
683
684 /*
685 * Only draw the ruler when something changed.
686 */
687 validate_virtcol_win(wp);
688 if ( redraw_cmdline
689 || always
690 || wp->w_cursor.lnum != wp->w_ru_cursor.lnum
691 || wp->w_cursor.col != wp->w_ru_cursor.col
692 || wp->w_virtcol != wp->w_ru_virtcol
693 || wp->w_cursor.coladd != wp->w_ru_cursor.coladd
694 || wp->w_topline != wp->w_ru_topline
695 || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count
696#ifdef FEAT_DIFF
697 || wp->w_topfill != wp->w_ru_topfill
698#endif
699 || empty_line != wp->w_ru_empty)
700 {
701 cursor_off();
702 if (wp->w_status_height)
703 {
Bram Moolenaarae0f1512021-03-30 22:12:12 +0200704 row = statusline_row(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200705 fillchar = fillchar_status(&attr, wp);
706 off = wp->w_wincol;
707 width = wp->w_width;
708 }
709 else
710 {
711 row = Rows - 1;
712 fillchar = ' ';
713 attr = 0;
714 width = Columns;
715 off = 0;
716 }
717
718 // In list mode virtcol needs to be recomputed
719 virtcol = wp->w_virtcol;
Bram Moolenaareed9d462021-02-15 20:38:25 +0100720 if (wp->w_p_list && wp->w_lcs_chars.tab1 == NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200721 {
722 wp->w_p_list = FALSE;
723 getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL);
724 wp->w_p_list = TRUE;
725 }
726
727 /*
728 * Some sprintfs return the length, some return a pointer.
729 * To avoid portability problems we use strlen() here.
730 */
731 vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,",
732 (wp->w_buffer->b_ml.ml_flags & ML_EMPTY)
733 ? 0L
734 : (long)(wp->w_cursor.lnum));
735 len = STRLEN(buffer);
736 col_print(buffer + len, RULER_BUF_LEN - len,
737 empty_line ? 0 : (int)wp->w_cursor.col + 1,
738 (int)virtcol + 1);
739
740 /*
741 * Add a "50%" if there is room for it.
742 * On the last line, don't print in the last column (scrolls the
743 * screen up on some terminals).
744 */
745 i = (int)STRLEN(buffer);
746 get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1);
747 o = i + vim_strsize(buffer + i + 1);
748 if (wp->w_status_height == 0) // can't use last char of screen
749 ++o;
750 this_ru_col = ru_col - (Columns - width);
751 if (this_ru_col < 0)
752 this_ru_col = 0;
753 // Never use more than half the window/screen width, leave the other
754 // half for the filename.
755 if (this_ru_col < (width + 1) / 2)
756 this_ru_col = (width + 1) / 2;
757 if (this_ru_col + o < width)
758 {
759 // need at least 3 chars left for get_rel_pos() + NUL
760 while (this_ru_col + o < width && RULER_BUF_LEN > i + 4)
761 {
762 if (has_mbyte)
763 i += (*mb_char2bytes)(fillchar, buffer + i);
764 else
765 buffer[i++] = fillchar;
766 ++o;
767 }
768 get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i);
769 }
770 // Truncate at window boundary.
771 if (has_mbyte)
772 {
773 o = 0;
774 for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i))
775 {
776 o += (*mb_ptr2cells)(buffer + i);
777 if (this_ru_col + o > width)
778 {
779 buffer[i] = NUL;
780 break;
781 }
782 }
783 }
784 else if (this_ru_col + (int)STRLEN(buffer) > width)
785 buffer[width - this_ru_col] = NUL;
786
787 screen_puts(buffer, row, this_ru_col + off, attr);
788 i = redraw_cmdline;
789 screen_fill(row, row + 1,
790 this_ru_col + off + (int)STRLEN(buffer),
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +0000791 (off + width),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200792 fillchar, fillchar, attr);
793 // don't redraw the cmdline because of showing the ruler
794 redraw_cmdline = i;
795 wp->w_ru_cursor = wp->w_cursor;
796 wp->w_ru_virtcol = wp->w_virtcol;
797 wp->w_ru_empty = empty_line;
798 wp->w_ru_topline = wp->w_topline;
799 wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count;
800#ifdef FEAT_DIFF
801 wp->w_ru_topfill = wp->w_topfill;
802#endif
803 }
804}
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200805
806/*
807 * To be called when "updating_screen" was set before and now the postponed
808 * side effects may take place.
809 */
810 void
811after_updating_screen(int may_resize_shell UNUSED)
812{
813 updating_screen = FALSE;
814#ifdef FEAT_GUI
815 if (may_resize_shell)
816 gui_may_resize_shell();
817#endif
818#ifdef FEAT_TERMINAL
819 term_check_channel_closed_recently();
820#endif
821
822#ifdef HAVE_DROP_FILE
823 // If handle_drop() was called while updating_screen was TRUE need to
824 // handle the drop now.
825 handle_any_postponed_drop();
826#endif
827}
828
829/*
830 * Update all windows that are editing the current buffer.
831 */
832 void
833update_curbuf(int type)
834{
835 redraw_curbuf_later(type);
836 update_screen(type);
837}
838
839#if defined(FEAT_MENU) || defined(FEAT_FOLDING)
840/*
841 * Copy "text" to ScreenLines using "attr".
842 * Returns the next screen column.
843 */
844 static int
845text_to_screenline(win_T *wp, char_u *text, int col)
846{
847 int off = (int)(current_ScreenLine - ScreenLines);
848
849 if (has_mbyte)
850 {
851 int cells;
852 int u8c, u8cc[MAX_MCO];
853 int i;
854 int idx;
855 int c_len;
856 char_u *p;
857# ifdef FEAT_ARABIC
858 int prev_c = 0; // previous Arabic character
859 int prev_c1 = 0; // first composing char for prev_c
860# endif
861
862# ifdef FEAT_RIGHTLEFT
863 if (wp->w_p_rl)
864 idx = off;
865 else
866# endif
867 idx = off + col;
868
869 // Store multibyte characters in ScreenLines[] et al. correctly.
870 for (p = text; *p != NUL; )
871 {
872 cells = (*mb_ptr2cells)(p);
873 c_len = (*mb_ptr2len)(p);
874 if (col + cells > wp->w_width
875# ifdef FEAT_RIGHTLEFT
876 - (wp->w_p_rl ? col : 0)
877# endif
878 )
879 break;
880 ScreenLines[idx] = *p;
881 if (enc_utf8)
882 {
883 u8c = utfc_ptr2char(p, u8cc);
884 if (*p < 0x80 && u8cc[0] == 0)
885 {
886 ScreenLinesUC[idx] = 0;
887#ifdef FEAT_ARABIC
888 prev_c = u8c;
889#endif
890 }
891 else
892 {
893#ifdef FEAT_ARABIC
894 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c))
895 {
896 // Do Arabic shaping.
897 int pc, pc1, nc;
898 int pcc[MAX_MCO];
899 int firstbyte = *p;
900
901 // The idea of what is the previous and next
902 // character depends on 'rightleft'.
903 if (wp->w_p_rl)
904 {
905 pc = prev_c;
906 pc1 = prev_c1;
907 nc = utf_ptr2char(p + c_len);
908 prev_c1 = u8cc[0];
909 }
910 else
911 {
912 pc = utfc_ptr2char(p + c_len, pcc);
913 nc = prev_c;
914 pc1 = pcc[0];
915 }
916 prev_c = u8c;
917
918 u8c = arabic_shape(u8c, &firstbyte, &u8cc[0],
919 pc, pc1, nc);
920 ScreenLines[idx] = firstbyte;
921 }
922 else
923 prev_c = u8c;
924#endif
925 // Non-BMP character: display as ? or fullwidth ?.
926 ScreenLinesUC[idx] = u8c;
927 for (i = 0; i < Screen_mco; ++i)
928 {
929 ScreenLinesC[i][idx] = u8cc[i];
930 if (u8cc[i] == 0)
931 break;
932 }
933 }
934 if (cells > 1)
935 ScreenLines[idx + 1] = 0;
936 }
937 else if (enc_dbcs == DBCS_JPNU && *p == 0x8e)
938 // double-byte single width character
939 ScreenLines2[idx] = p[1];
940 else if (cells > 1)
941 // double-width character
942 ScreenLines[idx + 1] = p[1];
943 col += cells;
944 idx += cells;
945 p += c_len;
946 }
947 }
948 else
949 {
950 int len = (int)STRLEN(text);
951
952 if (len > wp->w_width - col)
953 len = wp->w_width - col;
954 if (len > 0)
955 {
956#ifdef FEAT_RIGHTLEFT
957 if (wp->w_p_rl)
958 mch_memmove(current_ScreenLine, text, len);
959 else
960#endif
961 mch_memmove(current_ScreenLine + col, text, len);
962 col += len;
963 }
964 }
965 return col;
966}
967#endif
968
969#ifdef FEAT_MENU
970/*
971 * Draw the window toolbar.
972 */
973 static void
974redraw_win_toolbar(win_T *wp)
975{
976 vimmenu_T *menu;
977 int item_idx = 0;
978 int item_count = 0;
979 int col = 0;
980 int next_col;
981 int off = (int)(current_ScreenLine - ScreenLines);
982 int fill_attr = syn_name2attr((char_u *)"ToolbarLine");
983 int button_attr = syn_name2attr((char_u *)"ToolbarButton");
984
985 vim_free(wp->w_winbar_items);
Bram Moolenaar00d253e2020-04-06 22:13:01 +0200986 FOR_ALL_CHILD_MENUS(wp->w_winbar, menu)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200987 ++item_count;
988 wp->w_winbar_items = ALLOC_CLEAR_MULT(winbar_item_T, item_count + 1);
989
990 // TODO: use fewer spaces if there is not enough room
991 for (menu = wp->w_winbar->children;
992 menu != NULL && col < wp->w_width; menu = menu->next)
993 {
994 space_to_screenline(off + col, fill_attr);
995 if (++col >= wp->w_width)
996 break;
997 if (col > 1)
998 {
999 space_to_screenline(off + col, fill_attr);
1000 if (++col >= wp->w_width)
1001 break;
1002 }
1003
1004 wp->w_winbar_items[item_idx].wb_startcol = col;
1005 space_to_screenline(off + col, button_attr);
1006 if (++col >= wp->w_width)
1007 break;
1008
1009 next_col = text_to_screenline(wp, menu->name, col);
1010 while (col < next_col)
1011 {
1012 ScreenAttrs[off + col] = button_attr;
1013 ++col;
1014 }
1015 wp->w_winbar_items[item_idx].wb_endcol = col;
1016 wp->w_winbar_items[item_idx].wb_menu = menu;
1017 ++item_idx;
1018
1019 if (col >= wp->w_width)
1020 break;
1021 space_to_screenline(off + col, button_attr);
1022 ++col;
1023 }
1024 while (col < wp->w_width)
1025 {
1026 space_to_screenline(off + col, fill_attr);
1027 ++col;
1028 }
1029 wp->w_winbar_items[item_idx].wb_menu = NULL; // end marker
1030
zeertzjqd0c1b772024-03-16 15:03:33 +01001031 screen_line(wp, wp->w_winrow, wp->w_wincol, wp->w_width, wp->w_width, -1,
1032 0);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001033}
1034#endif
1035
1036#if defined(FEAT_FOLDING) || defined(PROTO)
1037/*
1038 * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr".
1039 */
1040 static void
1041copy_text_attr(
1042 int off,
1043 char_u *buf,
1044 int len,
1045 int attr)
1046{
1047 int i;
1048
1049 mch_memmove(ScreenLines + off, buf, (size_t)len);
1050 if (enc_utf8)
1051 vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len);
1052 for (i = 0; i < len; ++i)
1053 ScreenAttrs[off + i] = attr;
1054}
1055
1056/*
1057 * Display one folded line.
1058 */
1059 static void
1060fold_line(
1061 win_T *wp,
1062 long fold_count,
1063 foldinfo_T *foldinfo,
1064 linenr_T lnum,
1065 int row)
1066{
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001067 // Max value of 'foldcolumn' is 12 and maximum number of bytes in a
1068 // multi-byte character is MAX_MCO.
1069 char_u buf[MAX_MCO * 12 + 1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001070 pos_T *top, *bot;
1071 linenr_T lnume = lnum + fold_count - 1;
1072 int len;
1073 char_u *text;
1074 int fdc;
1075 int col;
1076 int txtcol;
1077 int off = (int)(current_ScreenLine - ScreenLines);
1078 int ri;
1079
1080 // Build the fold line:
1081 // 1. Add the cmdwin_type for the command-line window
1082 // 2. Add the 'foldcolumn'
1083 // 3. Add the 'number' or 'relativenumber' column
1084 // 4. Compose the text
1085 // 5. Add the text
1086 // 6. set highlighting for the Visual area an other text
1087 col = 0;
1088
1089 // 1. Add the cmdwin_type for the command-line window
1090 // Ignores 'rightleft', this window is never right-left.
Sean Dewar988f7432023-08-16 14:17:36 +01001091 if (wp == cmdwin_win)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001092 {
1093 ScreenLines[off] = cmdwin_type;
1094 ScreenAttrs[off] = HL_ATTR(HLF_AT);
1095 if (enc_utf8)
1096 ScreenLinesUC[off] = 0;
1097 ++col;
1098 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001099
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001100#ifdef FEAT_RIGHTLEFT
1101# define RL_MEMSET(p, v, l) \
1102 do { \
1103 if (wp->w_p_rl) \
kylo252ae6f1d82022-02-16 19:24:07 +00001104 for (ri = 0; ri < (l); ++ri) \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001105 ScreenAttrs[off + (wp->w_width - (p) - (l)) + ri] = v; \
1106 else \
kylo252ae6f1d82022-02-16 19:24:07 +00001107 for (ri = 0; ri < (l); ++ri) \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001108 ScreenAttrs[off + (p) + ri] = v; \
1109 } while (0)
1110#else
1111# define RL_MEMSET(p, v, l) \
1112 do { \
1113 for (ri = 0; ri < l; ++ri) \
1114 ScreenAttrs[off + (p) + ri] = v; \
1115 } while (0)
1116#endif
1117
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001118 // 2. Add the 'foldcolumn'
1119 // Reduce the width when there is not enough space.
1120 fdc = compute_foldcolumn(wp, col);
1121 if (fdc > 0)
1122 {
1123 char_u *p;
1124 int i;
1125 int idx;
1126
1127 fill_foldcolumn(buf, wp, TRUE, lnum);
1128 p = buf;
1129 for (i = 0; i < fdc; i++)
1130 {
1131 int ch;
1132
1133 if (has_mbyte)
1134 ch = mb_ptr2char_adv(&p);
1135 else
1136 ch = *p++;
1137#ifdef FEAT_RIGHTLEFT
1138 if (wp->w_p_rl)
1139 idx = off + wp->w_width - i - 1 - col;
1140 else
1141#endif
1142 idx = off + col + i;
1143 if (enc_utf8)
1144 {
1145 if (ch >= 0x80)
1146 {
1147 ScreenLinesUC[idx] = ch;
1148 ScreenLinesC[0][idx] = 0;
1149 ScreenLines[idx] = 0x80;
1150 }
1151 else
1152 {
1153 ScreenLines[idx] = ch;
1154 ScreenLinesUC[idx] = 0;
1155 }
1156 }
1157 else
1158 ScreenLines[idx] = ch;
1159 }
1160
1161 RL_MEMSET(col, HL_ATTR(HLF_FC), fdc);
1162 col += fdc;
1163 }
1164
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001165 // Set all attributes of the 'number' or 'relativenumber' column and the
1166 // text
1167 RL_MEMSET(col, HL_ATTR(HLF_FL), wp->w_width - col);
1168
1169#ifdef FEAT_SIGNS
1170 // If signs are being displayed, add two spaces.
1171 if (signcolumn_on(wp))
1172 {
1173 len = wp->w_width - col;
1174 if (len > 0)
1175 {
1176 if (len > 2)
1177 len = 2;
1178# ifdef FEAT_RIGHTLEFT
1179 if (wp->w_p_rl)
1180 // the line number isn't reversed
1181 copy_text_attr(off + wp->w_width - len - col,
1182 (char_u *)" ", len, HL_ATTR(HLF_FL));
1183 else
1184# endif
1185 copy_text_attr(off + col, (char_u *)" ", len, HL_ATTR(HLF_FL));
1186 col += len;
1187 }
1188 }
1189#endif
1190
1191 // 3. Add the 'number' or 'relativenumber' column
1192 if (wp->w_p_nu || wp->w_p_rnu)
1193 {
1194 len = wp->w_width - col;
1195 if (len > 0)
1196 {
1197 int w = number_width(wp);
1198 long num;
1199 char *fmt = "%*ld ";
1200
1201 if (len > w + 1)
1202 len = w + 1;
1203
1204 if (wp->w_p_nu && !wp->w_p_rnu)
1205 // 'number' + 'norelativenumber'
1206 num = (long)lnum;
1207 else
1208 {
1209 // 'relativenumber', don't use negative numbers
1210 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1211 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1212 {
1213 // 'number' + 'relativenumber': cursor line shows absolute
1214 // line number
1215 num = lnum;
1216 fmt = "%-*ld ";
1217 }
1218 }
1219
1220 sprintf((char *)buf, fmt, w, num);
1221#ifdef FEAT_RIGHTLEFT
1222 if (wp->w_p_rl)
1223 // the line number isn't reversed
1224 copy_text_attr(off + wp->w_width - len - col, buf, len,
1225 HL_ATTR(HLF_FL));
1226 else
1227#endif
1228 copy_text_attr(off + col, buf, len, HL_ATTR(HLF_FL));
1229 col += len;
1230 }
1231 }
1232
1233 // 4. Compose the folded-line string with 'foldtext', if set.
1234 text = get_foldtext(wp, lnum, lnume, foldinfo, buf);
1235
1236 txtcol = col; // remember where text starts
1237
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001238 // 5. move the text to current_ScreenLine. Fill up with "fold" from
1239 // 'fillchars'.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001240 // Right-left text is put in columns 0 - number-col, normal text is put
1241 // in columns number-col - window-width.
1242 col = text_to_screenline(wp, text, col);
1243
1244 // Fill the rest of the line with the fold filler
1245#ifdef FEAT_RIGHTLEFT
1246 if (wp->w_p_rl)
1247 col -= txtcol;
1248#endif
1249 while (col < wp->w_width
1250#ifdef FEAT_RIGHTLEFT
1251 - (wp->w_p_rl ? txtcol : 0)
1252#endif
1253 )
1254 {
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001255 int c = wp->w_fill_chars.fold;
1256
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001257 if (enc_utf8)
1258 {
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001259 if (c >= 0x80)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001260 {
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001261 ScreenLinesUC[off + col] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001262 ScreenLinesC[0][off + col] = 0;
1263 ScreenLines[off + col] = 0x80; // avoid storing zero
1264 }
1265 else
1266 {
1267 ScreenLinesUC[off + col] = 0;
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001268 ScreenLines[off + col] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001269 }
1270 col++;
1271 }
1272 else
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001273 ScreenLines[off + col++] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001274 }
1275
1276 if (text != buf)
1277 vim_free(text);
1278
1279 // 6. set highlighting for the Visual area an other text.
1280 // If all folded lines are in the Visual area, highlight the line.
1281 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1282 {
1283 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1284 {
1285 // Visual is after curwin->w_cursor
1286 top = &curwin->w_cursor;
1287 bot = &VIsual;
1288 }
1289 else
1290 {
1291 // Visual is before curwin->w_cursor
1292 top = &VIsual;
1293 bot = &curwin->w_cursor;
1294 }
1295 if (lnum >= top->lnum
1296 && lnume <= bot->lnum
1297 && (VIsual_mode != 'v'
1298 || ((lnum > top->lnum
1299 || (lnum == top->lnum
1300 && top->col == 0))
1301 && (lnume < bot->lnum
1302 || (lnume == bot->lnum
1303 && (bot->col - (*p_sel == 'e'))
zeertzjq94b7c322024-03-12 21:50:32 +01001304 >= ml_get_buf_len(wp->w_buffer, lnume))))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001305 {
1306 if (VIsual_mode == Ctrl_V)
1307 {
1308 // Visual block mode: highlight the chars part of the block
1309 if (wp->w_old_cursor_fcol + txtcol < (colnr_T)wp->w_width)
1310 {
1311 if (wp->w_old_cursor_lcol != MAXCOL
1312 && wp->w_old_cursor_lcol + txtcol
1313 < (colnr_T)wp->w_width)
1314 len = wp->w_old_cursor_lcol;
1315 else
1316 len = wp->w_width - txtcol;
1317 RL_MEMSET(wp->w_old_cursor_fcol + txtcol, HL_ATTR(HLF_V),
1318 len - (int)wp->w_old_cursor_fcol);
1319 }
1320 }
1321 else
1322 {
1323 // Set all attributes of the text
1324 RL_MEMSET(txtcol, HL_ATTR(HLF_V), wp->w_width - txtcol);
1325 }
1326 }
1327 }
1328
1329#ifdef FEAT_SYN_HL
1330 // Show colorcolumn in the fold line, but let cursorcolumn override it.
1331 if (wp->w_p_cc_cols)
1332 {
1333 int i = 0;
1334 int j = wp->w_p_cc_cols[i];
1335 int old_txtcol = txtcol;
1336
1337 while (j > -1)
1338 {
1339 txtcol += j;
1340 if (wp->w_p_wrap)
1341 txtcol -= wp->w_skipcol;
1342 else
1343 txtcol -= wp->w_leftcol;
1344 if (txtcol >= 0 && txtcol < wp->w_width)
1345 ScreenAttrs[off + txtcol] = hl_combine_attr(
1346 ScreenAttrs[off + txtcol], HL_ATTR(HLF_MC));
1347 txtcol = old_txtcol;
1348 j = wp->w_p_cc_cols[++i];
1349 }
1350 }
1351
1352 // Show 'cursorcolumn' in the fold line.
1353 if (wp->w_p_cuc)
1354 {
1355 txtcol += wp->w_virtcol;
1356 if (wp->w_p_wrap)
1357 txtcol -= wp->w_skipcol;
1358 else
1359 txtcol -= wp->w_leftcol;
1360 if (txtcol >= 0 && txtcol < wp->w_width)
1361 ScreenAttrs[off + txtcol] = hl_combine_attr(
1362 ScreenAttrs[off + txtcol], HL_ATTR(HLF_CUC));
1363 }
1364#endif
1365
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001366 screen_line(wp, row + W_WINROW(wp), wp->w_wincol,
zeertzjqd0c1b772024-03-16 15:03:33 +01001367 wp->w_width, wp->w_width, -1, 0);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001368
1369 // Update w_cline_height and w_cline_folded if the cursor line was
1370 // updated (saves a call to plines() later).
1371 if (wp == curwin
1372 && lnum <= curwin->w_cursor.lnum
1373 && lnume >= curwin->w_cursor.lnum)
1374 {
1375 curwin->w_cline_row = row;
1376 curwin->w_cline_height = 1;
1377 curwin->w_cline_folded = TRUE;
1378 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
1379 }
Bram Moolenaar00aaa512021-07-03 18:04:11 +02001380
1381# ifdef FEAT_CONCEAL
1382 // When the line was not folded w_wrow may have been set, recompute it.
Bram Moolenaar5cb09622021-07-05 22:03:04 +02001383 if (wp == curwin
1384 && wp->w_cursor.lnum >= lnum
1385 && wp->w_cursor.lnum <= lnume
1386 && conceal_cursor_line(wp))
Bram Moolenaar00aaa512021-07-03 18:04:11 +02001387 curs_columns(TRUE);
1388# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001389}
1390#endif
1391
1392/*
1393 * Update a single window.
1394 *
1395 * This may cause the windows below it also to be redrawn (when clearing the
1396 * screen or scrolling lines).
1397 *
1398 * How the window is redrawn depends on wp->w_redr_type. Each type also
1399 * implies the one below it.
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001400 * UPD_NOT_VALID redraw the whole window
1401 * UPD_SOME_VALID redraw the whole window but do scroll when possible
1402 * UPD_REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like
1403 * UPD_VALID
1404 * UPD_INVERTED redraw the changed part of the Visual area
1405 * UPD_INVERTED_ALL redraw the whole Visual area
1406 * UPD_VALID 1. scroll up/down to adjust for a changed w_topline
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001407 * 2. update lines at the top when scrolled down
1408 * 3. redraw changed text:
1409 * - if wp->w_buffer->b_mod_set set, update lines between
1410 * b_mod_top and b_mod_bot.
1411 * - if wp->w_redraw_top non-zero, redraw lines between
zeertzjqf2d90a32024-02-12 20:28:01 +01001412 * wp->w_redraw_top and wp->w_redraw_bot.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001413 * - continue redrawing when syntax status is invalid.
1414 * 4. if scrolled up, update lines at the bottom.
1415 * This results in three areas that may need updating:
1416 * top: from first row to top_end (when scrolled down)
1417 * mid: from mid_start to mid_end (update inversion or changed text)
1418 * bot: from bot_start to last row (when scrolled up)
1419 */
1420 static void
1421win_update(win_T *wp)
1422{
1423 buf_T *buf = wp->w_buffer;
1424 int type;
1425 int top_end = 0; // Below last row of the top area that needs
1426 // updating. 0 when no top area updating.
1427 int mid_start = 999;// first row of the mid area that needs
1428 // updating. 999 when no mid area updating.
1429 int mid_end = 0; // Below last row of the mid area that needs
1430 // updating. 0 when no mid area updating.
1431 int bot_start = 999;// first row of the bot area that needs
1432 // updating. 999 when no bot area updating
1433 int scrolled_down = FALSE; // TRUE when scrolled down when
1434 // w_topline got smaller a bit
1435#ifdef FEAT_SEARCH_EXTRA
1436 int top_to_mod = FALSE; // redraw above mod_top
1437#endif
1438
1439 int row; // current window row to display
1440 linenr_T lnum; // current buffer lnum to display
1441 int idx; // current index in w_lines[]
1442 int srow; // starting row of the current line
1443
1444 int eof = FALSE; // if TRUE, we hit the end of the file
1445 int didline = FALSE; // if TRUE, we finished the last line
1446 int i;
1447 long j;
1448 static int recursive = FALSE; // being called recursively
Bram Moolenaarcbee6352019-11-12 20:49:15 +01001449 linenr_T old_botline = wp->w_botline;
1450#ifdef FEAT_CONCEAL
1451 int old_wrow = wp->w_wrow;
1452 int old_wcol = wp->w_wcol;
1453#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454#ifdef FEAT_FOLDING
1455 long fold_count;
1456#endif
1457#ifdef FEAT_SYN_HL
1458 // remember what happened to the previous line, to know if
1459 // check_visual_highlight() can be used
Bram Moolenaare7a74d52022-03-19 11:10:15 +00001460# define DID_NONE 1 // didn't update a line
1461# define DID_LINE 2 // updated a normal line
1462# define DID_FOLD 3 // updated a folded line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001463 int did_update = DID_NONE;
1464 linenr_T syntax_last_parsed = 0; // last parsed text line
1465#endif
1466 linenr_T mod_top = 0;
1467 linenr_T mod_bot = 0;
1468#if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
1469 int save_got_int;
1470#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001471
Bram Moolenaare52e0c82020-02-28 22:20:10 +01001472#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
1473 // This needs to be done only for the first window when update_screen() is
1474 // called.
1475 if (!did_update_one_window)
1476 {
1477 did_update_one_window = TRUE;
1478# ifdef FEAT_SEARCH_EXTRA
1479 start_search_hl();
1480# endif
1481# ifdef FEAT_CLIPBOARD
1482 // When Visual area changed, may have to update selection.
1483 if (clip_star.available && clip_isautosel_star())
1484 clip_update_selection(&clip_star);
1485 if (clip_plus.available && clip_isautosel_plus())
1486 clip_update_selection(&clip_plus);
1487# endif
1488 }
1489#endif
1490
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001491 type = wp->w_redr_type;
1492
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001493 if (type == UPD_NOT_VALID)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001494 {
1495 wp->w_redr_status = TRUE;
1496 wp->w_lines_valid = 0;
1497 }
1498
Bram Moolenaarae0f1512021-03-30 22:12:12 +02001499 // Window frame is zero-height: nothing to draw.
1500 if (wp->w_height + WINBAR_HEIGHT(wp) == 0
1501 || (wp->w_frame->fr_height == wp->w_status_height
1502#if defined(FEAT_PROP_POPUP)
1503 && !popup_is_popup(wp)
1504#endif
1505 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001506 {
1507 wp->w_redr_type = 0;
1508 return;
1509 }
1510
1511 // Window is zero-width: Only need to draw the separator.
1512 if (wp->w_width == 0)
1513 {
1514 // draw the vertical separator right of this window
1515 draw_vsep_win(wp, 0);
1516 wp->w_redr_type = 0;
1517 return;
1518 }
1519
1520#ifdef FEAT_TERMINAL
1521 // If this window contains a terminal, redraw works completely differently.
1522 if (term_do_update_window(wp))
1523 {
1524 term_update_window(wp);
1525# ifdef FEAT_MENU
1526 // Draw the window toolbar, if there is one.
1527 if (winbar_height(wp) > 0)
1528 redraw_win_toolbar(wp);
1529# endif
1530 wp->w_redr_type = 0;
1531 return;
1532 }
1533#endif
1534
1535#ifdef FEAT_SEARCH_EXTRA
1536 init_search_hl(wp, &screen_search_hl);
1537#endif
1538
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +01001539 // Make sure skipcol is valid, it depends on various options and the window
1540 // width.
Sean Dewar02fcae02024-02-21 19:40:44 +01001541 if (wp->w_skipcol > 0 && wp->w_width > win_col_off(wp))
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +01001542 {
1543 int w = 0;
1544 int width1 = wp->w_width - win_col_off(wp);
1545 int width2 = width1 + win_col_off2(wp);
1546 int add = width1;
1547
1548 while (w < wp->w_skipcol)
1549 {
1550 if (w > 0)
1551 add = width2;
1552 w += add;
1553 }
1554 if (w != wp->w_skipcol)
1555 // always round down, the higher value may not be valid
1556 wp->w_skipcol = w - add;
1557 }
1558
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001559#ifdef FEAT_LINEBREAK
1560 // Force redraw when width of 'number' or 'relativenumber' column
1561 // changes.
1562 i = (wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) : 0;
1563 if (wp->w_nrwidth != i)
1564 {
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001565 type = UPD_NOT_VALID;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001566 wp->w_nrwidth = i;
1567 }
1568 else
1569#endif
1570
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001571 {
1572 // Set mod_top to the first line that needs displaying because of
1573 // changes. Set mod_bot to the first line after the changes.
1574 mod_top = wp->w_redraw_top;
1575 if (wp->w_redraw_bot != 0)
1576 mod_bot = wp->w_redraw_bot + 1;
1577 else
1578 mod_bot = 0;
1579 if (buf->b_mod_set)
1580 {
1581 if (mod_top == 0 || mod_top > buf->b_mod_top)
1582 {
1583 mod_top = buf->b_mod_top;
1584#ifdef FEAT_SYN_HL
1585 // Need to redraw lines above the change that may be included
1586 // in a pattern match.
1587 if (syntax_present(wp))
1588 {
1589 mod_top -= buf->b_s.b_syn_sync_linebreaks;
1590 if (mod_top < 1)
1591 mod_top = 1;
1592 }
1593#endif
1594 }
1595 if (mod_bot == 0 || mod_bot < buf->b_mod_bot)
1596 mod_bot = buf->b_mod_bot;
1597
1598#ifdef FEAT_SEARCH_EXTRA
1599 // When 'hlsearch' is on and using a multi-line search pattern, a
1600 // change in one line may make the Search highlighting in a
1601 // previous line invalid. Simple solution: redraw all visible
1602 // lines above the change.
1603 // Same for a match pattern.
1604 if (screen_search_hl.rm.regprog != NULL
1605 && re_multiline(screen_search_hl.rm.regprog))
1606 top_to_mod = TRUE;
1607 else
1608 {
1609 matchitem_T *cur = wp->w_match_head;
1610
1611 while (cur != NULL)
1612 {
Bram Moolenaar50faf022022-09-29 12:50:17 +01001613 if (cur->mit_match.regprog != NULL
1614 && re_multiline(cur->mit_match.regprog))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001615 {
1616 top_to_mod = TRUE;
1617 break;
1618 }
Bram Moolenaar50faf022022-09-29 12:50:17 +01001619 cur = cur->mit_next;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001620 }
1621 }
1622#endif
1623 }
Bram Moolenaar368137a2022-05-31 13:43:12 +01001624
1625#ifdef FEAT_SEARCH_EXTRA
1626 if (search_hl_has_cursor_lnum > 0)
1627 {
1628 // CurSearch was used last time, need to redraw the line with it to
1629 // avoid having two matches highlighted with CurSearch.
1630 if (mod_top == 0 || mod_top > search_hl_has_cursor_lnum)
1631 mod_top = search_hl_has_cursor_lnum;
1632 if (mod_bot == 0 || mod_bot < search_hl_has_cursor_lnum + 1)
1633 mod_bot = search_hl_has_cursor_lnum + 1;
1634 }
1635#endif
1636
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001637#ifdef FEAT_FOLDING
1638 if (mod_top != 0 && hasAnyFolding(wp))
1639 {
1640 linenr_T lnumt, lnumb;
1641
1642 // A change in a line can cause lines above it to become folded or
1643 // unfolded. Find the top most buffer line that may be affected.
1644 // If the line was previously folded and displayed, get the first
1645 // line of that fold. If the line is folded now, get the first
1646 // folded line. Use the minimum of these two.
1647
1648 // Find last valid w_lines[] entry above mod_top. Set lnumt to
1649 // the line below it. If there is no valid entry, use w_topline.
1650 // Find the first valid w_lines[] entry below mod_bot. Set lnumb
1651 // to this line. If there is no valid entry, use MAXLNUM.
1652 lnumt = wp->w_topline;
1653 lnumb = MAXLNUM;
1654 for (i = 0; i < wp->w_lines_valid; ++i)
1655 if (wp->w_lines[i].wl_valid)
1656 {
1657 if (wp->w_lines[i].wl_lastlnum < mod_top)
1658 lnumt = wp->w_lines[i].wl_lastlnum + 1;
1659 if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot)
1660 {
1661 lnumb = wp->w_lines[i].wl_lnum;
1662 // When there is a fold column it might need updating
1663 // in the next line ("J" just above an open fold).
1664 if (compute_foldcolumn(wp, 0) > 0)
1665 ++lnumb;
1666 }
1667 }
1668
1669 (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL);
1670 if (mod_top > lnumt)
1671 mod_top = lnumt;
1672
1673 // Now do the same for the bottom line (one above mod_bot).
1674 --mod_bot;
1675 (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL);
1676 ++mod_bot;
1677 if (mod_bot < lnumb)
1678 mod_bot = lnumb;
1679 }
1680#endif
1681
1682 // When a change starts above w_topline and the end is below
1683 // w_topline, start redrawing at w_topline.
1684 // If the end of the change is above w_topline: do like no change was
1685 // made, but redraw the first line to find changes in syntax.
1686 if (mod_top != 0 && mod_top < wp->w_topline)
1687 {
1688 if (mod_bot > wp->w_topline)
1689 mod_top = wp->w_topline;
1690#ifdef FEAT_SYN_HL
1691 else if (syntax_present(wp))
1692 top_end = 1;
1693#endif
1694 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001695 }
1696 wp->w_redraw_top = 0; // reset for next time
1697 wp->w_redraw_bot = 0;
Bram Moolenaar368137a2022-05-31 13:43:12 +01001698#ifdef FEAT_SEARCH_EXTRA
1699 search_hl_has_cursor_lnum = 0;
1700#endif
1701
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001702
1703 // When only displaying the lines at the top, set top_end. Used when
1704 // window has scrolled down for msg_scrolled.
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001705 if (type == UPD_REDRAW_TOP)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001706 {
1707 j = 0;
1708 for (i = 0; i < wp->w_lines_valid; ++i)
1709 {
1710 j += wp->w_lines[i].wl_size;
1711 if (j >= wp->w_upd_rows)
1712 {
1713 top_end = j;
1714 break;
1715 }
1716 }
1717 if (top_end == 0)
1718 // not found (cannot happen?): redraw everything
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001719 type = UPD_NOT_VALID;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001720 else
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001721 // top area defined, the rest is UPD_VALID
1722 type = UPD_VALID;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001723 }
1724
1725 // Trick: we want to avoid clearing the screen twice. screenclear() will
1726 // set "screen_cleared" to TRUE. The special value MAYBE (which is still
1727 // non-zero and thus not FALSE) will indicate that screenclear() was not
1728 // called.
1729 if (screen_cleared)
1730 screen_cleared = MAYBE;
1731
1732 // If there are no changes on the screen that require a complete redraw,
1733 // handle three cases:
1734 // 1: we are off the top of the screen by a few lines: scroll down
1735 // 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up
1736 // 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in
1737 // w_lines[] that needs updating.
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001738 if ((type == UPD_VALID || type == UPD_SOME_VALID
1739 || type == UPD_INVERTED || type == UPD_INVERTED_ALL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001740#ifdef FEAT_DIFF
1741 && !wp->w_botfill && !wp->w_old_botfill
1742#endif
1743 )
1744 {
Bram Moolenaarf8992d42020-08-01 19:14:13 +02001745 if (mod_top != 0
1746 && wp->w_topline == mod_top
1747 && (!wp->w_lines[0].wl_valid
Bram Moolenaarabb6fbd2022-03-25 15:42:27 +00001748 || wp->w_topline == wp->w_lines[0].wl_lnum))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001749 {
Bram Moolenaarf8992d42020-08-01 19:14:13 +02001750 // w_topline is the first changed line and window is not scrolled,
1751 // the scrolling from changed lines will be done further down.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001752 }
1753 else if (wp->w_lines[0].wl_valid
1754 && (wp->w_topline < wp->w_lines[0].wl_lnum
1755#ifdef FEAT_DIFF
1756 || (wp->w_topline == wp->w_lines[0].wl_lnum
1757 && wp->w_topfill > wp->w_old_topfill)
1758#endif
1759 ))
1760 {
1761 // New topline is above old topline: May scroll down.
1762#ifdef FEAT_FOLDING
1763 if (hasAnyFolding(wp))
1764 {
1765 linenr_T ln;
1766
1767 // count the number of lines we are off, counting a sequence
1768 // of folded lines as one
1769 j = 0;
1770 for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln)
1771 {
1772 ++j;
1773 if (j >= wp->w_height - 2)
1774 break;
1775 (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL);
1776 }
1777 }
1778 else
1779#endif
1780 j = wp->w_lines[0].wl_lnum - wp->w_topline;
1781 if (j < wp->w_height - 2) // not too far off
1782 {
zeertzjqbfe377b2023-08-17 22:58:53 +02001783 i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1,
Luuk van Baal32d701f2024-04-28 16:24:02 +02001784 wp->w_height);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001785#ifdef FEAT_DIFF
1786 // insert extra lines for previously invisible filler lines
1787 if (wp->w_lines[0].wl_lnum != wp->w_topline)
1788 i += diff_check_fill(wp, wp->w_lines[0].wl_lnum)
1789 - wp->w_old_topfill;
1790#endif
1791 if (i < wp->w_height - 2) // less than a screen off
1792 {
1793 // Try to insert the correct number of lines.
1794 // If not the last window, delete the lines at the bottom.
1795 // win_ins_lines may fail when the terminal can't do it.
1796 if (i > 0)
1797 check_for_delay(FALSE);
1798 if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK)
1799 {
1800 if (wp->w_lines_valid != 0)
1801 {
1802 // Need to update rows that are new, stop at the
1803 // first one that scrolled down.
1804 top_end = i;
1805 scrolled_down = TRUE;
1806
1807 // Move the entries that were scrolled, disable
1808 // the entries for the lines to be redrawn.
1809 if ((wp->w_lines_valid += j) > wp->w_height)
1810 wp->w_lines_valid = wp->w_height;
Bram Moolenaara2a89732022-08-31 14:46:18 +01001811 for (idx = wp->w_lines_valid; idx - j >= 0; idx--)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001812 wp->w_lines[idx] = wp->w_lines[idx - j];
1813 while (idx >= 0)
1814 wp->w_lines[idx--].wl_valid = FALSE;
1815 }
1816 }
1817 else
1818 mid_start = 0; // redraw all lines
1819 }
1820 else
1821 mid_start = 0; // redraw all lines
1822 }
1823 else
1824 mid_start = 0; // redraw all lines
1825 }
1826 else
1827 {
1828 // New topline is at or below old topline: May scroll up.
1829 // When topline didn't change, find first entry in w_lines[] that
1830 // needs updating.
1831
Bram Moolenaarf6ebc822022-01-16 13:58:33 +00001832 // Try to find wp->w_topline in wp->w_lines[].wl_lnum. The check
1833 // for "Rows" is in case "wl_size" is incorrect somehow.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001834 j = -1;
1835 row = 0;
Bram Moolenaarf6ebc822022-01-16 13:58:33 +00001836 for (i = 0; i < wp->w_lines_valid && i < Rows; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001837 {
1838 if (wp->w_lines[i].wl_valid
1839 && wp->w_lines[i].wl_lnum == wp->w_topline)
1840 {
1841 j = i;
1842 break;
1843 }
1844 row += wp->w_lines[i].wl_size;
1845 }
1846 if (j == -1)
1847 {
1848 // if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all
1849 // lines
1850 mid_start = 0;
1851 }
1852 else
1853 {
1854 // Try to delete the correct number of lines.
1855 // wp->w_topline is at wp->w_lines[i].wl_lnum.
1856#ifdef FEAT_DIFF
1857 // If the topline didn't change, delete old filler lines,
1858 // otherwise delete filler lines of the new topline...
1859 if (wp->w_lines[0].wl_lnum == wp->w_topline)
1860 row += wp->w_old_topfill;
1861 else
1862 row += diff_check_fill(wp, wp->w_topline);
1863 // ... but don't delete new filler lines.
1864 row -= wp->w_topfill;
1865#endif
Bram Moolenaarf6ebc822022-01-16 13:58:33 +00001866 if (row > Rows) // just in case
1867 row = Rows;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001868 if (row > 0)
1869 {
1870 check_for_delay(FALSE);
1871 if (win_del_lines(wp, 0, row, FALSE, wp == firstwin, 0)
1872 == OK)
1873 bot_start = wp->w_height - row;
1874 else
1875 mid_start = 0; // redraw all lines
1876 }
1877 if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0)
1878 {
1879 // Skip the lines (below the deleted lines) that are still
1880 // valid and don't need redrawing. Copy their info
1881 // upwards, to compensate for the deleted lines. Set
1882 // bot_start to the first row that needs redrawing.
1883 bot_start = 0;
1884 idx = 0;
1885 for (;;)
1886 {
1887 wp->w_lines[idx] = wp->w_lines[j];
1888 // stop at line that didn't fit, unless it is still
1889 // valid (no lines deleted)
1890 if (row > 0 && bot_start + row
1891 + (int)wp->w_lines[j].wl_size > wp->w_height)
1892 {
1893 wp->w_lines_valid = idx + 1;
1894 break;
1895 }
1896 bot_start += wp->w_lines[idx++].wl_size;
1897
1898 // stop at the last valid entry in w_lines[].wl_size
1899 if (++j >= wp->w_lines_valid)
1900 {
1901 wp->w_lines_valid = idx;
1902 break;
1903 }
1904 }
1905#ifdef FEAT_DIFF
1906 // Correct the first entry for filler lines at the top
1907 // when it won't get updated below.
1908 if (wp->w_p_diff && bot_start > 0)
zeertzjq47f85842024-10-01 19:35:47 +02001909 {
1910 int n = plines_win_nofill(wp, wp->w_topline, FALSE)
1911 + wp->w_topfill - adjust_plines_for_skipcol(wp);
1912 if (n > wp->w_height)
1913 n = wp->w_height;
1914 wp->w_lines[0].wl_size = n;
1915 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001916#endif
1917 }
1918 }
1919 }
1920
Bram Moolenaar13608d82022-08-29 15:06:50 +01001921 // When starting redraw in the first line, redraw all lines.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001922 if (mid_start == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001923 mid_end = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001924
1925 // When win_del_lines() or win_ins_lines() caused the screen to be
1926 // cleared (only happens for the first window) or when screenclear()
1927 // was called directly above, "must_redraw" will have been set to
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001928 // UPD_NOT_VALID, need to reset it here to avoid redrawing twice.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001929 if (screen_cleared == TRUE)
1930 must_redraw = 0;
1931 }
1932 else
1933 {
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001934 // Not UPD_VALID or UPD_INVERTED: redraw all lines.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001935 mid_start = 0;
1936 mid_end = wp->w_height;
1937 }
1938
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001939 if (type == UPD_SOME_VALID)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001940 {
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001941 // UPD_SOME_VALID: redraw all lines.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001942 mid_start = 0;
1943 mid_end = wp->w_height;
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001944 type = UPD_NOT_VALID;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001945 }
1946
1947 // check if we are updating or removing the inverted part
1948 if ((VIsual_active && buf == curwin->w_buffer)
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001949 || (wp->w_old_cursor_lnum != 0 && type != UPD_NOT_VALID))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001950 {
1951 linenr_T from, to;
1952
1953 if (VIsual_active)
1954 {
Bram Moolenaarfe154992022-03-22 20:42:12 +00001955 if (VIsual_mode != wp->w_old_visual_mode
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001956 || type == UPD_INVERTED_ALL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001957 {
1958 // If the type of Visual selection changed, redraw the whole
1959 // selection. Also when the ownership of the X selection is
1960 // gained or lost.
1961 if (curwin->w_cursor.lnum < VIsual.lnum)
1962 {
1963 from = curwin->w_cursor.lnum;
1964 to = VIsual.lnum;
1965 }
1966 else
1967 {
1968 from = VIsual.lnum;
1969 to = curwin->w_cursor.lnum;
1970 }
1971 // redraw more when the cursor moved as well
1972 if (wp->w_old_cursor_lnum < from)
1973 from = wp->w_old_cursor_lnum;
1974 if (wp->w_old_cursor_lnum > to)
1975 to = wp->w_old_cursor_lnum;
1976 if (wp->w_old_visual_lnum < from)
1977 from = wp->w_old_visual_lnum;
1978 if (wp->w_old_visual_lnum > to)
1979 to = wp->w_old_visual_lnum;
1980 }
1981 else
1982 {
1983 // Find the line numbers that need to be updated: The lines
1984 // between the old cursor position and the current cursor
1985 // position. Also check if the Visual position changed.
1986 if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum)
1987 {
1988 from = curwin->w_cursor.lnum;
1989 to = wp->w_old_cursor_lnum;
1990 }
1991 else
1992 {
1993 from = wp->w_old_cursor_lnum;
1994 to = curwin->w_cursor.lnum;
1995 if (from == 0) // Visual mode just started
1996 from = to;
1997 }
1998
1999 if (VIsual.lnum != wp->w_old_visual_lnum
2000 || VIsual.col != wp->w_old_visual_col)
2001 {
2002 if (wp->w_old_visual_lnum < from
2003 && wp->w_old_visual_lnum != 0)
2004 from = wp->w_old_visual_lnum;
2005 if (wp->w_old_visual_lnum > to)
2006 to = wp->w_old_visual_lnum;
2007 if (VIsual.lnum < from)
2008 from = VIsual.lnum;
2009 if (VIsual.lnum > to)
2010 to = VIsual.lnum;
2011 }
2012 }
2013
2014 // If in block mode and changed column or curwin->w_curswant:
2015 // update all lines.
2016 // First compute the actual start and end column.
2017 if (VIsual_mode == Ctrl_V)
2018 {
2019 colnr_T fromc, toc;
2020#if defined(FEAT_LINEBREAK)
Gary Johnson51ad8502021-08-03 18:33:08 +02002021 int save_ve_flags = curwin->w_ve_flags;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002022
2023 if (curwin->w_p_lbr)
Gary Johnson51ad8502021-08-03 18:33:08 +02002024 curwin->w_ve_flags = VE_ALL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002025#endif
2026 getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc);
Bram Moolenaarb17ab862021-07-03 22:15:17 +02002027 ++toc;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002028#if defined(FEAT_LINEBREAK)
Gary Johnson51ad8502021-08-03 18:33:08 +02002029 curwin->w_ve_flags = save_ve_flags;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002030#endif
Bram Moolenaar9cee4a12021-07-03 15:08:37 +02002031 // Highlight to the end of the line, unless 'virtualedit' has
2032 // "block".
Bram Moolenaarb17ab862021-07-03 22:15:17 +02002033 if (curwin->w_curswant == MAXCOL)
2034 {
Gary Johnson53ba05b2021-07-26 22:19:10 +02002035 if (get_ve_flags() & VE_BLOCK)
Bram Moolenaarb17ab862021-07-03 22:15:17 +02002036 {
2037 pos_T pos;
2038 int cursor_above =
2039 curwin->w_cursor.lnum < VIsual.lnum;
2040
2041 // Need to find the longest line.
2042 toc = 0;
2043 pos.coladd = 0;
2044 for (pos.lnum = curwin->w_cursor.lnum; cursor_above
2045 ? pos.lnum <= VIsual.lnum
2046 : pos.lnum >= VIsual.lnum;
2047 pos.lnum += cursor_above ? 1 : -1)
2048 {
2049 colnr_T t;
2050
Bram Moolenaar6bcb1822021-07-09 15:54:00 +02002051 pos.col = (int)STRLEN(ml_get_buf(wp->w_buffer,
Bram Moolenaarb17ab862021-07-03 22:15:17 +02002052 pos.lnum, FALSE));
2053 getvvcol(wp, &pos, NULL, NULL, &t);
2054 if (toc < t)
2055 toc = t;
2056 }
2057 ++toc;
2058 }
2059 else
2060 toc = MAXCOL;
2061 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002062
2063 if (fromc != wp->w_old_cursor_fcol
2064 || toc != wp->w_old_cursor_lcol)
2065 {
2066 if (from > VIsual.lnum)
2067 from = VIsual.lnum;
2068 if (to < VIsual.lnum)
2069 to = VIsual.lnum;
2070 }
2071 wp->w_old_cursor_fcol = fromc;
2072 wp->w_old_cursor_lcol = toc;
2073 }
2074 }
2075 else
2076 {
2077 // Use the line numbers of the old Visual area.
2078 if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum)
2079 {
2080 from = wp->w_old_cursor_lnum;
2081 to = wp->w_old_visual_lnum;
2082 }
2083 else
2084 {
2085 from = wp->w_old_visual_lnum;
2086 to = wp->w_old_cursor_lnum;
2087 }
2088 }
2089
2090 // There is no need to update lines above the top of the window.
2091 if (from < wp->w_topline)
2092 from = wp->w_topline;
2093
2094 // If we know the value of w_botline, use it to restrict the update to
2095 // the lines that are visible in the window.
2096 if (wp->w_valid & VALID_BOTLINE)
2097 {
2098 if (from >= wp->w_botline)
2099 from = wp->w_botline - 1;
2100 if (to >= wp->w_botline)
2101 to = wp->w_botline - 1;
2102 }
2103
2104 // Find the minimal part to be updated.
2105 // Watch out for scrolling that made entries in w_lines[] invalid.
2106 // E.g., CTRL-U makes the first half of w_lines[] invalid and sets
2107 // top_end; need to redraw from top_end to the "to" line.
2108 // A middle mouse click with a Visual selection may change the text
2109 // above the Visual area and reset wl_valid, do count these for
2110 // mid_end (in srow).
2111 if (mid_start > 0)
2112 {
2113 lnum = wp->w_topline;
2114 idx = 0;
2115 srow = 0;
2116 if (scrolled_down)
2117 mid_start = top_end;
2118 else
2119 mid_start = 0;
2120 while (lnum < from && idx < wp->w_lines_valid) // find start
2121 {
2122 if (wp->w_lines[idx].wl_valid)
2123 mid_start += wp->w_lines[idx].wl_size;
2124 else if (!scrolled_down)
2125 srow += wp->w_lines[idx].wl_size;
2126 ++idx;
2127# ifdef FEAT_FOLDING
2128 if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid)
2129 lnum = wp->w_lines[idx].wl_lnum;
2130 else
2131# endif
2132 ++lnum;
2133 }
2134 srow += mid_start;
2135 mid_end = wp->w_height;
2136 for ( ; idx < wp->w_lines_valid; ++idx) // find end
2137 {
2138 if (wp->w_lines[idx].wl_valid
2139 && wp->w_lines[idx].wl_lnum >= to + 1)
2140 {
2141 // Only update until first row of this line
2142 mid_end = srow;
2143 break;
2144 }
2145 srow += wp->w_lines[idx].wl_size;
2146 }
2147 }
2148 }
2149
2150 if (VIsual_active && buf == curwin->w_buffer)
2151 {
2152 wp->w_old_visual_mode = VIsual_mode;
2153 wp->w_old_cursor_lnum = curwin->w_cursor.lnum;
2154 wp->w_old_visual_lnum = VIsual.lnum;
2155 wp->w_old_visual_col = VIsual.col;
2156 wp->w_old_curswant = curwin->w_curswant;
2157 }
2158 else
2159 {
2160 wp->w_old_visual_mode = 0;
2161 wp->w_old_cursor_lnum = 0;
2162 wp->w_old_visual_lnum = 0;
2163 wp->w_old_visual_col = 0;
2164 }
2165
2166#if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
2167 // reset got_int, otherwise regexp won't work
2168 save_got_int = got_int;
2169 got_int = 0;
2170#endif
2171#ifdef SYN_TIME_LIMIT
2172 // Set the time limit to 'redrawtime'.
Bram Moolenaar6f0cf622022-06-19 12:27:45 +01002173 redrawtime_limit_set = TRUE;
Paul Ollis65745772022-06-05 16:55:54 +01002174 init_regexp_timeout(p_rdt);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002175#endif
2176#ifdef FEAT_FOLDING
2177 win_foldinfo.fi_level = 0;
2178#endif
2179
2180#ifdef FEAT_MENU
2181 // Draw the window toolbar, if there is one.
2182 // TODO: only when needed.
2183 if (winbar_height(wp) > 0)
2184 redraw_win_toolbar(wp);
2185#endif
2186
Luuk van Baal30805a12023-05-27 22:22:10 +01002187 lnum = wp->w_topline; // first line shown in window
2188
2189 spellvars_T spv;
2190#ifdef FEAT_SPELL
2191 // Initialize spell related variables for the first drawn line.
2192 CLEAR_FIELD(spv);
Luuk van Baale84c7732023-05-31 18:57:36 +01002193 if (spell_check_window(wp))
Luuk van Baal30805a12023-05-27 22:22:10 +01002194 {
Luuk van Baale84c7732023-05-31 18:57:36 +01002195 spv.spv_has_spell = TRUE;
Luuk van Baal30805a12023-05-27 22:22:10 +01002196 spv.spv_unchanged = mod_top == 0;
Luuk van Baal30805a12023-05-27 22:22:10 +01002197 }
2198#endif
2199
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002200 // Update all the window rows.
2201 idx = 0; // first entry in w_lines[].wl_size
2202 row = 0;
2203 srow = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002204 for (;;)
2205 {
2206 // stop updating when reached the end of the window (check for _past_
2207 // the end of the window is at the end of the loop)
2208 if (row == wp->w_height)
2209 {
2210 didline = TRUE;
2211 break;
2212 }
2213
2214 // stop updating when hit the end of the file
2215 if (lnum > buf->b_ml.ml_line_count)
2216 {
2217 eof = TRUE;
2218 break;
2219 }
2220
2221 // Remember the starting row of the line that is going to be dealt
2222 // with. It is used further down when the line doesn't fit.
2223 srow = row;
2224
2225 // Update a line when it is in an area that needs updating, when it
2226 // has changes or w_lines[idx] is invalid.
2227 // "bot_start" may be halfway a wrapped line after using
2228 // win_del_lines(), check if the current line includes it.
2229 // When syntax folding is being used, the saved syntax states will
2230 // already have been updated, we can't see where the syntax state is
2231 // the same again, just update until the end of the window.
2232 if (row < top_end
2233 || (row >= mid_start && row < mid_end)
2234#ifdef FEAT_SEARCH_EXTRA
2235 || top_to_mod
2236#endif
2237 || idx >= wp->w_lines_valid
2238 || (row + wp->w_lines[idx].wl_size > bot_start)
2239 || (mod_top != 0
2240 && (lnum == mod_top
2241 || (lnum >= mod_top
2242 && (lnum < mod_bot
2243#ifdef FEAT_SYN_HL
2244 || did_update == DID_FOLD
2245 || (did_update == DID_LINE
2246 && syntax_present(wp)
2247 && (
2248# ifdef FEAT_FOLDING
2249 (foldmethodIsSyntax(wp)
2250 && hasAnyFolding(wp)) ||
2251# endif
2252 syntax_check_changed(lnum)))
2253#endif
2254#ifdef FEAT_SEARCH_EXTRA
2255 // match in fixed position might need redraw
2256 // if lines were inserted or deleted
2257 || (wp->w_match_head != NULL
zeertzjq9f25a3a2024-11-26 15:08:02 +01002258 && buf->b_mod_set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002259 && buf->b_mod_xlines != 0)
2260#endif
Bram Moolenaar11a58af2019-10-24 22:32:31 +02002261 ))))
2262#ifdef FEAT_SYN_HL
zeertzjqc20e46a2022-03-23 14:55:23 +00002263 || (wp->w_p_cul && lnum == wp->w_cursor.lnum)
2264 || lnum == wp->w_last_cursorline
Bram Moolenaar11a58af2019-10-24 22:32:31 +02002265#endif
2266 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002267 {
2268#ifdef FEAT_SEARCH_EXTRA
2269 if (lnum == mod_top)
2270 top_to_mod = FALSE;
2271#endif
2272
2273 // When at start of changed lines: May scroll following lines
2274 // up or down to minimize redrawing.
2275 // Don't do this when the change continues until the end.
2276 // Don't scroll when dollar_vcol >= 0, keep the "$".
Bram Moolenaarc9e7e342021-07-22 21:33:03 +02002277 // Don't scroll when redrawing the top, scrolled already above.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002278 if (lnum == mod_top
2279 && mod_bot != MAXLNUM
Bram Moolenaarc9e7e342021-07-22 21:33:03 +02002280 && !(dollar_vcol >= 0 && mod_bot == mod_top + 1)
2281 && row >= top_end)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002282 {
2283 int old_rows = 0;
2284 int new_rows = 0;
2285 int xtra_rows;
2286 linenr_T l;
2287
2288 // Count the old number of window rows, using w_lines[], which
2289 // should still contain the sizes for the lines as they are
2290 // currently displayed.
2291 for (i = idx; i < wp->w_lines_valid; ++i)
2292 {
2293 // Only valid lines have a meaningful wl_lnum. Invalid
2294 // lines are part of the changed area.
2295 if (wp->w_lines[i].wl_valid
2296 && wp->w_lines[i].wl_lnum == mod_bot)
2297 break;
2298 old_rows += wp->w_lines[i].wl_size;
2299#ifdef FEAT_FOLDING
2300 if (wp->w_lines[i].wl_valid
2301 && wp->w_lines[i].wl_lastlnum + 1 == mod_bot)
2302 {
2303 // Must have found the last valid entry above mod_bot.
2304 // Add following invalid entries.
2305 ++i;
2306 while (i < wp->w_lines_valid
2307 && !wp->w_lines[i].wl_valid)
2308 old_rows += wp->w_lines[i++].wl_size;
2309 break;
2310 }
2311#endif
2312 }
2313
2314 if (i >= wp->w_lines_valid)
2315 {
2316 // We can't find a valid line below the changed lines,
2317 // need to redraw until the end of the window.
2318 // Inserting/deleting lines has no use.
2319 bot_start = 0;
2320 }
2321 else
2322 {
2323 // Able to count old number of rows: Count new window
2324 // rows, and may insert/delete lines
2325 j = idx;
2326 for (l = lnum; l < mod_bot; ++l)
2327 {
2328#ifdef FEAT_FOLDING
2329 if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL))
2330 ++new_rows;
2331 else
2332#endif
Dominique Pelle9b0b8442021-10-18 20:56:39 +01002333 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002334#ifdef FEAT_DIFF
2335 if (l == wp->w_topline)
Luuk van Baalc8502f92023-05-06 12:40:15 +01002336 {
2337 int n = plines_win_nofill(wp, l, FALSE)
2338 + wp->w_topfill;
zeertzjq6235a102023-08-19 14:12:42 +02002339 n -= adjust_plines_for_skipcol(wp);
Luuk van Baalc8502f92023-05-06 12:40:15 +01002340 if (n > wp->w_height)
2341 n = wp->w_height;
2342 new_rows += n;
2343 }
Dominique Pelle9b0b8442021-10-18 20:56:39 +01002344 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002345#endif
Dominique Pelle9b0b8442021-10-18 20:56:39 +01002346 new_rows += plines_win(wp, l, TRUE);
2347 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002348 ++j;
2349 if (new_rows > wp->w_height - row - 2)
2350 {
2351 // it's getting too much, must redraw the rest
2352 new_rows = 9999;
2353 break;
2354 }
2355 }
2356 xtra_rows = new_rows - old_rows;
2357 if (xtra_rows < 0)
2358 {
2359 // May scroll text up. If there is not enough
2360 // remaining text or scrolling fails, must redraw the
2361 // rest. If scrolling works, must redraw the text
2362 // below the scrolled text.
2363 if (row - xtra_rows >= wp->w_height - 2)
2364 mod_bot = MAXLNUM;
2365 else
2366 {
2367 check_for_delay(FALSE);
2368 if (win_del_lines(wp, row,
2369 -xtra_rows, FALSE, FALSE, 0) == FAIL)
2370 mod_bot = MAXLNUM;
2371 else
2372 bot_start = wp->w_height + xtra_rows;
2373 }
2374 }
2375 else if (xtra_rows > 0)
2376 {
2377 // May scroll text down. If there is not enough
2378 // remaining text of scrolling fails, must redraw the
2379 // rest.
2380 if (row + xtra_rows >= wp->w_height - 2)
2381 mod_bot = MAXLNUM;
2382 else
2383 {
2384 check_for_delay(FALSE);
2385 if (win_ins_lines(wp, row + old_rows,
2386 xtra_rows, FALSE, FALSE) == FAIL)
2387 mod_bot = MAXLNUM;
2388 else if (top_end > row + old_rows)
2389 // Scrolled the part at the top that requires
2390 // updating down.
2391 top_end += xtra_rows;
2392 }
2393 }
2394
2395 // When not updating the rest, may need to move w_lines[]
2396 // entries.
2397 if (mod_bot != MAXLNUM && i != j)
2398 {
2399 if (j < i)
2400 {
2401 int x = row + new_rows;
2402
2403 // move entries in w_lines[] upwards
2404 for (;;)
2405 {
2406 // stop at last valid entry in w_lines[]
2407 if (i >= wp->w_lines_valid)
2408 {
2409 wp->w_lines_valid = j;
2410 break;
2411 }
2412 wp->w_lines[j] = wp->w_lines[i];
2413 // stop at a line that won't fit
2414 if (x + (int)wp->w_lines[j].wl_size
2415 > wp->w_height)
2416 {
2417 wp->w_lines_valid = j + 1;
2418 break;
2419 }
2420 x += wp->w_lines[j++].wl_size;
2421 ++i;
2422 }
2423 if (bot_start > x)
2424 bot_start = x;
2425 }
2426 else // j > i
2427 {
2428 // move entries in w_lines[] downwards
2429 j -= i;
2430 wp->w_lines_valid += j;
2431 if (wp->w_lines_valid > wp->w_height)
2432 wp->w_lines_valid = wp->w_height;
2433 for (i = wp->w_lines_valid; i - j >= idx; --i)
Bram Moolenaara2a89732022-08-31 14:46:18 +01002434 wp->w_lines[i] = wp->w_lines[i - j];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002435
2436 // The w_lines[] entries for inserted lines are
2437 // now invalid, but wl_size may be used above.
2438 // Reset to zero.
2439 while (i >= idx)
2440 {
2441 wp->w_lines[i].wl_size = 0;
2442 wp->w_lines[i--].wl_valid = FALSE;
2443 }
2444 }
2445 }
2446 }
2447 }
2448
2449#ifdef FEAT_FOLDING
2450 // When lines are folded, display one line for all of them.
2451 // Otherwise, display normally (can be several display lines when
2452 // 'wrap' is on).
2453 fold_count = foldedCount(wp, lnum, &win_foldinfo);
2454 if (fold_count != 0)
2455 {
2456 fold_line(wp, fold_count, &win_foldinfo, lnum, row);
2457 ++row;
2458 --fold_count;
2459 wp->w_lines[idx].wl_folded = TRUE;
Luuk van Baale84c7732023-05-31 18:57:36 +01002460 wp->w_lines[idx].wl_lastlnum = lnum + fold_count;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002461# ifdef FEAT_SYN_HL
2462 did_update = DID_FOLD;
2463# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002464# ifdef FEAT_SPELL
Luuk van Baale84c7732023-05-31 18:57:36 +01002465 spv.spv_capcol_lnum = 0;
Luuk van Baal30805a12023-05-27 22:22:10 +01002466# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002467 }
2468 else
2469#endif
2470 if (idx < wp->w_lines_valid
2471 && wp->w_lines[idx].wl_valid
2472 && wp->w_lines[idx].wl_lnum == lnum
2473 && lnum > wp->w_topline
2474 && !(dy_flags & (DY_LASTLINE | DY_TRUNCATE))
2475 && !WIN_IS_POPUP(wp)
2476 && srow + wp->w_lines[idx].wl_size > wp->w_height
2477#ifdef FEAT_DIFF
2478 && diff_check_fill(wp, lnum) == 0
2479#endif
2480 )
2481 {
2482 // This line is not going to fit. Don't draw anything here,
2483 // will draw "@ " lines below.
2484 row = wp->w_height + 1;
2485 }
2486 else
2487 {
2488#ifdef FEAT_SEARCH_EXTRA
2489 prepare_search_hl(wp, &screen_search_hl, lnum);
2490#endif
2491#ifdef FEAT_SYN_HL
2492 // Let the syntax stuff know we skipped a few lines.
2493 if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum
2494 && syntax_present(wp))
Bram Moolenaar0abd6cf2022-10-14 17:04:09 +01002495 syntax_end_parsing(wp, syntax_last_parsed + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002496#endif
2497
2498 // Display one line.
zeertzjqebfd8562024-02-06 10:59:03 +01002499 row = win_line(wp, lnum, srow, wp->w_height, 0, &spv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002500
2501#ifdef FEAT_FOLDING
2502 wp->w_lines[idx].wl_folded = FALSE;
2503 wp->w_lines[idx].wl_lastlnum = lnum;
2504#endif
2505#ifdef FEAT_SYN_HL
2506 did_update = DID_LINE;
2507 syntax_last_parsed = lnum;
2508#endif
2509 }
2510
2511 wp->w_lines[idx].wl_lnum = lnum;
2512 wp->w_lines[idx].wl_valid = TRUE;
2513
2514 // Past end of the window or end of the screen. Note that after
2515 // resizing wp->w_height may be end up too big. That's a problem
2516 // elsewhere, but prevent a crash here.
Bram Moolenaara2a89732022-08-31 14:46:18 +01002517 if (row > wp->w_height || row + wp->w_winrow >= Rows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002518 {
2519 // we may need the size of that too long line later on
2520 if (dollar_vcol == -1)
2521 wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE);
2522 ++idx;
2523 break;
2524 }
2525 if (dollar_vcol == -1)
2526 wp->w_lines[idx].wl_size = row - srow;
2527 ++idx;
2528#ifdef FEAT_FOLDING
2529 lnum += fold_count + 1;
2530#else
2531 ++lnum;
2532#endif
2533 }
2534 else
2535 {
zeertzjqae07ebc2024-02-08 11:37:40 +01002536 // If:
2537 // - 'number' is set and below inserted/deleted lines, or
2538 // - 'relativenumber' is set and cursor moved vertically,
2539 // the text doesn't need to be redrawn, but the number column does.
zeertzjq9f25a3a2024-11-26 15:08:02 +01002540 if ((wp->w_p_nu && mod_top != 0 && lnum >= mod_bot
2541 && buf->b_mod_set && buf->b_mod_xlines != 0)
zeertzjqae07ebc2024-02-08 11:37:40 +01002542 || (wp->w_p_rnu
2543 && wp->w_last_cursor_lnum_rnu != wp->w_cursor.lnum))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002544 {
2545#ifdef FEAT_FOLDING
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002546 fold_count = foldedCount(wp, lnum, &win_foldinfo);
2547 if (fold_count != 0)
2548 fold_line(wp, fold_count, &win_foldinfo, lnum, row);
2549 else
2550#endif
zeertzjqebfd8562024-02-06 10:59:03 +01002551 (void)win_line(wp, lnum, srow, wp->w_height,
2552 wp->w_lines[idx].wl_size, &spv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002553 }
2554
2555 // This line does not need to be drawn, advance to the next one.
2556 row += wp->w_lines[idx++].wl_size;
2557 if (row > wp->w_height) // past end of screen
2558 break;
2559#ifdef FEAT_FOLDING
2560 lnum = wp->w_lines[idx - 1].wl_lastlnum + 1;
2561#else
2562 ++lnum;
2563#endif
2564#ifdef FEAT_SYN_HL
2565 did_update = DID_NONE;
2566#endif
Luuk van Baale84c7732023-05-31 18:57:36 +01002567#ifdef FEAT_SPELL
2568 spv.spv_capcol_lnum = 0;
2569#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002570 }
2571
2572 if (lnum > buf->b_ml.ml_line_count)
2573 {
2574 eof = TRUE;
2575 break;
2576 }
Bram Moolenaarfa1a4572022-01-16 11:42:20 +00002577
2578 // Safety check: if any of the wl_size values is wrong we might go over
2579 // the end of w_lines[].
Bram Moolenaara2a89732022-08-31 14:46:18 +01002580 if (idx >= Rows)
Bram Moolenaarfa1a4572022-01-16 11:42:20 +00002581 break;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002582 }
2583
2584 // End of loop over all window lines.
2585
zeertzjqc20e46a2022-03-23 14:55:23 +00002586#ifdef FEAT_SYN_HL
2587 // Now that the window has been redrawn with the old and new cursor line,
2588 // update w_last_cursorline.
2589 wp->w_last_cursorline = wp->w_p_cul ? wp->w_cursor.lnum : 0;
2590#endif
Lewis Russell16246392022-03-29 11:38:17 +01002591 wp->w_last_cursor_lnum_rnu = wp->w_p_rnu ? wp->w_cursor.lnum : 0;
zeertzjqc20e46a2022-03-23 14:55:23 +00002592
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002593#ifdef FEAT_VTP
2594 // Rewrite the character at the end of the screen line.
Bram Moolenaar7ed8f592020-04-28 20:44:42 +02002595 // See the version that was fixed.
2596 if (use_vtp() && get_conpty_fix_type() < 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002597 {
K.Takata54119102022-02-03 13:33:03 +00002598 int k;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002599
K.Takata54119102022-02-03 13:33:03 +00002600 for (k = 0; k < Rows; ++k)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002601 if (enc_utf8)
K.Takata54119102022-02-03 13:33:03 +00002602 if ((*mb_off2cells)(LineOffset[k] + Columns - 2,
2603 LineOffset[k] + screen_Columns) > 1)
2604 screen_draw_rectangle(k, Columns - 2, 1, 2, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002605 else
K.Takata54119102022-02-03 13:33:03 +00002606 screen_draw_rectangle(k, Columns - 1, 1, 1, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002607 else
K.Takata54119102022-02-03 13:33:03 +00002608 screen_char(LineOffset[k] + Columns - 1, k, Columns - 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002609 }
2610#endif
2611
2612 if (idx > wp->w_lines_valid)
2613 wp->w_lines_valid = idx;
2614
2615#ifdef FEAT_SYN_HL
2616 // Let the syntax stuff know we stop parsing here.
2617 if (syntax_last_parsed != 0 && syntax_present(wp))
Bram Moolenaar0abd6cf2022-10-14 17:04:09 +01002618 syntax_end_parsing(wp, syntax_last_parsed + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002619#endif
2620
2621 // If we didn't hit the end of the file, and we didn't finish the last
2622 // line we were working on, then the line didn't fit.
2623 wp->w_empty_rows = 0;
2624#ifdef FEAT_DIFF
2625 wp->w_filler_rows = 0;
2626#endif
2627 if (!eof && !didline)
2628 {
2629 if (lnum == wp->w_topline)
2630 {
2631 // Single line that does not fit!
2632 // Don't overwrite it, it can be edited.
2633 wp->w_botline = lnum + 1;
2634 }
2635#ifdef FEAT_DIFF
2636 else if (diff_check_fill(wp, lnum) >= wp->w_height - srow)
2637 {
2638 // Window ends in filler lines.
2639 wp->w_botline = lnum;
2640 wp->w_filler_rows = wp->w_height - srow;
2641 }
2642#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002643#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002644 else if (WIN_IS_POPUP(wp))
2645 {
2646 // popup line that doesn't fit is left as-is
2647 wp->w_botline = lnum;
2648 }
2649#endif
2650 else if (dy_flags & DY_TRUNCATE) // 'display' has "truncate"
2651 {
Bram Moolenaar4ba5f1d2022-10-04 14:36:29 +01002652 int scr_row = W_WINROW(wp) + wp->w_height - 1;
2653 int symbol = wp->w_fill_chars.lastline;
zeertzjq18b35002022-10-04 20:35:37 +01002654 int charlen;
Bram Moolenaar4ba5f1d2022-10-04 14:36:29 +01002655 char_u fillbuf[12]; // 2 characters of 6 bytes
2656
zeertzjq18b35002022-10-04 20:35:37 +01002657 charlen = mb_char2bytes(symbol, &fillbuf[0]);
2658 mb_char2bytes(symbol, &fillbuf[charlen]);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002659
2660 // Last line isn't finished: Display "@@@" in the last screen line.
Bram Moolenaar4ba5f1d2022-10-04 14:36:29 +01002661 screen_puts_len(fillbuf,
zeertzjq18b35002022-10-04 20:35:37 +01002662 (wp->w_width > 2 ? 2 : wp->w_width) * charlen,
Bram Moolenaar4ba5f1d2022-10-04 14:36:29 +01002663 scr_row, wp->w_wincol, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002664 screen_fill(scr_row, scr_row + 1,
2665 (int)wp->w_wincol + 2, (int)W_ENDCOL(wp),
Bram Moolenaar4ba5f1d2022-10-04 14:36:29 +01002666 symbol, ' ', HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002667 set_empty_rows(wp, srow);
2668 wp->w_botline = lnum;
2669 }
2670 else if (dy_flags & DY_LASTLINE) // 'display' has "lastline"
2671 {
Bram Moolenaarcee9c842022-04-09 12:40:13 +01002672 int start_col = (int)W_ENDCOL(wp) - 3;
Bram Moolenaar4ba5f1d2022-10-04 14:36:29 +01002673 int symbol = wp->w_fill_chars.lastline;
Bram Moolenaarcee9c842022-04-09 12:40:13 +01002674
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002675 // Last line isn't finished: Display "@@@" at the end.
2676 screen_fill(W_WINROW(wp) + wp->w_height - 1,
2677 W_WINROW(wp) + wp->w_height,
Bram Moolenaarcee9c842022-04-09 12:40:13 +01002678 start_col < wp->w_wincol ? wp->w_wincol : start_col,
2679 (int)W_ENDCOL(wp),
Bram Moolenaar4ba5f1d2022-10-04 14:36:29 +01002680 symbol, symbol, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002681 set_empty_rows(wp, srow);
2682 wp->w_botline = lnum;
2683 }
2684 else
2685 {
Bram Moolenaar4ba5f1d2022-10-04 14:36:29 +01002686 win_draw_end(wp, wp->w_fill_chars.lastline, ' ', TRUE,
2687 srow, wp->w_height, HLF_AT);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002688 wp->w_botline = lnum;
2689 }
2690 }
2691 else
2692 {
2693 draw_vsep_win(wp, row);
2694 if (eof) // we hit the end of the file
2695 {
2696 wp->w_botline = buf->b_ml.ml_line_count + 1;
2697#ifdef FEAT_DIFF
2698 j = diff_check_fill(wp, wp->w_botline);
2699 if (j > 0 && !wp->w_botfill)
2700 {
2701 // Display filler lines at the end of the file.
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01002702 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002703 i = '-';
2704 else
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01002705 i = wp->w_fill_chars.diff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002706 if (row + j > wp->w_height)
2707 j = wp->w_height - row;
2708 win_draw_end(wp, i, i, TRUE, row, row + (int)j, HLF_DED);
2709 row += j;
2710 }
2711#endif
2712 }
2713 else if (dollar_vcol == -1)
2714 wp->w_botline = lnum;
2715
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01002716 // Make sure the rest of the screen is blank.
2717 // write the "eob" character from 'fillchars' to rows that aren't part
2718 // of the file.
Bram Moolenaar1666ac92019-11-10 17:22:31 +01002719 if (WIN_IS_POPUP(wp))
2720 win_draw_end(wp, ' ', ' ', FALSE, row, wp->w_height, HLF_AT);
2721 else
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01002722 win_draw_end(wp, wp->w_fill_chars.eob, ' ', FALSE,
2723 row, wp->w_height, HLF_EOB);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002724 }
2725
2726#ifdef SYN_TIME_LIMIT
Paul Ollis65745772022-06-05 16:55:54 +01002727 disable_regexp_timeout();
Bram Moolenaar6f0cf622022-06-19 12:27:45 +01002728 redrawtime_limit_set = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002729#endif
2730
2731 // Reset the type of redrawing required, the window has been updated.
2732 wp->w_redr_type = 0;
2733#ifdef FEAT_DIFF
2734 wp->w_old_topfill = wp->w_topfill;
2735 wp->w_old_botfill = wp->w_botfill;
2736#endif
2737
2738 if (dollar_vcol == -1)
2739 {
2740 // There is a trick with w_botline. If we invalidate it on each
2741 // change that might modify it, this will cause a lot of expensive
2742 // calls to plines() in update_topline() each time. Therefore the
2743 // value of w_botline is often approximated, and this value is used to
2744 // compute the value of w_topline. If the value of w_botline was
2745 // wrong, check that the value of w_topline is correct (cursor is on
2746 // the visible part of the text). If it's not, we need to redraw
2747 // again. Mostly this just means scrolling up a few lines, so it
2748 // doesn't look too bad. Only do this for the current window (where
2749 // changes are relevant).
2750 wp->w_valid |= VALID_BOTLINE;
2751 if (wp == curwin && wp->w_botline != old_botline && !recursive)
2752 {
Bram Moolenaarcbee6352019-11-12 20:49:15 +01002753 win_T *wwp;
2754#if defined(FEAT_CONCEAL)
2755 linenr_T old_topline = wp->w_topline;
2756 int new_wcol = wp->w_wcol;
2757#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002758 recursive = TRUE;
2759 curwin->w_valid &= ~VALID_TOPLINE;
2760 update_topline(); // may invalidate w_botline again
Bram Moolenaarcbee6352019-11-12 20:49:15 +01002761
2762#if defined(FEAT_CONCEAL)
2763 if (old_wcol != new_wcol && (wp->w_valid & (VALID_WCOL|VALID_WROW))
2764 != (VALID_WCOL|VALID_WROW))
2765 {
2766 // A win_line() call applied a fix to screen cursor column to
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002767 // accommodate concealment of cursor line, but in this call to
Bram Moolenaarcbee6352019-11-12 20:49:15 +01002768 // update_topline() the cursor's row or column got invalidated.
2769 // If they are left invalid, setcursor() will recompute them
2770 // but there won't be any further win_line() call to re-fix the
2771 // column and the cursor will end up misplaced. So we call
2772 // cursor validation now and reapply the fix again (or call
2773 // win_line() to do it for us).
2774 validate_cursor();
2775 if (wp->w_wcol == old_wcol && wp->w_wrow == old_wrow
2776 && old_topline == wp->w_topline)
2777 wp->w_wcol = new_wcol;
2778 else
2779 redrawWinline(wp, wp->w_cursor.lnum);
2780 }
2781#endif
Luuk van Baal3d5065f2024-09-01 10:33:56 +02002782 // New redraw either due to updated topline, wcol fix or reset skipcol.
Bram Moolenaarcbee6352019-11-12 20:49:15 +01002783 if (wp->w_redr_type != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002784 {
2785 // Don't update for changes in buffer again.
2786 i = curbuf->b_mod_set;
2787 curbuf->b_mod_set = FALSE;
Bram Moolenaarcbee6352019-11-12 20:49:15 +01002788 j = curbuf->b_mod_xlines;
2789 curbuf->b_mod_xlines = 0;
Luuk van Baal3d5065f2024-09-01 10:33:56 +02002790 curs_columns(TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002791 win_update(curwin);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002792 curbuf->b_mod_set = i;
Bram Moolenaarcbee6352019-11-12 20:49:15 +01002793 curbuf->b_mod_xlines = j;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002794 }
Bram Moolenaarcbee6352019-11-12 20:49:15 +01002795 // Other windows might have w_redr_type raised in update_topline().
2796 must_redraw = 0;
2797 FOR_ALL_WINDOWS(wwp)
2798 if (wwp->w_redr_type > must_redraw)
2799 must_redraw = wwp->w_redr_type;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002800 recursive = FALSE;
2801 }
2802 }
2803
2804#if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
2805 // restore got_int, unless CTRL-C was hit while redrawing
2806 if (!got_int)
2807 got_int = save_got_int;
2808#endif
2809}
2810
2811#if defined(FEAT_NETBEANS_INTG) || defined(FEAT_GUI)
2812/*
2813 * Prepare for updating one or more windows.
2814 * Caller must check for "updating_screen" already set to avoid recursiveness.
2815 */
2816 static void
2817update_prepare(void)
2818{
2819 cursor_off();
2820 updating_screen = TRUE;
2821#ifdef FEAT_GUI
2822 // Remove the cursor before starting to do anything, because scrolling may
2823 // make it difficult to redraw the text under it.
2824 if (gui.in_use)
2825 gui_undraw_cursor();
2826#endif
2827#ifdef FEAT_SEARCH_EXTRA
2828 start_search_hl();
2829#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002830#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002831 // Update popup_mask if needed.
2832 may_update_popup_mask(must_redraw);
2833#endif
2834}
2835
2836/*
2837 * Finish updating one or more windows.
2838 */
2839 static void
2840update_finish(void)
2841{
2842 if (redraw_cmdline || redraw_mode)
2843 showmode();
2844
2845# ifdef FEAT_SEARCH_EXTRA
2846 end_search_hl();
2847# endif
2848
2849 after_updating_screen(TRUE);
2850
2851# ifdef FEAT_GUI
2852 // Redraw the cursor and update the scrollbars when all screen updating is
2853 // done.
2854 if (gui.in_use)
2855 {
2856 out_flush_cursor(FALSE, FALSE);
2857 gui_update_scrollbars(FALSE);
2858 }
2859# endif
2860}
2861#endif
2862
2863#if defined(FEAT_NETBEANS_INTG) || defined(PROTO)
2864 void
2865update_debug_sign(buf_T *buf, linenr_T lnum)
2866{
2867 win_T *wp;
2868 int doit = FALSE;
2869
2870# ifdef FEAT_FOLDING
2871 win_foldinfo.fi_level = 0;
2872# endif
2873
2874 // update/delete a specific sign
2875 redraw_buf_line_later(buf, lnum);
2876
2877 // check if it resulted in the need to redraw a window
2878 FOR_ALL_WINDOWS(wp)
2879 if (wp->w_redr_type != 0)
2880 doit = TRUE;
2881
2882 // Return when there is nothing to do, screen updating is already
2883 // happening (recursive call), messages on the screen or still starting up.
2884 if (!doit || updating_screen
Bram Moolenaar24959102022-05-07 20:01:16 +01002885 || State == MODE_ASKMORE || State == MODE_HITRETURN
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002886 || msg_scrolled
2887#ifdef FEAT_GUI
2888 || gui.starting
2889#endif
2890 || starting)
2891 return;
2892
2893 // update all windows that need updating
2894 update_prepare();
2895
2896 FOR_ALL_WINDOWS(wp)
2897 {
2898 if (wp->w_redr_type != 0)
2899 win_update(wp);
2900 if (wp->w_redr_status)
2901 win_redr_status(wp, FALSE);
2902 }
2903
2904 update_finish();
2905}
2906#endif
2907
2908#if defined(FEAT_GUI) || defined(PROTO)
2909/*
2910 * Update a single window, its status line and maybe the command line msg.
2911 * Used for the GUI scrollbar.
2912 */
2913 void
2914updateWindow(win_T *wp)
2915{
2916 // return if already busy updating
2917 if (updating_screen)
2918 return;
2919
2920 update_prepare();
2921
2922#ifdef FEAT_CLIPBOARD
2923 // When Visual area changed, may have to update selection.
2924 if (clip_star.available && clip_isautosel_star())
2925 clip_update_selection(&clip_star);
2926 if (clip_plus.available && clip_isautosel_plus())
2927 clip_update_selection(&clip_plus);
2928#endif
2929
2930 win_update(wp);
2931
2932 // When the screen was cleared redraw the tab pages line.
2933 if (redraw_tabline)
2934 draw_tabline();
2935
Martin Tournoijba43e762022-10-13 22:12:15 +01002936 if (wp->w_redr_status || p_ru
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002937# ifdef FEAT_STL_OPT
2938 || *p_stl != NUL || *wp->w_p_stl != NUL
2939# endif
2940 )
2941 win_redr_status(wp, FALSE);
2942
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002943#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002944 // Display popup windows on top of everything.
2945 update_popups(win_update);
2946#endif
2947
2948 update_finish();
2949}
2950#endif
2951
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002952/*
2953 * Redraw as soon as possible. When the command line is not scrolled redraw
2954 * right away and restore what was on the command line.
2955 * Return a code indicating what happened.
2956 */
2957 int
2958redraw_asap(int type)
2959{
2960 int rows;
2961 int cols = screen_Columns;
2962 int r;
2963 int ret = 0;
2964 schar_T *screenline; // copy from ScreenLines[]
2965 sattr_T *screenattr; // copy from ScreenAttrs[]
2966 int i;
2967 u8char_T *screenlineUC = NULL; // copy from ScreenLinesUC[]
2968 u8char_T *screenlineC[MAX_MCO]; // copy from ScreenLinesC[][]
2969 schar_T *screenline2 = NULL; // copy from ScreenLines2[]
2970
2971 redraw_later(type);
Shougo Matsushitaf39cfb72022-07-30 16:54:05 +01002972 if (msg_scrolled
2973 || (State != MODE_NORMAL && State != MODE_NORMAL_BUSY)
Bram Moolenaara2a89732022-08-31 14:46:18 +01002974 || exiting)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002975 return ret;
2976
2977 // Allocate space to save the text displayed in the command line area.
2978 rows = screen_Rows - cmdline_row;
2979 screenline = LALLOC_MULT(schar_T, rows * cols);
2980 screenattr = LALLOC_MULT(sattr_T, rows * cols);
2981 if (screenline == NULL || screenattr == NULL)
2982 ret = 2;
2983 if (enc_utf8)
2984 {
2985 screenlineUC = LALLOC_MULT(u8char_T, rows * cols);
2986 if (screenlineUC == NULL)
2987 ret = 2;
2988 for (i = 0; i < p_mco; ++i)
2989 {
2990 screenlineC[i] = LALLOC_MULT(u8char_T, rows * cols);
2991 if (screenlineC[i] == NULL)
2992 ret = 2;
2993 }
2994 }
2995 if (enc_dbcs == DBCS_JPNU)
2996 {
2997 screenline2 = LALLOC_MULT(schar_T, rows * cols);
2998 if (screenline2 == NULL)
2999 ret = 2;
3000 }
3001
3002 if (ret != 2)
3003 {
3004 // Save the text displayed in the command line area.
3005 for (r = 0; r < rows; ++r)
3006 {
3007 mch_memmove(screenline + r * cols,
3008 ScreenLines + LineOffset[cmdline_row + r],
3009 (size_t)cols * sizeof(schar_T));
3010 mch_memmove(screenattr + r * cols,
3011 ScreenAttrs + LineOffset[cmdline_row + r],
3012 (size_t)cols * sizeof(sattr_T));
3013 if (enc_utf8)
3014 {
3015 mch_memmove(screenlineUC + r * cols,
3016 ScreenLinesUC + LineOffset[cmdline_row + r],
3017 (size_t)cols * sizeof(u8char_T));
3018 for (i = 0; i < p_mco; ++i)
3019 mch_memmove(screenlineC[i] + r * cols,
3020 ScreenLinesC[i] + LineOffset[cmdline_row + r],
3021 (size_t)cols * sizeof(u8char_T));
3022 }
3023 if (enc_dbcs == DBCS_JPNU)
3024 mch_memmove(screenline2 + r * cols,
3025 ScreenLines2 + LineOffset[cmdline_row + r],
3026 (size_t)cols * sizeof(schar_T));
3027 }
3028
3029 update_screen(0);
3030 ret = 3;
3031
3032 if (must_redraw == 0)
3033 {
3034 int off = (int)(current_ScreenLine - ScreenLines);
3035
3036 // Restore the text displayed in the command line area.
3037 for (r = 0; r < rows; ++r)
3038 {
3039 mch_memmove(current_ScreenLine,
3040 screenline + r * cols,
3041 (size_t)cols * sizeof(schar_T));
3042 mch_memmove(ScreenAttrs + off,
3043 screenattr + r * cols,
3044 (size_t)cols * sizeof(sattr_T));
3045 if (enc_utf8)
3046 {
3047 mch_memmove(ScreenLinesUC + off,
3048 screenlineUC + r * cols,
3049 (size_t)cols * sizeof(u8char_T));
3050 for (i = 0; i < p_mco; ++i)
3051 mch_memmove(ScreenLinesC[i] + off,
3052 screenlineC[i] + r * cols,
3053 (size_t)cols * sizeof(u8char_T));
3054 }
3055 if (enc_dbcs == DBCS_JPNU)
3056 mch_memmove(ScreenLines2 + off,
3057 screenline2 + r * cols,
3058 (size_t)cols * sizeof(schar_T));
zeertzjqd0c1b772024-03-16 15:03:33 +01003059 screen_line(curwin, cmdline_row + r, 0, cols, cols, -1, 0);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003060 }
3061 ret = 4;
3062 }
3063 }
3064
3065 vim_free(screenline);
3066 vim_free(screenattr);
3067 if (enc_utf8)
3068 {
3069 vim_free(screenlineUC);
3070 for (i = 0; i < p_mco; ++i)
3071 vim_free(screenlineC[i]);
3072 }
3073 if (enc_dbcs == DBCS_JPNU)
3074 vim_free(screenline2);
3075
3076 // Show the intro message when appropriate.
3077 maybe_intro_message();
3078
3079 setcursor();
3080
3081 return ret;
3082}
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003083
3084/*
3085 * Invoked after an asynchronous callback is called.
3086 * If an echo command was used the cursor needs to be put back where
3087 * it belongs. If highlighting was changed a redraw is needed.
3088 * If "call_update_screen" is FALSE don't call update_screen() when at the
3089 * command line.
Bram Moolenaare5050712021-12-09 10:51:05 +00003090 * If "redraw_message" is TRUE.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003091 */
3092 void
Bram Moolenaare5050712021-12-09 10:51:05 +00003093redraw_after_callback(int call_update_screen, int do_message)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003094{
3095 ++redrawing_for_callback;
3096
Bram Moolenaar24959102022-05-07 20:01:16 +01003097 if (State == MODE_HITRETURN || State == MODE_ASKMORE
3098 || State == MODE_SETWSIZE || State == MODE_EXTERNCMD
3099 || State == MODE_CONFIRM || exmode_active)
Bram Moolenaare5050712021-12-09 10:51:05 +00003100 {
3101 if (do_message)
3102 repeat_message();
3103 }
Bram Moolenaar24959102022-05-07 20:01:16 +01003104 else if (State & MODE_CMDLINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003105 {
Yegappan Lakshmanan3908ef52022-02-08 12:08:07 +00003106 if (pum_visible())
3107 cmdline_pum_display();
Bram Moolenaar54162322022-08-26 16:58:51 +01003108
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003109 // Don't redraw when in prompt_for_number().
3110 if (cmdline_row > 0)
3111 {
3112 // Redrawing only works when the screen didn't scroll. Don't clear
3113 // wildmenu entries.
3114 if (msg_scrolled == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003115 && wild_menu_showing == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003116 && call_update_screen)
3117 update_screen(0);
3118
3119 // Redraw in the same position, so that the user can continue
3120 // editing the command.
3121 redrawcmdline_ex(FALSE);
3122 }
3123 }
Bram Moolenaar24959102022-05-07 20:01:16 +01003124 else if (State & (MODE_NORMAL | MODE_INSERT | MODE_TERMINAL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003125 {
zeertzjq3e559cd2022-03-27 19:26:55 +01003126 update_topline();
3127 validate_cursor();
3128
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003129 // keep the command line if possible
Bram Moolenaara4d158b2022-08-14 14:17:45 +01003130 update_screen(UPD_VALID_NO_UPDATE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003131 setcursor();
Bram Moolenaar9f284162021-04-22 21:39:30 +02003132
3133 if (msg_scrolled == 0)
3134 {
3135 // don't want a hit-enter prompt when something else is displayed
3136 msg_didany = FALSE;
3137 need_wait_return = FALSE;
3138 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003139 }
3140 cursor_on();
3141#ifdef FEAT_GUI
3142 if (gui.in_use && !gui_mch_is_blink_off())
3143 // Don't update the cursor when it is blinking and off to avoid
3144 // flicker.
3145 out_flush_cursor(FALSE, FALSE);
3146 else
3147#endif
3148 out_flush();
3149
3150 --redrawing_for_callback;
3151}
3152
3153/*
3154 * Redraw the current window later, with update_screen(type).
3155 * Set must_redraw only if not already set to a higher value.
Bram Moolenaara4d158b2022-08-14 14:17:45 +01003156 * E.g. if must_redraw is UPD_CLEAR, type UPD_NOT_VALID will do nothing.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003157 */
3158 void
3159redraw_later(int type)
3160{
3161 redraw_win_later(curwin, type);
3162}
3163
3164 void
3165redraw_win_later(
3166 win_T *wp,
3167 int type)
3168{
Bram Moolenaar471c0fa2022-08-22 15:19:16 +01003169 if (!exiting && !redraw_not_allowed && wp->w_redr_type < type)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003170 {
3171 wp->w_redr_type = type;
Bram Moolenaara4d158b2022-08-14 14:17:45 +01003172 if (type >= UPD_NOT_VALID)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003173 wp->w_lines_valid = 0;
3174 if (must_redraw < type) // must_redraw is the maximum of all windows
3175 must_redraw = type;
3176 }
3177}
3178
3179/*
3180 * Force a complete redraw later. Also resets the highlighting. To be used
3181 * after executing a shell command that messes up the screen.
3182 */
3183 void
3184redraw_later_clear(void)
3185{
Bram Moolenaara4d158b2022-08-14 14:17:45 +01003186 redraw_all_later(UPD_CLEAR);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003187 reset_screen_attr();
3188}
3189
3190/*
Bram Moolenaar13608d82022-08-29 15:06:50 +01003191 * Mark all windows to be redrawn later. Except popup windows.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003192 */
3193 void
3194redraw_all_later(int type)
3195{
3196 win_T *wp;
3197
3198 FOR_ALL_WINDOWS(wp)
3199 redraw_win_later(wp, type);
3200 // This may be needed when switching tabs.
Bram Moolenaar471c0fa2022-08-22 15:19:16 +01003201 set_must_redraw(type);
3202}
3203
Bram Moolenaar13608d82022-08-29 15:06:50 +01003204#if 0 // not actually used yet, it probably should
3205/*
3206 * Mark all windows, including popup windows, to be redrawn.
3207 */
3208 void
3209redraw_all_windows_later(int type)
3210{
3211 redraw_all_later(type);
3212#ifdef FEAT_PROP_POPUP
3213 popup_redraw_all(); // redraw all popup windows
3214#endif
3215}
3216#endif
3217
Bram Moolenaar471c0fa2022-08-22 15:19:16 +01003218/*
3219 * Set "must_redraw" to "type" unless it already has a higher value
3220 * or it is currently not allowed.
3221 */
3222 void
3223set_must_redraw(int type)
3224{
3225 if (!redraw_not_allowed && must_redraw < type)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003226 must_redraw = type;
3227}
3228
3229/*
3230 * Mark all windows that are editing the current buffer to be updated later.
3231 */
3232 void
3233redraw_curbuf_later(int type)
3234{
3235 redraw_buf_later(curbuf, type);
3236}
3237
3238 void
3239redraw_buf_later(buf_T *buf, int type)
3240{
3241 win_T *wp;
3242
3243 FOR_ALL_WINDOWS(wp)
3244 {
3245 if (wp->w_buffer == buf)
3246 redraw_win_later(wp, type);
3247 }
Bram Moolenaare52e0c82020-02-28 22:20:10 +01003248#if defined(FEAT_TERMINAL) && defined(FEAT_PROP_POPUP)
3249 // terminal in popup window is not in list of windows
3250 if (curwin->w_buffer == buf)
3251 redraw_win_later(curwin, type);
3252#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003253}
3254
3255#if defined(FEAT_SIGNS) || defined(PROTO)
3256 void
3257redraw_buf_line_later(buf_T *buf, linenr_T lnum)
3258{
3259 win_T *wp;
3260
3261 FOR_ALL_WINDOWS(wp)
3262 if (wp->w_buffer == buf && lnum >= wp->w_topline
3263 && lnum < wp->w_botline)
3264 redrawWinline(wp, lnum);
3265}
3266#endif
3267
3268#if defined(FEAT_JOB_CHANNEL) || defined(PROTO)
3269 void
3270redraw_buf_and_status_later(buf_T *buf, int type)
3271{
3272 win_T *wp;
3273
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003274 if (wild_menu_showing != 0)
3275 // Don't redraw while the command line completion is displayed, it
3276 // would disappear.
3277 return;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003278 FOR_ALL_WINDOWS(wp)
3279 {
3280 if (wp->w_buffer == buf)
3281 {
3282 redraw_win_later(wp, type);
3283 wp->w_redr_status = TRUE;
3284 }
3285 }
3286}
3287#endif
3288
3289/*
3290 * mark all status lines for redraw; used after first :cd
3291 */
3292 void
3293status_redraw_all(void)
3294{
3295 win_T *wp;
3296
3297 FOR_ALL_WINDOWS(wp)
3298 if (wp->w_status_height)
3299 {
3300 wp->w_redr_status = TRUE;
Bram Moolenaara4d158b2022-08-14 14:17:45 +01003301 redraw_later(UPD_VALID);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003302 }
3303}
3304
3305/*
3306 * mark all status lines of the current buffer for redraw
3307 */
3308 void
3309status_redraw_curbuf(void)
3310{
3311 win_T *wp;
3312
3313 FOR_ALL_WINDOWS(wp)
3314 if (wp->w_status_height != 0 && wp->w_buffer == curbuf)
3315 {
3316 wp->w_redr_status = TRUE;
Bram Moolenaara4d158b2022-08-14 14:17:45 +01003317 redraw_later(UPD_VALID);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003318 }
3319}
3320
3321/*
3322 * Redraw all status lines that need to be redrawn.
3323 */
3324 void
3325redraw_statuslines(void)
3326{
3327 win_T *wp;
3328
3329 FOR_ALL_WINDOWS(wp)
3330 if (wp->w_redr_status)
3331 win_redr_status(wp, FALSE);
3332 if (redraw_tabline)
3333 draw_tabline();
3334}
3335
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003336/*
3337 * Redraw all status lines at the bottom of frame "frp".
3338 */
3339 void
3340win_redraw_last_status(frame_T *frp)
3341{
3342 if (frp->fr_layout == FR_LEAF)
3343 frp->fr_win->w_redr_status = TRUE;
3344 else if (frp->fr_layout == FR_ROW)
3345 {
3346 FOR_ALL_FRAMES(frp, frp->fr_child)
3347 win_redraw_last_status(frp);
3348 }
3349 else // frp->fr_layout == FR_COL
3350 {
3351 frp = frp->fr_child;
3352 while (frp->fr_next != NULL)
3353 frp = frp->fr_next;
3354 win_redraw_last_status(frp);
3355 }
3356}
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003357
3358/*
3359 * Changed something in the current window, at buffer line "lnum", that
3360 * requires that line and possibly other lines to be redrawn.
3361 * Used when entering/leaving Insert mode with the cursor on a folded line.
3362 * Used to remove the "$" from a change command.
3363 * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot
3364 * may become invalid and the whole window will have to be redrawn.
3365 */
3366 void
3367redrawWinline(
3368 win_T *wp,
3369 linenr_T lnum)
3370{
3371 if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum)
3372 wp->w_redraw_top = lnum;
3373 if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum)
3374 wp->w_redraw_bot = lnum;
Bram Moolenaara4d158b2022-08-14 14:17:45 +01003375 redraw_win_later(wp, UPD_VALID);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003376}