Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1 | /* 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 Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 31 | * call redraw_later(UPD_VALID) to have the window displayed by update_screen() |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 32 | * 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 Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 43 | * settings), must call redraw_later(UPD_NOT_VALID) to have the whole window |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 44 | * redisplayed by update_screen() later. |
| 45 | * |
| 46 | * Commands that change how a buffer is displayed (e.g., setting 'tabstop') |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 47 | * must call redraw_curbuf_later(UPD_NOT_VALID) to have all the windows for the |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 48 | * buffer redisplayed by update_screen() later. |
| 49 | * |
| 50 | * Commands that change highlighting and possibly cause a scroll too must call |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 51 | * 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 Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 54 | * |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 55 | * Commands that move the window position must call redraw_later(UPD_NOT_VALID). |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 56 | * TODO: should minimize redrawing by scrolling when possible. |
| 57 | * |
| 58 | * Commands that change everything (e.g., resizing the screen) must call |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 59 | * redraw_all_later(UPD_NOT_VALID) or redraw_all_later(UPD_CLEAR). |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 60 | * |
| 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 | |
| 68 | static void win_update(win_T *wp); |
| 69 | #ifdef FEAT_STL_OPT |
| 70 | static void redraw_custom_statusline(win_T *wp); |
| 71 | #endif |
Bram Moolenaar | e52e0c8 | 2020-02-28 22:20:10 +0100 | [diff] [blame] | 72 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 73 | static int did_update_one_window; |
| 74 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 75 | |
| 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 |
| 82 | update_screen(int type_arg) |
| 83 | { |
| 84 | int type = type_arg; |
| 85 | win_T *wp; |
| 86 | static int did_intro = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 87 | #ifdef FEAT_GUI |
Bram Moolenaar | e52e0c8 | 2020-02-28 22:20:10 +0100 | [diff] [blame] | 88 | int did_one = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 89 | int did_undraw = FALSE; |
| 90 | int gui_cursor_col = 0; |
| 91 | int gui_cursor_row = 0; |
| 92 | #endif |
| 93 | int no_update = FALSE; |
Bram Moolenaar | e0c03c8 | 2021-04-23 21:01:34 +0200 | [diff] [blame] | 94 | int save_pum_will_redraw = pum_will_redraw; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 95 | |
| 96 | // Don't do anything if the screen structures are (not yet) valid. |
| 97 | if (!screen_valid(TRUE)) |
| 98 | return FAIL; |
| 99 | |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 100 | if (type == UPD_VALID_NO_UPDATE) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 101 | { |
| 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 Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 135 | if (curwin->w_lines_valid == 0 && type < UPD_NOT_VALID |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 136 | #ifdef FEAT_TERMINAL |
| 137 | && !term_do_update_window(curwin) |
| 138 | #endif |
| 139 | ) |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 140 | type = UPD_NOT_VALID; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 141 | |
| 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 Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 148 | if (type > UPD_INVERTED_ALL) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 149 | curwin->w_lines_valid = 0; // don't use w_lines[].wl_size now |
| 150 | return FAIL; |
| 151 | } |
| 152 | updating_screen = TRUE; |
| 153 | |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 154 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 155 | // 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 Moolenaar | f73e5ba | 2022-08-29 12:41:06 +0100 | [diff] [blame] | 171 | if (type != UPD_CLEAR) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 172 | { |
Bram Moolenaar | f73e5ba | 2022-08-29 12:41:06 +0100 | [diff] [blame] | 173 | if (msg_scrolled > Rows - 5) // redrawing is faster |
Bram Moolenaar | b13d340 | 2022-08-29 13:44:28 +0100 | [diff] [blame] | 174 | { |
Bram Moolenaar | f73e5ba | 2022-08-29 12:41:06 +0100 | [diff] [blame] | 175 | type = UPD_NOT_VALID; |
Bram Moolenaar | b13d340 | 2022-08-29 13:44:28 +0100 | [diff] [blame] | 176 | redraw_as_cleared(); |
| 177 | } |
Bram Moolenaar | f73e5ba | 2022-08-29 12:41:06 +0100 | [diff] [blame] | 178 | else |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 179 | { |
Bram Moolenaar | f73e5ba | 2022-08-29 12:41:06 +0100 | [diff] [blame] | 180 | check_for_delay(FALSE); |
| 181 | if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, 0, NULL) |
| 182 | == FAIL) |
Bram Moolenaar | b13d340 | 2022-08-29 13:44:28 +0100 | [diff] [blame] | 183 | { |
Bram Moolenaar | f73e5ba | 2022-08-29 12:41:06 +0100 | [diff] [blame] | 184 | type = UPD_NOT_VALID; |
Bram Moolenaar | b13d340 | 2022-08-29 13:44:28 +0100 | [diff] [blame] | 185 | redraw_as_cleared(); |
| 186 | } |
Bram Moolenaar | f73e5ba | 2022-08-29 12:41:06 +0100 | [diff] [blame] | 187 | FOR_ALL_WINDOWS(wp) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 188 | { |
Bram Moolenaar | f73e5ba | 2022-08-29 12:41:06 +0100 | [diff] [blame] | 189 | if (wp->w_winrow < msg_scrolled) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 190 | { |
Bram Moolenaar | f73e5ba | 2022-08-29 12:41:06 +0100 | [diff] [blame] | 191 | 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 Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 206 | } |
| 207 | } |
Bram Moolenaar | f73e5ba | 2022-08-29 12:41:06 +0100 | [diff] [blame] | 208 | if (!no_update) |
| 209 | redraw_cmdline = TRUE; |
| 210 | redraw_tabline = TRUE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 211 | } |
Naruhiko Nishino | be5bd4d | 2025-05-14 21:20:28 +0200 | [diff] [blame] | 212 | #if defined(FEAT_TABPANEL) |
| 213 | redraw_tabpanel = TRUE; |
| 214 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 215 | } |
| 216 | msg_scrolled = 0; |
| 217 | need_wait_return = FALSE; |
| 218 | } |
| 219 | |
| 220 | // reset cmdline_row now (may have been changed temporarily) |
| 221 | compute_cmdrow(); |
| 222 | |
| 223 | // Check for changed highlighting |
| 224 | if (need_highlight_changed) |
| 225 | highlight_changed(); |
| 226 | |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 227 | if (type == UPD_CLEAR) // first clear screen |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 228 | { |
| 229 | screenclear(); // will reset clear_cmdline |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 230 | type = UPD_NOT_VALID; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 231 | // must_redraw may be set indirectly, avoid another redraw later |
| 232 | must_redraw = 0; |
| 233 | } |
| 234 | |
| 235 | if (clear_cmdline) // going to clear cmdline (done below) |
| 236 | check_for_delay(FALSE); |
| 237 | |
| 238 | #ifdef FEAT_LINEBREAK |
| 239 | // Force redraw when width of 'number' or 'relativenumber' column |
| 240 | // changes. |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 241 | if (curwin->w_redr_type < UPD_NOT_VALID |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 242 | && curwin->w_nrwidth != ((curwin->w_p_nu || curwin->w_p_rnu) |
| 243 | ? number_width(curwin) : 0)) |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 244 | curwin->w_redr_type = UPD_NOT_VALID; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 245 | #endif |
| 246 | |
| 247 | // Only start redrawing if there is really something to do. |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 248 | if (type == UPD_INVERTED) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 249 | update_curswant(); |
| 250 | if (curwin->w_redr_type < type |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 251 | && !((type == UPD_VALID |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 252 | && curwin->w_lines[0].wl_valid |
| 253 | #ifdef FEAT_DIFF |
| 254 | && curwin->w_topfill == curwin->w_old_topfill |
| 255 | && curwin->w_botfill == curwin->w_old_botfill |
| 256 | #endif |
| 257 | && curwin->w_topline == curwin->w_lines[0].wl_lnum) |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 258 | || (type == UPD_INVERTED |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 259 | && VIsual_active |
| 260 | && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum |
| 261 | && curwin->w_old_visual_mode == VIsual_mode |
| 262 | && (curwin->w_valid & VALID_VIRTCOL) |
| 263 | && curwin->w_old_curswant == curwin->w_curswant) |
| 264 | )) |
| 265 | curwin->w_redr_type = type; |
| 266 | |
| 267 | // Redraw the tab pages line if needed. |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 268 | if (redraw_tabline || type >= UPD_NOT_VALID) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 269 | draw_tabline(); |
| 270 | |
Naruhiko Nishino | be5bd4d | 2025-05-14 21:20:28 +0200 | [diff] [blame] | 271 | #if defined(FEAT_TABPANEL) |
| 272 | if (redraw_tabpanel || type >= UPD_NOT_VALID) |
| 273 | draw_tabpanel(); |
| 274 | #endif |
| 275 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 276 | #ifdef FEAT_SYN_HL |
| 277 | // Correct stored syntax highlighting info for changes in each displayed |
| 278 | // buffer. Each buffer must only be done once. |
| 279 | FOR_ALL_WINDOWS(wp) |
| 280 | { |
| 281 | if (wp->w_buffer->b_mod_set) |
| 282 | { |
| 283 | win_T *wwp; |
| 284 | |
| 285 | // Check if we already did this buffer. |
| 286 | for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) |
| 287 | if (wwp->w_buffer == wp->w_buffer) |
| 288 | break; |
| 289 | if (wwp == wp && syntax_present(wp)) |
| 290 | syn_stack_apply_changes(wp->w_buffer); |
| 291 | } |
| 292 | } |
| 293 | #endif |
| 294 | |
Bram Moolenaar | e0c03c8 | 2021-04-23 21:01:34 +0200 | [diff] [blame] | 295 | if (pum_redraw_in_same_position()) |
| 296 | // Avoid flicker if the popup menu is going to be redrawn in the same |
| 297 | // position. |
| 298 | pum_will_redraw = TRUE; |
| 299 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 300 | // Go from top to bottom through the windows, redrawing the ones that need |
| 301 | // it. |
| 302 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
Bram Moolenaar | e52e0c8 | 2020-02-28 22:20:10 +0100 | [diff] [blame] | 303 | did_update_one_window = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 304 | #endif |
| 305 | #ifdef FEAT_SEARCH_EXTRA |
| 306 | screen_search_hl.rm.regprog = NULL; |
| 307 | #endif |
| 308 | FOR_ALL_WINDOWS(wp) |
| 309 | { |
| 310 | if (wp->w_redr_type != 0) |
| 311 | { |
| 312 | cursor_off(); |
Bram Moolenaar | e52e0c8 | 2020-02-28 22:20:10 +0100 | [diff] [blame] | 313 | #ifdef FEAT_GUI |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 314 | if (!did_one) |
| 315 | { |
| 316 | did_one = TRUE; |
Bram Moolenaar | e52e0c8 | 2020-02-28 22:20:10 +0100 | [diff] [blame] | 317 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 318 | // Remove the cursor before starting to do anything, because |
| 319 | // scrolling may make it difficult to redraw the text under |
| 320 | // it. |
Bram Moolenaar | 09f067f | 2021-04-11 13:29:18 +0200 | [diff] [blame] | 321 | // Also remove the cursor if it needs to be hidden due to an |
| 322 | // ongoing cursor-less sleep. |
| 323 | if (gui.in_use && (wp == curwin || cursor_is_sleeping())) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 324 | { |
| 325 | gui_cursor_col = gui.cursor_col; |
| 326 | gui_cursor_row = gui.cursor_row; |
| 327 | gui_undraw_cursor(); |
| 328 | did_undraw = TRUE; |
| 329 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 330 | } |
| 331 | #endif |
| 332 | win_update(wp); |
| 333 | } |
| 334 | |
| 335 | // redraw status line after the window to minimize cursor movement |
| 336 | if (wp->w_redr_status) |
| 337 | { |
| 338 | cursor_off(); |
| 339 | win_redr_status(wp, TRUE); // any popup menu will be redrawn below |
| 340 | } |
| 341 | } |
| 342 | #if defined(FEAT_SEARCH_EXTRA) |
| 343 | end_search_hl(); |
| 344 | #endif |
Bram Moolenaar | e0c03c8 | 2021-04-23 21:01:34 +0200 | [diff] [blame] | 345 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 346 | // May need to redraw the popup menu. |
Bram Moolenaar | e0c03c8 | 2021-04-23 21:01:34 +0200 | [diff] [blame] | 347 | pum_will_redraw = save_pum_will_redraw; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 348 | pum_may_redraw(); |
| 349 | |
| 350 | // Reset b_mod_set flags. Going through all windows is probably faster |
| 351 | // than going through all buffers (there could be many buffers). |
| 352 | FOR_ALL_WINDOWS(wp) |
| 353 | wp->w_buffer->b_mod_set = FALSE; |
| 354 | |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 355 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 356 | // Display popup windows on top of the windows and command line. |
| 357 | update_popups(win_update); |
| 358 | #endif |
| 359 | |
Bram Moolenaar | 3194e5b | 2021-12-13 21:59:09 +0000 | [diff] [blame] | 360 | #ifdef FEAT_TERMINAL |
| 361 | FOR_ALL_WINDOWS(wp) |
| 362 | // If this window contains a terminal, after redrawing all windows, the |
| 363 | // dirty row range can be reset. |
| 364 | term_did_update_window(wp); |
| 365 | #endif |
| 366 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 367 | after_updating_screen(TRUE); |
| 368 | |
| 369 | // Clear or redraw the command line. Done last, because scrolling may |
| 370 | // mess up the command line. |
| 371 | if (clear_cmdline || redraw_cmdline || redraw_mode) |
| 372 | showmode(); |
| 373 | |
| 374 | if (no_update) |
| 375 | --no_win_do_lines_ins; |
| 376 | |
| 377 | // May put up an introductory message when not editing a file |
| 378 | if (!did_intro) |
| 379 | maybe_intro_message(); |
| 380 | did_intro = TRUE; |
| 381 | |
| 382 | #ifdef FEAT_GUI |
| 383 | // Redraw the cursor and update the scrollbars when all screen updating is |
| 384 | // done. |
| 385 | if (gui.in_use) |
| 386 | { |
| 387 | if (did_undraw && !gui_mch_is_blink_off()) |
| 388 | { |
| 389 | mch_disable_flush(); |
| 390 | out_flush(); // required before updating the cursor |
| 391 | mch_enable_flush(); |
| 392 | |
| 393 | // Put the GUI position where the cursor was, gui_update_cursor() |
| 394 | // uses that. |
| 395 | gui.col = gui_cursor_col; |
| 396 | gui.row = gui_cursor_row; |
| 397 | gui.col = mb_fix_col(gui.col, gui.row); |
| 398 | gui_update_cursor(FALSE, FALSE); |
| 399 | gui_may_flush(); |
| 400 | screen_cur_col = gui.col; |
| 401 | screen_cur_row = gui.row; |
| 402 | } |
| 403 | else |
| 404 | out_flush(); |
| 405 | gui_update_scrollbars(FALSE); |
| 406 | } |
| 407 | #endif |
| 408 | return OK; |
| 409 | } |
| 410 | |
| 411 | /* |
Bram Moolenaar | ae0f151 | 2021-03-30 22:12:12 +0200 | [diff] [blame] | 412 | * Return the row for drawing the statusline and the ruler of window "wp". |
| 413 | */ |
Bram Moolenaar | 49c51b8 | 2021-04-01 16:16:18 +0200 | [diff] [blame] | 414 | int |
Bram Moolenaar | ae0f151 | 2021-03-30 22:12:12 +0200 | [diff] [blame] | 415 | statusline_row(win_T *wp) |
| 416 | { |
| 417 | #if defined(FEAT_PROP_POPUP) |
| 418 | // If the window is really zero height the winbar isn't displayed. |
| 419 | if (wp->w_frame->fr_height == wp->w_status_height && !popup_is_popup(wp)) |
| 420 | return wp->w_winrow; |
| 421 | #endif |
| 422 | return W_WINROW(wp) + wp->w_height; |
| 423 | } |
| 424 | |
| 425 | /* |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 426 | * Redraw the status line of window wp. |
| 427 | * |
| 428 | * If inversion is possible we use it. Else '=' characters are used. |
| 429 | * If "ignore_pum" is TRUE, also redraw statusline when the popup menu is |
| 430 | * displayed. |
| 431 | */ |
Luuk van Baal | ba936f6 | 2022-12-15 13:15:39 +0000 | [diff] [blame] | 432 | void |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 433 | win_redr_status(win_T *wp, int ignore_pum UNUSED) |
| 434 | { |
| 435 | int row; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 436 | int fillchar; |
| 437 | int attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 438 | static int busy = FALSE; |
| 439 | |
| 440 | // It's possible to get here recursively when 'statusline' (indirectly) |
| 441 | // invokes ":redrawstatus". Simply ignore the call then. |
| 442 | if (busy) |
| 443 | return; |
| 444 | busy = TRUE; |
| 445 | |
Bram Moolenaar | ae0f151 | 2021-03-30 22:12:12 +0200 | [diff] [blame] | 446 | row = statusline_row(wp); |
| 447 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 448 | wp->w_redr_status = FALSE; |
| 449 | if (wp->w_status_height == 0) |
| 450 | { |
| 451 | // no status line, can only be last window |
| 452 | redraw_cmdline = TRUE; |
| 453 | } |
| 454 | else if (!redrawing() |
| 455 | // don't update status line when popup menu is visible and may be |
| 456 | // drawn over it, unless it will be redrawn later |
| 457 | || (!ignore_pum && pum_visible())) |
| 458 | { |
| 459 | // Don't redraw right now, do it later. |
| 460 | wp->w_redr_status = TRUE; |
| 461 | } |
| 462 | #ifdef FEAT_STL_OPT |
| 463 | else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
| 464 | { |
| 465 | // redraw custom status line |
| 466 | redraw_custom_statusline(wp); |
| 467 | } |
| 468 | #endif |
| 469 | else |
| 470 | { |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 471 | char_u *p; |
| 472 | int plen; |
| 473 | int NameBufflen; |
| 474 | int this_ru_col; |
| 475 | int n; // scratch value |
| 476 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 477 | fillchar = fillchar_status(&attr, wp); |
| 478 | |
| 479 | get_trans_bufname(wp->w_buffer); |
| 480 | p = NameBuff; |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 481 | plen = (int)STRLEN(p); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 482 | |
Bram Moolenaar | de05bb2 | 2022-01-13 13:08:14 +0000 | [diff] [blame] | 483 | if ((bt_help(wp->w_buffer) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 484 | #ifdef FEAT_QUICKFIX |
Bram Moolenaar | de05bb2 | 2022-01-13 13:08:14 +0000 | [diff] [blame] | 485 | || wp->w_p_pvw |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 486 | #endif |
Bram Moolenaar | de05bb2 | 2022-01-13 13:08:14 +0000 | [diff] [blame] | 487 | || bufIsChanged(wp->w_buffer) |
| 488 | || wp->w_buffer->b_p_ro) |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 489 | && plen < MAXPATHL - 1) |
John Marriott | 70dfc37 | 2025-01-16 18:58:20 +0100 | [diff] [blame] | 490 | { |
| 491 | *(p + plen++) = ' '; // replace NUL with space |
| 492 | *(p + plen) = NUL; // NUL terminate the string |
| 493 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 494 | if (bt_help(wp->w_buffer)) |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 495 | plen += vim_snprintf((char *)p + plen, MAXPATHL - plen, "%s", _("[Help]")); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 496 | #ifdef FEAT_QUICKFIX |
| 497 | if (wp->w_p_pvw) |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 498 | plen += vim_snprintf((char *)p + plen, MAXPATHL - plen, "%s", _("[Preview]")); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 499 | #endif |
Bram Moolenaar | 6d4b2f5 | 2022-08-25 15:11:15 +0100 | [diff] [blame] | 500 | if (bufIsChanged(wp->w_buffer) && !bt_terminal(wp->w_buffer)) |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 501 | plen += vim_snprintf((char *)p + plen, MAXPATHL - plen, "%s", "[+]"); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 502 | if (wp->w_buffer->b_p_ro) |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 503 | plen += vim_snprintf((char *)p + plen, MAXPATHL - plen, "%s", _("[RO]")); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 504 | |
| 505 | this_ru_col = ru_col - (Columns - wp->w_width); |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 506 | n = (wp->w_width + 1) / 2; |
| 507 | if (this_ru_col < n) |
| 508 | this_ru_col = n; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 509 | if (this_ru_col <= 1) |
| 510 | { |
| 511 | p = (char_u *)"<"; // No room for file name! |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 512 | plen = 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 513 | } |
| 514 | else if (has_mbyte) |
| 515 | { |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 516 | int i; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 517 | |
| 518 | // Count total number of display cells. |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 519 | plen = mb_string2cells(p, -1); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 520 | |
| 521 | // Find first character that will fit. |
| 522 | // Going from start to end is much faster for DBCS. |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 523 | for (i = 0; p[i] != NUL && plen >= this_ru_col - 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 524 | i += (*mb_ptr2len)(p + i)) |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 525 | plen -= (*mb_ptr2cells)(p + i); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 526 | if (i > 0) |
| 527 | { |
| 528 | p = p + i - 1; |
| 529 | *p = '<'; |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 530 | ++plen; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 531 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 532 | } |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 533 | else if (plen > this_ru_col - 1) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 534 | { |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 535 | p += plen - (this_ru_col - 1); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 536 | *p = '<'; |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 537 | plen = this_ru_col - 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 538 | } |
| 539 | |
Hirohito Higashi | 3b9b95d | 2025-06-01 20:22:55 +0200 | [diff] [blame] | 540 | screen_puts(p, row, wp->w_wincol, attr); |
| 541 | screen_fill(row, row + 1, plen + wp->w_wincol, |
| 542 | this_ru_col + wp->w_wincol, fillchar, fillchar, attr); |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 543 | if ((NameBufflen = get_keymap_str(wp, (char_u *)"<%s>", NameBuff, MAXPATHL)) > 0 |
| 544 | && (this_ru_col - plen) > (NameBufflen + 1)) |
| 545 | screen_puts(NameBuff, row, (int)(this_ru_col - NameBufflen |
Hirohito Higashi | 3b9b95d | 2025-06-01 20:22:55 +0200 | [diff] [blame] | 546 | - 1 + wp->w_wincol), attr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 547 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 548 | win_redr_ruler(wp, TRUE, ignore_pum); |
Luuk van Baal | ba936f6 | 2022-12-15 13:15:39 +0000 | [diff] [blame] | 549 | |
| 550 | // Draw the 'showcmd' information if 'showcmdloc' == "statusline". |
| 551 | if (p_sc && *p_sloc == 's') |
| 552 | { |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 553 | n = this_ru_col - plen - 2; // perform the calculation here so we only do it once |
| 554 | int width = MIN(10, n); |
Luuk van Baal | ba936f6 | 2022-12-15 13:15:39 +0000 | [diff] [blame] | 555 | |
| 556 | if (width > 0) |
| 557 | screen_puts_len(showcmd_buf, width, row, |
| 558 | wp->w_wincol + this_ru_col - width - 1, attr); |
| 559 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | /* |
| 563 | * May need to draw the character below the vertical separator. |
| 564 | */ |
| 565 | if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) |
| 566 | { |
| 567 | if (stl_connected(wp)) |
| 568 | fillchar = fillchar_status(&attr, wp); |
| 569 | else |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 570 | fillchar = fillchar_vsep(&attr, wp); |
Hirohito Higashi | 3b9b95d | 2025-06-01 20:22:55 +0200 | [diff] [blame] | 571 | screen_putchar(fillchar, row, W_ENDCOL(wp), attr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 572 | } |
| 573 | busy = FALSE; |
| 574 | } |
| 575 | |
| 576 | #ifdef FEAT_STL_OPT |
| 577 | /* |
| 578 | * Redraw the status line according to 'statusline' and take care of any |
| 579 | * errors encountered. |
| 580 | */ |
| 581 | static void |
| 582 | redraw_custom_statusline(win_T *wp) |
| 583 | { |
| 584 | static int entered = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 585 | |
| 586 | // When called recursively return. This can happen when the statusline |
| 587 | // contains an expression that triggers a redraw. |
| 588 | if (entered) |
| 589 | return; |
| 590 | entered = TRUE; |
| 591 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 592 | win_redr_custom(wp, FALSE); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 593 | entered = FALSE; |
| 594 | } |
| 595 | #endif |
| 596 | |
| 597 | /* |
| 598 | * Show current status info in ruler and various other places |
| 599 | * If always is FALSE, only show ruler if position has changed. |
| 600 | */ |
| 601 | void |
| 602 | showruler(int always) |
| 603 | { |
| 604 | if (!always && !redrawing()) |
| 605 | return; |
| 606 | if (pum_visible()) |
| 607 | { |
| 608 | // Don't redraw right now, do it later. |
| 609 | curwin->w_redr_status = TRUE; |
| 610 | return; |
| 611 | } |
| 612 | #if defined(FEAT_STL_OPT) |
| 613 | if ((*p_stl != NUL || *curwin->w_p_stl != NUL) && curwin->w_status_height) |
| 614 | redraw_custom_statusline(curwin); |
| 615 | else |
| 616 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 617 | win_redr_ruler(curwin, always, FALSE); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 618 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 619 | if (need_maketitle |
Bram Moolenaar | 651fca8 | 2021-11-29 20:39:38 +0000 | [diff] [blame] | 620 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 621 | || (p_icon && (stl_syntax & STL_IN_ICON)) |
| 622 | || (p_title && (stl_syntax & STL_IN_TITLE)) |
Bram Moolenaar | 651fca8 | 2021-11-29 20:39:38 +0000 | [diff] [blame] | 623 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 624 | ) |
| 625 | maketitle(); |
Bram Moolenaar | 651fca8 | 2021-11-29 20:39:38 +0000 | [diff] [blame] | 626 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 627 | // Redraw the tab pages line if needed. |
| 628 | if (redraw_tabline) |
| 629 | draw_tabline(); |
Naruhiko Nishino | be5bd4d | 2025-05-14 21:20:28 +0200 | [diff] [blame] | 630 | |
| 631 | #if defined(FEAT_TABPANEL) |
| 632 | if (redraw_tabpanel) |
| 633 | draw_tabpanel(); |
| 634 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 635 | } |
| 636 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 637 | void |
| 638 | win_redr_ruler(win_T *wp, int always, int ignore_pum) |
| 639 | { |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 640 | int empty_line = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 641 | |
Bram Moolenaar | a2a8973 | 2022-08-31 14:46:18 +0100 | [diff] [blame] | 642 | // If 'ruler' off don't do anything |
| 643 | if (!p_ru) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 644 | return; |
| 645 | |
| 646 | /* |
| 647 | * Check if cursor.lnum is valid, since win_redr_ruler() may be called |
| 648 | * after deleting lines, before cursor.lnum is corrected. |
| 649 | */ |
| 650 | if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) |
| 651 | return; |
| 652 | |
| 653 | // Don't draw the ruler while doing insert-completion, it might overwrite |
| 654 | // the (long) mode message. |
| 655 | if (wp == lastwin && lastwin->w_status_height == 0) |
| 656 | if (edit_submode != NULL) |
| 657 | return; |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 658 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 659 | // Don't draw the ruler when the popup menu is visible, it may overlap. |
| 660 | // Except when the popup menu will be redrawn anyway. |
| 661 | if (!ignore_pum && pum_visible()) |
| 662 | return; |
| 663 | |
| 664 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | a2a8973 | 2022-08-31 14:46:18 +0100 | [diff] [blame] | 665 | if (*p_ruf) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 666 | { |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 667 | win_redr_custom(wp, TRUE); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 668 | return; |
| 669 | } |
| 670 | #endif |
| 671 | |
| 672 | /* |
| 673 | * Check if not in Insert mode and the line is empty (will show "0-1"). |
| 674 | */ |
Bram Moolenaar | 2495910 | 2022-05-07 20:01:16 +0100 | [diff] [blame] | 675 | if ((State & MODE_INSERT) == 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 676 | && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) |
| 677 | empty_line = TRUE; |
| 678 | |
| 679 | /* |
| 680 | * Only draw the ruler when something changed. |
| 681 | */ |
| 682 | validate_virtcol_win(wp); |
| 683 | if ( redraw_cmdline |
| 684 | || always |
| 685 | || wp->w_cursor.lnum != wp->w_ru_cursor.lnum |
| 686 | || wp->w_cursor.col != wp->w_ru_cursor.col |
| 687 | || wp->w_virtcol != wp->w_ru_virtcol |
| 688 | || wp->w_cursor.coladd != wp->w_ru_cursor.coladd |
| 689 | || wp->w_topline != wp->w_ru_topline |
| 690 | || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count |
| 691 | #ifdef FEAT_DIFF |
| 692 | || wp->w_topfill != wp->w_ru_topfill |
| 693 | #endif |
| 694 | || empty_line != wp->w_ru_empty) |
| 695 | { |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 696 | int row; |
| 697 | int fillchar; |
| 698 | int attr; |
| 699 | int off; |
| 700 | int width; |
| 701 | colnr_T virtcol; |
| 702 | #define RULER_BUF_LEN 70 |
| 703 | char_u buffer[RULER_BUF_LEN]; |
| 704 | int bufferlen; |
| 705 | char_u rel_pos[RULER_BUF_LEN]; |
| 706 | int rel_poslen; |
| 707 | int this_ru_col; |
| 708 | int n1; // scratch value |
| 709 | int n2; // scratch value |
| 710 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 711 | cursor_off(); |
| 712 | if (wp->w_status_height) |
| 713 | { |
Bram Moolenaar | ae0f151 | 2021-03-30 22:12:12 +0200 | [diff] [blame] | 714 | row = statusline_row(wp); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 715 | fillchar = fillchar_status(&attr, wp); |
| 716 | off = wp->w_wincol; |
| 717 | width = wp->w_width; |
| 718 | } |
| 719 | else |
| 720 | { |
| 721 | row = Rows - 1; |
| 722 | fillchar = ' '; |
| 723 | attr = 0; |
| 724 | width = Columns; |
| 725 | off = 0; |
| 726 | } |
| 727 | |
| 728 | // In list mode virtcol needs to be recomputed |
| 729 | virtcol = wp->w_virtcol; |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 730 | if (wp->w_p_list && wp->w_lcs_chars.tab1 == NUL) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 731 | { |
| 732 | wp->w_p_list = FALSE; |
| 733 | getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); |
| 734 | wp->w_p_list = TRUE; |
| 735 | } |
| 736 | |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 737 | bufferlen = vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,", |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 738 | (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
| 739 | ? 0L |
| 740 | : (long)(wp->w_cursor.lnum)); |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 741 | bufferlen += col_print(buffer + bufferlen, RULER_BUF_LEN - bufferlen, |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 742 | empty_line ? 0 : (int)wp->w_cursor.col + 1, |
| 743 | (int)virtcol + 1); |
| 744 | |
| 745 | /* |
| 746 | * Add a "50%" if there is room for it. |
| 747 | * On the last line, don't print in the last column (scrolls the |
| 748 | * screen up on some terminals). |
| 749 | */ |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 750 | rel_poslen = get_rel_pos(wp, rel_pos, RULER_BUF_LEN); |
| 751 | n1 = bufferlen + vim_strsize(rel_pos); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 752 | if (wp->w_status_height == 0) // can't use last char of screen |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 753 | ++n1; |
| 754 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 755 | this_ru_col = ru_col - (Columns - width); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 756 | // Never use more than half the window/screen width, leave the other |
| 757 | // half for the filename. |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 758 | n2 = (width + 1) / 2; |
| 759 | if (this_ru_col < n2) |
| 760 | this_ru_col = n2; |
| 761 | if (this_ru_col + n1 < width) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 762 | { |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 763 | // need at least space for rel_pos + NUL |
| 764 | while (this_ru_col + n1 < width |
| 765 | && RULER_BUF_LEN > bufferlen + rel_poslen + 1) // +1 for NUL |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 766 | { |
| 767 | if (has_mbyte) |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 768 | bufferlen += (*mb_char2bytes)(fillchar, buffer + bufferlen); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 769 | else |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 770 | buffer[bufferlen++] = fillchar; |
| 771 | ++n1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 772 | } |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 773 | bufferlen += vim_snprintf((char *)buffer + bufferlen, RULER_BUF_LEN - bufferlen, |
| 774 | "%s", rel_pos); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 775 | } |
| 776 | // Truncate at window boundary. |
| 777 | if (has_mbyte) |
| 778 | { |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 779 | for (n1 = 0, n2 = 0; buffer[n1] != NUL; n1 += (*mb_ptr2len)(buffer + n1)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 780 | { |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 781 | n2 += (*mb_ptr2cells)(buffer + n1); |
| 782 | if (this_ru_col + n2 > width) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 783 | { |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 784 | bufferlen = n1; |
| 785 | buffer[bufferlen] = NUL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 786 | break; |
| 787 | } |
| 788 | } |
| 789 | } |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 790 | else if (this_ru_col + bufferlen > width) |
| 791 | { |
| 792 | bufferlen = width - this_ru_col; |
| 793 | buffer[bufferlen] = NUL; |
| 794 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 795 | |
Hirohito Higashi | 3b9b95d | 2025-06-01 20:22:55 +0200 | [diff] [blame] | 796 | screen_puts(buffer, row, this_ru_col + off, attr); |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 797 | n1 = redraw_cmdline; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 798 | screen_fill(row, row + 1, |
Hirohito Higashi | 3b9b95d | 2025-06-01 20:22:55 +0200 | [diff] [blame] | 799 | this_ru_col + off + bufferlen, |
| 800 | (off + width), |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 801 | fillchar, fillchar, attr); |
| 802 | // don't redraw the cmdline because of showing the ruler |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 803 | redraw_cmdline = n1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 804 | wp->w_ru_cursor = wp->w_cursor; |
| 805 | wp->w_ru_virtcol = wp->w_virtcol; |
| 806 | wp->w_ru_empty = empty_line; |
| 807 | wp->w_ru_topline = wp->w_topline; |
| 808 | wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; |
| 809 | #ifdef FEAT_DIFF |
| 810 | wp->w_ru_topfill = wp->w_topfill; |
| 811 | #endif |
| 812 | } |
| 813 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 814 | |
| 815 | /* |
| 816 | * To be called when "updating_screen" was set before and now the postponed |
| 817 | * side effects may take place. |
| 818 | */ |
| 819 | void |
| 820 | after_updating_screen(int may_resize_shell UNUSED) |
| 821 | { |
| 822 | updating_screen = FALSE; |
| 823 | #ifdef FEAT_GUI |
| 824 | if (may_resize_shell) |
| 825 | gui_may_resize_shell(); |
| 826 | #endif |
| 827 | #ifdef FEAT_TERMINAL |
| 828 | term_check_channel_closed_recently(); |
| 829 | #endif |
| 830 | |
| 831 | #ifdef HAVE_DROP_FILE |
| 832 | // If handle_drop() was called while updating_screen was TRUE need to |
| 833 | // handle the drop now. |
| 834 | handle_any_postponed_drop(); |
| 835 | #endif |
| 836 | } |
| 837 | |
| 838 | /* |
| 839 | * Update all windows that are editing the current buffer. |
| 840 | */ |
| 841 | void |
| 842 | update_curbuf(int type) |
| 843 | { |
| 844 | redraw_curbuf_later(type); |
| 845 | update_screen(type); |
| 846 | } |
| 847 | |
| 848 | #if defined(FEAT_MENU) || defined(FEAT_FOLDING) |
| 849 | /* |
| 850 | * Copy "text" to ScreenLines using "attr". |
| 851 | * Returns the next screen column. |
| 852 | */ |
| 853 | static int |
| 854 | text_to_screenline(win_T *wp, char_u *text, int col) |
| 855 | { |
| 856 | int off = (int)(current_ScreenLine - ScreenLines); |
| 857 | |
| 858 | if (has_mbyte) |
| 859 | { |
| 860 | int cells; |
| 861 | int u8c, u8cc[MAX_MCO]; |
| 862 | int i; |
| 863 | int idx; |
| 864 | int c_len; |
| 865 | char_u *p; |
| 866 | # ifdef FEAT_ARABIC |
| 867 | int prev_c = 0; // previous Arabic character |
| 868 | int prev_c1 = 0; // first composing char for prev_c |
| 869 | # endif |
| 870 | |
| 871 | # ifdef FEAT_RIGHTLEFT |
| 872 | if (wp->w_p_rl) |
| 873 | idx = off; |
| 874 | else |
| 875 | # endif |
| 876 | idx = off + col; |
| 877 | |
| 878 | // Store multibyte characters in ScreenLines[] et al. correctly. |
| 879 | for (p = text; *p != NUL; ) |
| 880 | { |
| 881 | cells = (*mb_ptr2cells)(p); |
| 882 | c_len = (*mb_ptr2len)(p); |
| 883 | if (col + cells > wp->w_width |
| 884 | # ifdef FEAT_RIGHTLEFT |
| 885 | - (wp->w_p_rl ? col : 0) |
| 886 | # endif |
| 887 | ) |
| 888 | break; |
| 889 | ScreenLines[idx] = *p; |
| 890 | if (enc_utf8) |
| 891 | { |
| 892 | u8c = utfc_ptr2char(p, u8cc); |
| 893 | if (*p < 0x80 && u8cc[0] == 0) |
| 894 | { |
| 895 | ScreenLinesUC[idx] = 0; |
| 896 | #ifdef FEAT_ARABIC |
| 897 | prev_c = u8c; |
| 898 | #endif |
| 899 | } |
| 900 | else |
| 901 | { |
| 902 | #ifdef FEAT_ARABIC |
| 903 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 904 | { |
| 905 | // Do Arabic shaping. |
| 906 | int pc, pc1, nc; |
| 907 | int pcc[MAX_MCO]; |
| 908 | int firstbyte = *p; |
| 909 | |
| 910 | // The idea of what is the previous and next |
| 911 | // character depends on 'rightleft'. |
| 912 | if (wp->w_p_rl) |
| 913 | { |
| 914 | pc = prev_c; |
| 915 | pc1 = prev_c1; |
| 916 | nc = utf_ptr2char(p + c_len); |
| 917 | prev_c1 = u8cc[0]; |
| 918 | } |
| 919 | else |
| 920 | { |
| 921 | pc = utfc_ptr2char(p + c_len, pcc); |
| 922 | nc = prev_c; |
| 923 | pc1 = pcc[0]; |
| 924 | } |
| 925 | prev_c = u8c; |
| 926 | |
| 927 | u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
| 928 | pc, pc1, nc); |
| 929 | ScreenLines[idx] = firstbyte; |
| 930 | } |
| 931 | else |
| 932 | prev_c = u8c; |
| 933 | #endif |
| 934 | // Non-BMP character: display as ? or fullwidth ?. |
| 935 | ScreenLinesUC[idx] = u8c; |
| 936 | for (i = 0; i < Screen_mco; ++i) |
| 937 | { |
| 938 | ScreenLinesC[i][idx] = u8cc[i]; |
| 939 | if (u8cc[i] == 0) |
| 940 | break; |
| 941 | } |
| 942 | } |
| 943 | if (cells > 1) |
| 944 | ScreenLines[idx + 1] = 0; |
| 945 | } |
| 946 | else if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
| 947 | // double-byte single width character |
| 948 | ScreenLines2[idx] = p[1]; |
| 949 | else if (cells > 1) |
| 950 | // double-width character |
| 951 | ScreenLines[idx + 1] = p[1]; |
| 952 | col += cells; |
| 953 | idx += cells; |
| 954 | p += c_len; |
| 955 | } |
| 956 | } |
| 957 | else |
| 958 | { |
| 959 | int len = (int)STRLEN(text); |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 960 | int n = wp->w_width - col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 961 | |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 962 | if (len > n) |
| 963 | len = n; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 964 | if (len > 0) |
| 965 | { |
| 966 | #ifdef FEAT_RIGHTLEFT |
| 967 | if (wp->w_p_rl) |
| 968 | mch_memmove(current_ScreenLine, text, len); |
| 969 | else |
| 970 | #endif |
| 971 | mch_memmove(current_ScreenLine + col, text, len); |
| 972 | col += len; |
| 973 | } |
| 974 | } |
| 975 | return col; |
| 976 | } |
| 977 | #endif |
| 978 | |
| 979 | #ifdef FEAT_MENU |
| 980 | /* |
| 981 | * Draw the window toolbar. |
| 982 | */ |
| 983 | static void |
| 984 | redraw_win_toolbar(win_T *wp) |
| 985 | { |
| 986 | vimmenu_T *menu; |
| 987 | int item_idx = 0; |
| 988 | int item_count = 0; |
| 989 | int col = 0; |
| 990 | int next_col; |
| 991 | int off = (int)(current_ScreenLine - ScreenLines); |
| 992 | int fill_attr = syn_name2attr((char_u *)"ToolbarLine"); |
| 993 | int button_attr = syn_name2attr((char_u *)"ToolbarButton"); |
| 994 | |
| 995 | vim_free(wp->w_winbar_items); |
Bram Moolenaar | 00d253e | 2020-04-06 22:13:01 +0200 | [diff] [blame] | 996 | FOR_ALL_CHILD_MENUS(wp->w_winbar, menu) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 997 | ++item_count; |
| 998 | wp->w_winbar_items = ALLOC_CLEAR_MULT(winbar_item_T, item_count + 1); |
| 999 | |
| 1000 | // TODO: use fewer spaces if there is not enough room |
| 1001 | for (menu = wp->w_winbar->children; |
| 1002 | menu != NULL && col < wp->w_width; menu = menu->next) |
| 1003 | { |
| 1004 | space_to_screenline(off + col, fill_attr); |
| 1005 | if (++col >= wp->w_width) |
| 1006 | break; |
| 1007 | if (col > 1) |
| 1008 | { |
| 1009 | space_to_screenline(off + col, fill_attr); |
| 1010 | if (++col >= wp->w_width) |
| 1011 | break; |
| 1012 | } |
| 1013 | |
| 1014 | wp->w_winbar_items[item_idx].wb_startcol = col; |
| 1015 | space_to_screenline(off + col, button_attr); |
| 1016 | if (++col >= wp->w_width) |
| 1017 | break; |
| 1018 | |
| 1019 | next_col = text_to_screenline(wp, menu->name, col); |
| 1020 | while (col < next_col) |
| 1021 | { |
| 1022 | ScreenAttrs[off + col] = button_attr; |
| 1023 | ++col; |
| 1024 | } |
| 1025 | wp->w_winbar_items[item_idx].wb_endcol = col; |
| 1026 | wp->w_winbar_items[item_idx].wb_menu = menu; |
| 1027 | ++item_idx; |
| 1028 | |
| 1029 | if (col >= wp->w_width) |
| 1030 | break; |
| 1031 | space_to_screenline(off + col, button_attr); |
| 1032 | ++col; |
| 1033 | } |
| 1034 | while (col < wp->w_width) |
| 1035 | { |
| 1036 | space_to_screenline(off + col, fill_attr); |
| 1037 | ++col; |
| 1038 | } |
| 1039 | wp->w_winbar_items[item_idx].wb_menu = NULL; // end marker |
| 1040 | |
Hirohito Higashi | 3b9b95d | 2025-06-01 20:22:55 +0200 | [diff] [blame] | 1041 | screen_line(wp, wp->w_winrow, wp->w_wincol, wp->w_width, |
Naruhiko Nishino | be5bd4d | 2025-05-14 21:20:28 +0200 | [diff] [blame] | 1042 | wp->w_width, -1, 0); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1043 | } |
| 1044 | #endif |
| 1045 | |
| 1046 | #if defined(FEAT_FOLDING) || defined(PROTO) |
| 1047 | /* |
| 1048 | * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". |
| 1049 | */ |
| 1050 | static void |
| 1051 | copy_text_attr( |
| 1052 | int off, |
| 1053 | char_u *buf, |
| 1054 | int len, |
| 1055 | int attr) |
| 1056 | { |
| 1057 | int i; |
| 1058 | |
| 1059 | mch_memmove(ScreenLines + off, buf, (size_t)len); |
| 1060 | if (enc_utf8) |
| 1061 | vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); |
| 1062 | for (i = 0; i < len; ++i) |
| 1063 | ScreenAttrs[off + i] = attr; |
| 1064 | } |
| 1065 | |
| 1066 | /* |
| 1067 | * Display one folded line. |
| 1068 | */ |
| 1069 | static void |
| 1070 | fold_line( |
| 1071 | win_T *wp, |
| 1072 | long fold_count, |
| 1073 | foldinfo_T *foldinfo, |
| 1074 | linenr_T lnum, |
| 1075 | int row) |
| 1076 | { |
Bram Moolenaar | 4fa1175 | 2021-03-03 13:26:02 +0100 | [diff] [blame] | 1077 | // Max value of 'foldcolumn' is 12 and maximum number of bytes in a |
| 1078 | // multi-byte character is MAX_MCO. |
| 1079 | char_u buf[MAX_MCO * 12 + 1]; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1080 | pos_T *top, *bot; |
| 1081 | linenr_T lnume = lnum + fold_count - 1; |
| 1082 | int len; |
| 1083 | char_u *text; |
| 1084 | int fdc; |
| 1085 | int col; |
| 1086 | int txtcol; |
| 1087 | int off = (int)(current_ScreenLine - ScreenLines); |
| 1088 | int ri; |
| 1089 | |
| 1090 | // Build the fold line: |
| 1091 | // 1. Add the cmdwin_type for the command-line window |
| 1092 | // 2. Add the 'foldcolumn' |
| 1093 | // 3. Add the 'number' or 'relativenumber' column |
| 1094 | // 4. Compose the text |
| 1095 | // 5. Add the text |
| 1096 | // 6. set highlighting for the Visual area an other text |
| 1097 | col = 0; |
| 1098 | |
| 1099 | // 1. Add the cmdwin_type for the command-line window |
| 1100 | // Ignores 'rightleft', this window is never right-left. |
Sean Dewar | 988f743 | 2023-08-16 14:17:36 +0100 | [diff] [blame] | 1101 | if (wp == cmdwin_win) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1102 | { |
| 1103 | ScreenLines[off] = cmdwin_type; |
| 1104 | ScreenAttrs[off] = HL_ATTR(HLF_AT); |
| 1105 | if (enc_utf8) |
| 1106 | ScreenLinesUC[off] = 0; |
| 1107 | ++col; |
| 1108 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1109 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1110 | #ifdef FEAT_RIGHTLEFT |
| 1111 | # define RL_MEMSET(p, v, l) \ |
| 1112 | do { \ |
| 1113 | if (wp->w_p_rl) \ |
kylo252 | ae6f1d8 | 2022-02-16 19:24:07 +0000 | [diff] [blame] | 1114 | for (ri = 0; ri < (l); ++ri) \ |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1115 | ScreenAttrs[off + (wp->w_width - (p) - (l)) + ri] = v; \ |
| 1116 | else \ |
kylo252 | ae6f1d8 | 2022-02-16 19:24:07 +0000 | [diff] [blame] | 1117 | for (ri = 0; ri < (l); ++ri) \ |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1118 | ScreenAttrs[off + (p) + ri] = v; \ |
| 1119 | } while (0) |
| 1120 | #else |
| 1121 | # define RL_MEMSET(p, v, l) \ |
| 1122 | do { \ |
| 1123 | for (ri = 0; ri < l; ++ri) \ |
| 1124 | ScreenAttrs[off + (p) + ri] = v; \ |
| 1125 | } while (0) |
| 1126 | #endif |
| 1127 | |
Bram Moolenaar | 4fa1175 | 2021-03-03 13:26:02 +0100 | [diff] [blame] | 1128 | // 2. Add the 'foldcolumn' |
| 1129 | // Reduce the width when there is not enough space. |
| 1130 | fdc = compute_foldcolumn(wp, col); |
| 1131 | if (fdc > 0) |
| 1132 | { |
| 1133 | char_u *p; |
| 1134 | int i; |
| 1135 | int idx; |
| 1136 | |
| 1137 | fill_foldcolumn(buf, wp, TRUE, lnum); |
| 1138 | p = buf; |
| 1139 | for (i = 0; i < fdc; i++) |
| 1140 | { |
| 1141 | int ch; |
| 1142 | |
| 1143 | if (has_mbyte) |
| 1144 | ch = mb_ptr2char_adv(&p); |
| 1145 | else |
| 1146 | ch = *p++; |
| 1147 | #ifdef FEAT_RIGHTLEFT |
| 1148 | if (wp->w_p_rl) |
| 1149 | idx = off + wp->w_width - i - 1 - col; |
| 1150 | else |
| 1151 | #endif |
| 1152 | idx = off + col + i; |
| 1153 | if (enc_utf8) |
| 1154 | { |
| 1155 | if (ch >= 0x80) |
| 1156 | { |
| 1157 | ScreenLinesUC[idx] = ch; |
| 1158 | ScreenLinesC[0][idx] = 0; |
| 1159 | ScreenLines[idx] = 0x80; |
| 1160 | } |
| 1161 | else |
| 1162 | { |
| 1163 | ScreenLines[idx] = ch; |
| 1164 | ScreenLinesUC[idx] = 0; |
| 1165 | } |
| 1166 | } |
| 1167 | else |
| 1168 | ScreenLines[idx] = ch; |
| 1169 | } |
| 1170 | |
| 1171 | RL_MEMSET(col, HL_ATTR(HLF_FC), fdc); |
| 1172 | col += fdc; |
| 1173 | } |
| 1174 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1175 | // Set all attributes of the 'number' or 'relativenumber' column and the |
| 1176 | // text |
| 1177 | RL_MEMSET(col, HL_ATTR(HLF_FL), wp->w_width - col); |
| 1178 | |
| 1179 | #ifdef FEAT_SIGNS |
| 1180 | // If signs are being displayed, add two spaces. |
| 1181 | if (signcolumn_on(wp)) |
| 1182 | { |
| 1183 | len = wp->w_width - col; |
| 1184 | if (len > 0) |
| 1185 | { |
| 1186 | if (len > 2) |
| 1187 | len = 2; |
| 1188 | # ifdef FEAT_RIGHTLEFT |
| 1189 | if (wp->w_p_rl) |
| 1190 | // the line number isn't reversed |
| 1191 | copy_text_attr(off + wp->w_width - len - col, |
| 1192 | (char_u *)" ", len, HL_ATTR(HLF_FL)); |
| 1193 | else |
| 1194 | # endif |
| 1195 | copy_text_attr(off + col, (char_u *)" ", len, HL_ATTR(HLF_FL)); |
| 1196 | col += len; |
| 1197 | } |
| 1198 | } |
| 1199 | #endif |
| 1200 | |
| 1201 | // 3. Add the 'number' or 'relativenumber' column |
| 1202 | if (wp->w_p_nu || wp->w_p_rnu) |
| 1203 | { |
| 1204 | len = wp->w_width - col; |
| 1205 | if (len > 0) |
| 1206 | { |
| 1207 | int w = number_width(wp); |
| 1208 | long num; |
| 1209 | char *fmt = "%*ld "; |
| 1210 | |
| 1211 | if (len > w + 1) |
| 1212 | len = w + 1; |
| 1213 | |
| 1214 | if (wp->w_p_nu && !wp->w_p_rnu) |
| 1215 | // 'number' + 'norelativenumber' |
| 1216 | num = (long)lnum; |
| 1217 | else |
| 1218 | { |
| 1219 | // 'relativenumber', don't use negative numbers |
| 1220 | num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
| 1221 | if (num == 0 && wp->w_p_nu && wp->w_p_rnu) |
| 1222 | { |
| 1223 | // 'number' + 'relativenumber': cursor line shows absolute |
| 1224 | // line number |
| 1225 | num = lnum; |
| 1226 | fmt = "%-*ld "; |
| 1227 | } |
| 1228 | } |
| 1229 | |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 1230 | vim_snprintf((char *)buf, sizeof(buf), fmt, w, num); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1231 | #ifdef FEAT_RIGHTLEFT |
| 1232 | if (wp->w_p_rl) |
| 1233 | // the line number isn't reversed |
| 1234 | copy_text_attr(off + wp->w_width - len - col, buf, len, |
| 1235 | HL_ATTR(HLF_FL)); |
| 1236 | else |
| 1237 | #endif |
| 1238 | copy_text_attr(off + col, buf, len, HL_ATTR(HLF_FL)); |
| 1239 | col += len; |
| 1240 | } |
| 1241 | } |
| 1242 | |
| 1243 | // 4. Compose the folded-line string with 'foldtext', if set. |
| 1244 | text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
| 1245 | |
| 1246 | txtcol = col; // remember where text starts |
| 1247 | |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 1248 | // 5. move the text to current_ScreenLine. Fill up with "fold" from |
| 1249 | // 'fillchars'. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1250 | // Right-left text is put in columns 0 - number-col, normal text is put |
| 1251 | // in columns number-col - window-width. |
| 1252 | col = text_to_screenline(wp, text, col); |
| 1253 | |
| 1254 | // Fill the rest of the line with the fold filler |
| 1255 | #ifdef FEAT_RIGHTLEFT |
| 1256 | if (wp->w_p_rl) |
| 1257 | col -= txtcol; |
| 1258 | #endif |
| 1259 | while (col < wp->w_width |
| 1260 | #ifdef FEAT_RIGHTLEFT |
| 1261 | - (wp->w_p_rl ? txtcol : 0) |
| 1262 | #endif |
| 1263 | ) |
| 1264 | { |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 1265 | int c = wp->w_fill_chars.fold; |
| 1266 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1267 | if (enc_utf8) |
| 1268 | { |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 1269 | if (c >= 0x80) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1270 | { |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 1271 | ScreenLinesUC[off + col] = c; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1272 | ScreenLinesC[0][off + col] = 0; |
| 1273 | ScreenLines[off + col] = 0x80; // avoid storing zero |
| 1274 | } |
| 1275 | else |
| 1276 | { |
| 1277 | ScreenLinesUC[off + col] = 0; |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 1278 | ScreenLines[off + col] = c; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1279 | } |
| 1280 | col++; |
| 1281 | } |
| 1282 | else |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 1283 | ScreenLines[off + col++] = c; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | if (text != buf) |
| 1287 | vim_free(text); |
| 1288 | |
| 1289 | // 6. set highlighting for the Visual area an other text. |
| 1290 | // If all folded lines are in the Visual area, highlight the line. |
| 1291 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 1292 | { |
| 1293 | if (LTOREQ_POS(curwin->w_cursor, VIsual)) |
| 1294 | { |
| 1295 | // Visual is after curwin->w_cursor |
| 1296 | top = &curwin->w_cursor; |
| 1297 | bot = &VIsual; |
| 1298 | } |
| 1299 | else |
| 1300 | { |
| 1301 | // Visual is before curwin->w_cursor |
| 1302 | top = &VIsual; |
| 1303 | bot = &curwin->w_cursor; |
| 1304 | } |
| 1305 | if (lnum >= top->lnum |
| 1306 | && lnume <= bot->lnum |
| 1307 | && (VIsual_mode != 'v' |
| 1308 | || ((lnum > top->lnum |
| 1309 | || (lnum == top->lnum |
| 1310 | && top->col == 0)) |
| 1311 | && (lnume < bot->lnum |
| 1312 | || (lnume == bot->lnum |
| 1313 | && (bot->col - (*p_sel == 'e')) |
zeertzjq | 94b7c32 | 2024-03-12 21:50:32 +0100 | [diff] [blame] | 1314 | >= ml_get_buf_len(wp->w_buffer, lnume)))))) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1315 | { |
| 1316 | if (VIsual_mode == Ctrl_V) |
| 1317 | { |
| 1318 | // Visual block mode: highlight the chars part of the block |
| 1319 | if (wp->w_old_cursor_fcol + txtcol < (colnr_T)wp->w_width) |
| 1320 | { |
| 1321 | if (wp->w_old_cursor_lcol != MAXCOL |
| 1322 | && wp->w_old_cursor_lcol + txtcol |
| 1323 | < (colnr_T)wp->w_width) |
| 1324 | len = wp->w_old_cursor_lcol; |
| 1325 | else |
| 1326 | len = wp->w_width - txtcol; |
| 1327 | RL_MEMSET(wp->w_old_cursor_fcol + txtcol, HL_ATTR(HLF_V), |
| 1328 | len - (int)wp->w_old_cursor_fcol); |
| 1329 | } |
| 1330 | } |
| 1331 | else |
| 1332 | { |
| 1333 | // Set all attributes of the text |
| 1334 | RL_MEMSET(txtcol, HL_ATTR(HLF_V), wp->w_width - txtcol); |
| 1335 | } |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | #ifdef FEAT_SYN_HL |
| 1340 | // Show colorcolumn in the fold line, but let cursorcolumn override it. |
| 1341 | if (wp->w_p_cc_cols) |
| 1342 | { |
| 1343 | int i = 0; |
| 1344 | int j = wp->w_p_cc_cols[i]; |
| 1345 | int old_txtcol = txtcol; |
| 1346 | |
| 1347 | while (j > -1) |
| 1348 | { |
| 1349 | txtcol += j; |
| 1350 | if (wp->w_p_wrap) |
| 1351 | txtcol -= wp->w_skipcol; |
| 1352 | else |
| 1353 | txtcol -= wp->w_leftcol; |
| 1354 | if (txtcol >= 0 && txtcol < wp->w_width) |
| 1355 | ScreenAttrs[off + txtcol] = hl_combine_attr( |
| 1356 | ScreenAttrs[off + txtcol], HL_ATTR(HLF_MC)); |
| 1357 | txtcol = old_txtcol; |
| 1358 | j = wp->w_p_cc_cols[++i]; |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | // Show 'cursorcolumn' in the fold line. |
| 1363 | if (wp->w_p_cuc) |
| 1364 | { |
| 1365 | txtcol += wp->w_virtcol; |
| 1366 | if (wp->w_p_wrap) |
| 1367 | txtcol -= wp->w_skipcol; |
| 1368 | else |
| 1369 | txtcol -= wp->w_leftcol; |
| 1370 | if (txtcol >= 0 && txtcol < wp->w_width) |
| 1371 | ScreenAttrs[off + txtcol] = hl_combine_attr( |
| 1372 | ScreenAttrs[off + txtcol], HL_ATTR(HLF_CUC)); |
| 1373 | } |
| 1374 | #endif |
| 1375 | |
Hirohito Higashi | 3b9b95d | 2025-06-01 20:22:55 +0200 | [diff] [blame] | 1376 | screen_line(wp, row + W_WINROW(wp), wp->w_wincol, wp->w_width, wp->w_width, |
| 1377 | -1, 0); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1378 | |
| 1379 | // Update w_cline_height and w_cline_folded if the cursor line was |
| 1380 | // updated (saves a call to plines() later). |
| 1381 | if (wp == curwin |
| 1382 | && lnum <= curwin->w_cursor.lnum |
| 1383 | && lnume >= curwin->w_cursor.lnum) |
| 1384 | { |
| 1385 | curwin->w_cline_row = row; |
| 1386 | curwin->w_cline_height = 1; |
| 1387 | curwin->w_cline_folded = TRUE; |
| 1388 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 1389 | } |
Bram Moolenaar | 00aaa51 | 2021-07-03 18:04:11 +0200 | [diff] [blame] | 1390 | |
| 1391 | # ifdef FEAT_CONCEAL |
| 1392 | // When the line was not folded w_wrow may have been set, recompute it. |
Bram Moolenaar | 5cb0962 | 2021-07-05 22:03:04 +0200 | [diff] [blame] | 1393 | if (wp == curwin |
| 1394 | && wp->w_cursor.lnum >= lnum |
| 1395 | && wp->w_cursor.lnum <= lnume |
| 1396 | && conceal_cursor_line(wp)) |
Bram Moolenaar | 00aaa51 | 2021-07-03 18:04:11 +0200 | [diff] [blame] | 1397 | curs_columns(TRUE); |
| 1398 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1399 | } |
| 1400 | #endif |
| 1401 | |
| 1402 | /* |
| 1403 | * Update a single window. |
| 1404 | * |
| 1405 | * This may cause the windows below it also to be redrawn (when clearing the |
| 1406 | * screen or scrolling lines). |
| 1407 | * |
| 1408 | * How the window is redrawn depends on wp->w_redr_type. Each type also |
| 1409 | * implies the one below it. |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 1410 | * UPD_NOT_VALID redraw the whole window |
| 1411 | * UPD_SOME_VALID redraw the whole window but do scroll when possible |
| 1412 | * UPD_REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like |
| 1413 | * UPD_VALID |
| 1414 | * UPD_INVERTED redraw the changed part of the Visual area |
| 1415 | * UPD_INVERTED_ALL redraw the whole Visual area |
| 1416 | * UPD_VALID 1. scroll up/down to adjust for a changed w_topline |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1417 | * 2. update lines at the top when scrolled down |
| 1418 | * 3. redraw changed text: |
| 1419 | * - if wp->w_buffer->b_mod_set set, update lines between |
| 1420 | * b_mod_top and b_mod_bot. |
| 1421 | * - if wp->w_redraw_top non-zero, redraw lines between |
zeertzjq | f2d90a3 | 2024-02-12 20:28:01 +0100 | [diff] [blame] | 1422 | * wp->w_redraw_top and wp->w_redraw_bot. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1423 | * - continue redrawing when syntax status is invalid. |
| 1424 | * 4. if scrolled up, update lines at the bottom. |
| 1425 | * This results in three areas that may need updating: |
| 1426 | * top: from first row to top_end (when scrolled down) |
| 1427 | * mid: from mid_start to mid_end (update inversion or changed text) |
| 1428 | * bot: from bot_start to last row (when scrolled up) |
| 1429 | */ |
| 1430 | static void |
| 1431 | win_update(win_T *wp) |
| 1432 | { |
| 1433 | buf_T *buf = wp->w_buffer; |
| 1434 | int type; |
| 1435 | int top_end = 0; // Below last row of the top area that needs |
| 1436 | // updating. 0 when no top area updating. |
| 1437 | int mid_start = 999;// first row of the mid area that needs |
| 1438 | // updating. 999 when no mid area updating. |
| 1439 | int mid_end = 0; // Below last row of the mid area that needs |
| 1440 | // updating. 0 when no mid area updating. |
| 1441 | int bot_start = 999;// first row of the bot area that needs |
| 1442 | // updating. 999 when no bot area updating |
| 1443 | int scrolled_down = FALSE; // TRUE when scrolled down when |
| 1444 | // w_topline got smaller a bit |
| 1445 | #ifdef FEAT_SEARCH_EXTRA |
| 1446 | int top_to_mod = FALSE; // redraw above mod_top |
| 1447 | #endif |
| 1448 | |
| 1449 | int row; // current window row to display |
| 1450 | linenr_T lnum; // current buffer lnum to display |
| 1451 | int idx; // current index in w_lines[] |
| 1452 | int srow; // starting row of the current line |
| 1453 | |
| 1454 | int eof = FALSE; // if TRUE, we hit the end of the file |
| 1455 | int didline = FALSE; // if TRUE, we finished the last line |
| 1456 | int i; |
| 1457 | long j; |
| 1458 | static int recursive = FALSE; // being called recursively |
Bram Moolenaar | cbee635 | 2019-11-12 20:49:15 +0100 | [diff] [blame] | 1459 | linenr_T old_botline = wp->w_botline; |
| 1460 | #ifdef FEAT_CONCEAL |
| 1461 | int old_wrow = wp->w_wrow; |
| 1462 | int old_wcol = wp->w_wcol; |
| 1463 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1464 | #ifdef FEAT_FOLDING |
| 1465 | long fold_count; |
| 1466 | #endif |
| 1467 | #ifdef FEAT_SYN_HL |
| 1468 | // remember what happened to the previous line, to know if |
| 1469 | // check_visual_highlight() can be used |
Bram Moolenaar | e7a74d5 | 2022-03-19 11:10:15 +0000 | [diff] [blame] | 1470 | # define DID_NONE 1 // didn't update a line |
| 1471 | # define DID_LINE 2 // updated a normal line |
| 1472 | # define DID_FOLD 3 // updated a folded line |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1473 | int did_update = DID_NONE; |
| 1474 | linenr_T syntax_last_parsed = 0; // last parsed text line |
| 1475 | #endif |
| 1476 | linenr_T mod_top = 0; |
| 1477 | linenr_T mod_bot = 0; |
| 1478 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1479 | int save_got_int; |
| 1480 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1481 | |
Bram Moolenaar | e52e0c8 | 2020-02-28 22:20:10 +0100 | [diff] [blame] | 1482 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 1483 | // This needs to be done only for the first window when update_screen() is |
| 1484 | // called. |
| 1485 | if (!did_update_one_window) |
| 1486 | { |
| 1487 | did_update_one_window = TRUE; |
| 1488 | # ifdef FEAT_SEARCH_EXTRA |
| 1489 | start_search_hl(); |
| 1490 | # endif |
| 1491 | # ifdef FEAT_CLIPBOARD |
| 1492 | // When Visual area changed, may have to update selection. |
| 1493 | if (clip_star.available && clip_isautosel_star()) |
| 1494 | clip_update_selection(&clip_star); |
| 1495 | if (clip_plus.available && clip_isautosel_plus()) |
| 1496 | clip_update_selection(&clip_plus); |
| 1497 | # endif |
| 1498 | } |
| 1499 | #endif |
| 1500 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1501 | type = wp->w_redr_type; |
| 1502 | |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 1503 | if (type == UPD_NOT_VALID) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1504 | { |
| 1505 | wp->w_redr_status = TRUE; |
| 1506 | wp->w_lines_valid = 0; |
| 1507 | } |
| 1508 | |
Bram Moolenaar | ae0f151 | 2021-03-30 22:12:12 +0200 | [diff] [blame] | 1509 | // Window frame is zero-height: nothing to draw. |
| 1510 | if (wp->w_height + WINBAR_HEIGHT(wp) == 0 |
| 1511 | || (wp->w_frame->fr_height == wp->w_status_height |
| 1512 | #if defined(FEAT_PROP_POPUP) |
| 1513 | && !popup_is_popup(wp) |
| 1514 | #endif |
| 1515 | )) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1516 | { |
| 1517 | wp->w_redr_type = 0; |
| 1518 | return; |
| 1519 | } |
| 1520 | |
| 1521 | // Window is zero-width: Only need to draw the separator. |
| 1522 | if (wp->w_width == 0) |
| 1523 | { |
| 1524 | // draw the vertical separator right of this window |
| 1525 | draw_vsep_win(wp, 0); |
| 1526 | wp->w_redr_type = 0; |
| 1527 | return; |
| 1528 | } |
| 1529 | |
| 1530 | #ifdef FEAT_TERMINAL |
| 1531 | // If this window contains a terminal, redraw works completely differently. |
| 1532 | if (term_do_update_window(wp)) |
| 1533 | { |
| 1534 | term_update_window(wp); |
| 1535 | # ifdef FEAT_MENU |
| 1536 | // Draw the window toolbar, if there is one. |
| 1537 | if (winbar_height(wp) > 0) |
| 1538 | redraw_win_toolbar(wp); |
| 1539 | # endif |
| 1540 | wp->w_redr_type = 0; |
| 1541 | return; |
| 1542 | } |
| 1543 | #endif |
| 1544 | |
| 1545 | #ifdef FEAT_SEARCH_EXTRA |
| 1546 | init_search_hl(wp, &screen_search_hl); |
| 1547 | #endif |
| 1548 | |
Bram Moolenaar | b6aab8f | 2022-10-03 20:01:16 +0100 | [diff] [blame] | 1549 | // Make sure skipcol is valid, it depends on various options and the window |
| 1550 | // width. |
Sean Dewar | 02fcae0 | 2024-02-21 19:40:44 +0100 | [diff] [blame] | 1551 | if (wp->w_skipcol > 0 && wp->w_width > win_col_off(wp)) |
Bram Moolenaar | b6aab8f | 2022-10-03 20:01:16 +0100 | [diff] [blame] | 1552 | { |
| 1553 | int w = 0; |
| 1554 | int width1 = wp->w_width - win_col_off(wp); |
| 1555 | int width2 = width1 + win_col_off2(wp); |
| 1556 | int add = width1; |
| 1557 | |
| 1558 | while (w < wp->w_skipcol) |
| 1559 | { |
| 1560 | if (w > 0) |
| 1561 | add = width2; |
| 1562 | w += add; |
| 1563 | } |
| 1564 | if (w != wp->w_skipcol) |
| 1565 | // always round down, the higher value may not be valid |
| 1566 | wp->w_skipcol = w - add; |
| 1567 | } |
| 1568 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1569 | #ifdef FEAT_LINEBREAK |
| 1570 | // Force redraw when width of 'number' or 'relativenumber' column |
| 1571 | // changes. |
| 1572 | i = (wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) : 0; |
| 1573 | if (wp->w_nrwidth != i) |
| 1574 | { |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 1575 | type = UPD_NOT_VALID; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1576 | wp->w_nrwidth = i; |
| 1577 | } |
| 1578 | else |
| 1579 | #endif |
| 1580 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1581 | { |
| 1582 | // Set mod_top to the first line that needs displaying because of |
| 1583 | // changes. Set mod_bot to the first line after the changes. |
| 1584 | mod_top = wp->w_redraw_top; |
| 1585 | if (wp->w_redraw_bot != 0) |
| 1586 | mod_bot = wp->w_redraw_bot + 1; |
| 1587 | else |
| 1588 | mod_bot = 0; |
| 1589 | if (buf->b_mod_set) |
| 1590 | { |
| 1591 | if (mod_top == 0 || mod_top > buf->b_mod_top) |
| 1592 | { |
| 1593 | mod_top = buf->b_mod_top; |
| 1594 | #ifdef FEAT_SYN_HL |
| 1595 | // Need to redraw lines above the change that may be included |
| 1596 | // in a pattern match. |
| 1597 | if (syntax_present(wp)) |
| 1598 | { |
| 1599 | mod_top -= buf->b_s.b_syn_sync_linebreaks; |
| 1600 | if (mod_top < 1) |
| 1601 | mod_top = 1; |
| 1602 | } |
| 1603 | #endif |
| 1604 | } |
| 1605 | if (mod_bot == 0 || mod_bot < buf->b_mod_bot) |
| 1606 | mod_bot = buf->b_mod_bot; |
| 1607 | |
| 1608 | #ifdef FEAT_SEARCH_EXTRA |
| 1609 | // When 'hlsearch' is on and using a multi-line search pattern, a |
| 1610 | // change in one line may make the Search highlighting in a |
| 1611 | // previous line invalid. Simple solution: redraw all visible |
| 1612 | // lines above the change. |
| 1613 | // Same for a match pattern. |
| 1614 | if (screen_search_hl.rm.regprog != NULL |
| 1615 | && re_multiline(screen_search_hl.rm.regprog)) |
| 1616 | top_to_mod = TRUE; |
| 1617 | else |
| 1618 | { |
| 1619 | matchitem_T *cur = wp->w_match_head; |
| 1620 | |
| 1621 | while (cur != NULL) |
| 1622 | { |
Bram Moolenaar | 50faf02 | 2022-09-29 12:50:17 +0100 | [diff] [blame] | 1623 | if (cur->mit_match.regprog != NULL |
| 1624 | && re_multiline(cur->mit_match.regprog)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1625 | { |
| 1626 | top_to_mod = TRUE; |
| 1627 | break; |
| 1628 | } |
Bram Moolenaar | 50faf02 | 2022-09-29 12:50:17 +0100 | [diff] [blame] | 1629 | cur = cur->mit_next; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1630 | } |
| 1631 | } |
| 1632 | #endif |
| 1633 | } |
Bram Moolenaar | 368137a | 2022-05-31 13:43:12 +0100 | [diff] [blame] | 1634 | |
| 1635 | #ifdef FEAT_SEARCH_EXTRA |
| 1636 | if (search_hl_has_cursor_lnum > 0) |
| 1637 | { |
| 1638 | // CurSearch was used last time, need to redraw the line with it to |
| 1639 | // avoid having two matches highlighted with CurSearch. |
| 1640 | if (mod_top == 0 || mod_top > search_hl_has_cursor_lnum) |
| 1641 | mod_top = search_hl_has_cursor_lnum; |
| 1642 | if (mod_bot == 0 || mod_bot < search_hl_has_cursor_lnum + 1) |
| 1643 | mod_bot = search_hl_has_cursor_lnum + 1; |
| 1644 | } |
| 1645 | #endif |
| 1646 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1647 | #ifdef FEAT_FOLDING |
| 1648 | if (mod_top != 0 && hasAnyFolding(wp)) |
| 1649 | { |
| 1650 | linenr_T lnumt, lnumb; |
| 1651 | |
| 1652 | // A change in a line can cause lines above it to become folded or |
| 1653 | // unfolded. Find the top most buffer line that may be affected. |
| 1654 | // If the line was previously folded and displayed, get the first |
| 1655 | // line of that fold. If the line is folded now, get the first |
| 1656 | // folded line. Use the minimum of these two. |
| 1657 | |
| 1658 | // Find last valid w_lines[] entry above mod_top. Set lnumt to |
| 1659 | // the line below it. If there is no valid entry, use w_topline. |
| 1660 | // Find the first valid w_lines[] entry below mod_bot. Set lnumb |
| 1661 | // to this line. If there is no valid entry, use MAXLNUM. |
| 1662 | lnumt = wp->w_topline; |
| 1663 | lnumb = MAXLNUM; |
| 1664 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1665 | if (wp->w_lines[i].wl_valid) |
| 1666 | { |
| 1667 | if (wp->w_lines[i].wl_lastlnum < mod_top) |
| 1668 | lnumt = wp->w_lines[i].wl_lastlnum + 1; |
| 1669 | if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) |
| 1670 | { |
| 1671 | lnumb = wp->w_lines[i].wl_lnum; |
| 1672 | // When there is a fold column it might need updating |
| 1673 | // in the next line ("J" just above an open fold). |
| 1674 | if (compute_foldcolumn(wp, 0) > 0) |
| 1675 | ++lnumb; |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); |
| 1680 | if (mod_top > lnumt) |
| 1681 | mod_top = lnumt; |
| 1682 | |
| 1683 | // Now do the same for the bottom line (one above mod_bot). |
| 1684 | --mod_bot; |
| 1685 | (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); |
| 1686 | ++mod_bot; |
| 1687 | if (mod_bot < lnumb) |
| 1688 | mod_bot = lnumb; |
| 1689 | } |
| 1690 | #endif |
| 1691 | |
| 1692 | // When a change starts above w_topline and the end is below |
| 1693 | // w_topline, start redrawing at w_topline. |
| 1694 | // If the end of the change is above w_topline: do like no change was |
| 1695 | // made, but redraw the first line to find changes in syntax. |
| 1696 | if (mod_top != 0 && mod_top < wp->w_topline) |
| 1697 | { |
| 1698 | if (mod_bot > wp->w_topline) |
| 1699 | mod_top = wp->w_topline; |
| 1700 | #ifdef FEAT_SYN_HL |
| 1701 | else if (syntax_present(wp)) |
| 1702 | top_end = 1; |
| 1703 | #endif |
| 1704 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1705 | } |
| 1706 | wp->w_redraw_top = 0; // reset for next time |
| 1707 | wp->w_redraw_bot = 0; |
Bram Moolenaar | 368137a | 2022-05-31 13:43:12 +0100 | [diff] [blame] | 1708 | #ifdef FEAT_SEARCH_EXTRA |
| 1709 | search_hl_has_cursor_lnum = 0; |
| 1710 | #endif |
| 1711 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1712 | |
| 1713 | // When only displaying the lines at the top, set top_end. Used when |
| 1714 | // window has scrolled down for msg_scrolled. |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 1715 | if (type == UPD_REDRAW_TOP) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1716 | { |
| 1717 | j = 0; |
| 1718 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1719 | { |
| 1720 | j += wp->w_lines[i].wl_size; |
| 1721 | if (j >= wp->w_upd_rows) |
| 1722 | { |
| 1723 | top_end = j; |
| 1724 | break; |
| 1725 | } |
| 1726 | } |
| 1727 | if (top_end == 0) |
| 1728 | // not found (cannot happen?): redraw everything |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 1729 | type = UPD_NOT_VALID; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1730 | else |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 1731 | // top area defined, the rest is UPD_VALID |
| 1732 | type = UPD_VALID; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | // Trick: we want to avoid clearing the screen twice. screenclear() will |
| 1736 | // set "screen_cleared" to TRUE. The special value MAYBE (which is still |
| 1737 | // non-zero and thus not FALSE) will indicate that screenclear() was not |
| 1738 | // called. |
| 1739 | if (screen_cleared) |
| 1740 | screen_cleared = MAYBE; |
| 1741 | |
| 1742 | // If there are no changes on the screen that require a complete redraw, |
| 1743 | // handle three cases: |
| 1744 | // 1: we are off the top of the screen by a few lines: scroll down |
| 1745 | // 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up |
| 1746 | // 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in |
| 1747 | // w_lines[] that needs updating. |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 1748 | if ((type == UPD_VALID || type == UPD_SOME_VALID |
| 1749 | || type == UPD_INVERTED || type == UPD_INVERTED_ALL) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1750 | #ifdef FEAT_DIFF |
| 1751 | && !wp->w_botfill && !wp->w_old_botfill |
| 1752 | #endif |
| 1753 | ) |
| 1754 | { |
Bram Moolenaar | f8992d4 | 2020-08-01 19:14:13 +0200 | [diff] [blame] | 1755 | if (mod_top != 0 |
| 1756 | && wp->w_topline == mod_top |
| 1757 | && (!wp->w_lines[0].wl_valid |
Bram Moolenaar | abb6fbd | 2022-03-25 15:42:27 +0000 | [diff] [blame] | 1758 | || wp->w_topline == wp->w_lines[0].wl_lnum)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1759 | { |
Bram Moolenaar | f8992d4 | 2020-08-01 19:14:13 +0200 | [diff] [blame] | 1760 | // w_topline is the first changed line and window is not scrolled, |
| 1761 | // the scrolling from changed lines will be done further down. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1762 | } |
| 1763 | else if (wp->w_lines[0].wl_valid |
| 1764 | && (wp->w_topline < wp->w_lines[0].wl_lnum |
| 1765 | #ifdef FEAT_DIFF |
| 1766 | || (wp->w_topline == wp->w_lines[0].wl_lnum |
| 1767 | && wp->w_topfill > wp->w_old_topfill) |
| 1768 | #endif |
| 1769 | )) |
| 1770 | { |
| 1771 | // New topline is above old topline: May scroll down. |
| 1772 | #ifdef FEAT_FOLDING |
| 1773 | if (hasAnyFolding(wp)) |
| 1774 | { |
| 1775 | linenr_T ln; |
| 1776 | |
| 1777 | // count the number of lines we are off, counting a sequence |
| 1778 | // of folded lines as one |
| 1779 | j = 0; |
| 1780 | for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) |
| 1781 | { |
| 1782 | ++j; |
| 1783 | if (j >= wp->w_height - 2) |
| 1784 | break; |
| 1785 | (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); |
| 1786 | } |
| 1787 | } |
| 1788 | else |
| 1789 | #endif |
| 1790 | j = wp->w_lines[0].wl_lnum - wp->w_topline; |
| 1791 | if (j < wp->w_height - 2) // not too far off |
| 1792 | { |
zeertzjq | bfe377b | 2023-08-17 22:58:53 +0200 | [diff] [blame] | 1793 | i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1, |
Luuk van Baal | 32d701f | 2024-04-28 16:24:02 +0200 | [diff] [blame] | 1794 | wp->w_height); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1795 | #ifdef FEAT_DIFF |
| 1796 | // insert extra lines for previously invisible filler lines |
| 1797 | if (wp->w_lines[0].wl_lnum != wp->w_topline) |
| 1798 | i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) |
| 1799 | - wp->w_old_topfill; |
| 1800 | #endif |
| 1801 | if (i < wp->w_height - 2) // less than a screen off |
| 1802 | { |
| 1803 | // Try to insert the correct number of lines. |
| 1804 | // If not the last window, delete the lines at the bottom. |
| 1805 | // win_ins_lines may fail when the terminal can't do it. |
| 1806 | if (i > 0) |
| 1807 | check_for_delay(FALSE); |
| 1808 | if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) |
| 1809 | { |
| 1810 | if (wp->w_lines_valid != 0) |
| 1811 | { |
| 1812 | // Need to update rows that are new, stop at the |
| 1813 | // first one that scrolled down. |
| 1814 | top_end = i; |
| 1815 | scrolled_down = TRUE; |
| 1816 | |
| 1817 | // Move the entries that were scrolled, disable |
| 1818 | // the entries for the lines to be redrawn. |
| 1819 | if ((wp->w_lines_valid += j) > wp->w_height) |
| 1820 | wp->w_lines_valid = wp->w_height; |
Bram Moolenaar | a2a8973 | 2022-08-31 14:46:18 +0100 | [diff] [blame] | 1821 | for (idx = wp->w_lines_valid; idx - j >= 0; idx--) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1822 | wp->w_lines[idx] = wp->w_lines[idx - j]; |
| 1823 | while (idx >= 0) |
| 1824 | wp->w_lines[idx--].wl_valid = FALSE; |
| 1825 | } |
| 1826 | } |
| 1827 | else |
| 1828 | mid_start = 0; // redraw all lines |
| 1829 | } |
| 1830 | else |
| 1831 | mid_start = 0; // redraw all lines |
| 1832 | } |
| 1833 | else |
| 1834 | mid_start = 0; // redraw all lines |
| 1835 | } |
| 1836 | else |
| 1837 | { |
| 1838 | // New topline is at or below old topline: May scroll up. |
| 1839 | // When topline didn't change, find first entry in w_lines[] that |
| 1840 | // needs updating. |
| 1841 | |
Bram Moolenaar | f6ebc82 | 2022-01-16 13:58:33 +0000 | [diff] [blame] | 1842 | // Try to find wp->w_topline in wp->w_lines[].wl_lnum. The check |
| 1843 | // for "Rows" is in case "wl_size" is incorrect somehow. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1844 | j = -1; |
| 1845 | row = 0; |
Bram Moolenaar | f6ebc82 | 2022-01-16 13:58:33 +0000 | [diff] [blame] | 1846 | for (i = 0; i < wp->w_lines_valid && i < Rows; i++) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1847 | { |
| 1848 | if (wp->w_lines[i].wl_valid |
| 1849 | && wp->w_lines[i].wl_lnum == wp->w_topline) |
| 1850 | { |
| 1851 | j = i; |
| 1852 | break; |
| 1853 | } |
| 1854 | row += wp->w_lines[i].wl_size; |
| 1855 | } |
| 1856 | if (j == -1) |
| 1857 | { |
| 1858 | // if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all |
| 1859 | // lines |
| 1860 | mid_start = 0; |
| 1861 | } |
| 1862 | else |
| 1863 | { |
| 1864 | // Try to delete the correct number of lines. |
| 1865 | // wp->w_topline is at wp->w_lines[i].wl_lnum. |
| 1866 | #ifdef FEAT_DIFF |
| 1867 | // If the topline didn't change, delete old filler lines, |
| 1868 | // otherwise delete filler lines of the new topline... |
| 1869 | if (wp->w_lines[0].wl_lnum == wp->w_topline) |
| 1870 | row += wp->w_old_topfill; |
| 1871 | else |
| 1872 | row += diff_check_fill(wp, wp->w_topline); |
| 1873 | // ... but don't delete new filler lines. |
| 1874 | row -= wp->w_topfill; |
| 1875 | #endif |
Bram Moolenaar | f6ebc82 | 2022-01-16 13:58:33 +0000 | [diff] [blame] | 1876 | if (row > Rows) // just in case |
| 1877 | row = Rows; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1878 | if (row > 0) |
| 1879 | { |
| 1880 | check_for_delay(FALSE); |
| 1881 | if (win_del_lines(wp, 0, row, FALSE, wp == firstwin, 0) |
| 1882 | == OK) |
| 1883 | bot_start = wp->w_height - row; |
| 1884 | else |
| 1885 | mid_start = 0; // redraw all lines |
| 1886 | } |
| 1887 | if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) |
| 1888 | { |
| 1889 | // Skip the lines (below the deleted lines) that are still |
| 1890 | // valid and don't need redrawing. Copy their info |
| 1891 | // upwards, to compensate for the deleted lines. Set |
| 1892 | // bot_start to the first row that needs redrawing. |
| 1893 | bot_start = 0; |
| 1894 | idx = 0; |
| 1895 | for (;;) |
| 1896 | { |
| 1897 | wp->w_lines[idx] = wp->w_lines[j]; |
| 1898 | // stop at line that didn't fit, unless it is still |
| 1899 | // valid (no lines deleted) |
| 1900 | if (row > 0 && bot_start + row |
| 1901 | + (int)wp->w_lines[j].wl_size > wp->w_height) |
| 1902 | { |
| 1903 | wp->w_lines_valid = idx + 1; |
| 1904 | break; |
| 1905 | } |
| 1906 | bot_start += wp->w_lines[idx++].wl_size; |
| 1907 | |
| 1908 | // stop at the last valid entry in w_lines[].wl_size |
| 1909 | if (++j >= wp->w_lines_valid) |
| 1910 | { |
| 1911 | wp->w_lines_valid = idx; |
| 1912 | break; |
| 1913 | } |
| 1914 | } |
| 1915 | #ifdef FEAT_DIFF |
| 1916 | // Correct the first entry for filler lines at the top |
| 1917 | // when it won't get updated below. |
| 1918 | if (wp->w_p_diff && bot_start > 0) |
zeertzjq | 47f8584 | 2024-10-01 19:35:47 +0200 | [diff] [blame] | 1919 | { |
| 1920 | int n = plines_win_nofill(wp, wp->w_topline, FALSE) |
| 1921 | + wp->w_topfill - adjust_plines_for_skipcol(wp); |
| 1922 | if (n > wp->w_height) |
| 1923 | n = wp->w_height; |
| 1924 | wp->w_lines[0].wl_size = n; |
| 1925 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1926 | #endif |
| 1927 | } |
| 1928 | } |
| 1929 | } |
| 1930 | |
Bram Moolenaar | 13608d8 | 2022-08-29 15:06:50 +0100 | [diff] [blame] | 1931 | // When starting redraw in the first line, redraw all lines. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1932 | if (mid_start == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1933 | mid_end = wp->w_height; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1934 | |
| 1935 | // When win_del_lines() or win_ins_lines() caused the screen to be |
| 1936 | // cleared (only happens for the first window) or when screenclear() |
| 1937 | // was called directly above, "must_redraw" will have been set to |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 1938 | // UPD_NOT_VALID, need to reset it here to avoid redrawing twice. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1939 | if (screen_cleared == TRUE) |
| 1940 | must_redraw = 0; |
| 1941 | } |
| 1942 | else |
| 1943 | { |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 1944 | // Not UPD_VALID or UPD_INVERTED: redraw all lines. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1945 | mid_start = 0; |
| 1946 | mid_end = wp->w_height; |
| 1947 | } |
| 1948 | |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 1949 | if (type == UPD_SOME_VALID) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1950 | { |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 1951 | // UPD_SOME_VALID: redraw all lines. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1952 | mid_start = 0; |
| 1953 | mid_end = wp->w_height; |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 1954 | type = UPD_NOT_VALID; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | // check if we are updating or removing the inverted part |
| 1958 | if ((VIsual_active && buf == curwin->w_buffer) |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 1959 | || (wp->w_old_cursor_lnum != 0 && type != UPD_NOT_VALID)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1960 | { |
| 1961 | linenr_T from, to; |
| 1962 | |
| 1963 | if (VIsual_active) |
| 1964 | { |
Bram Moolenaar | fe15499 | 2022-03-22 20:42:12 +0000 | [diff] [blame] | 1965 | if (VIsual_mode != wp->w_old_visual_mode |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 1966 | || type == UPD_INVERTED_ALL) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1967 | { |
| 1968 | // If the type of Visual selection changed, redraw the whole |
| 1969 | // selection. Also when the ownership of the X selection is |
| 1970 | // gained or lost. |
| 1971 | if (curwin->w_cursor.lnum < VIsual.lnum) |
| 1972 | { |
| 1973 | from = curwin->w_cursor.lnum; |
| 1974 | to = VIsual.lnum; |
| 1975 | } |
| 1976 | else |
| 1977 | { |
| 1978 | from = VIsual.lnum; |
| 1979 | to = curwin->w_cursor.lnum; |
| 1980 | } |
| 1981 | // redraw more when the cursor moved as well |
| 1982 | if (wp->w_old_cursor_lnum < from) |
| 1983 | from = wp->w_old_cursor_lnum; |
| 1984 | if (wp->w_old_cursor_lnum > to) |
| 1985 | to = wp->w_old_cursor_lnum; |
| 1986 | if (wp->w_old_visual_lnum < from) |
| 1987 | from = wp->w_old_visual_lnum; |
| 1988 | if (wp->w_old_visual_lnum > to) |
| 1989 | to = wp->w_old_visual_lnum; |
| 1990 | } |
| 1991 | else |
| 1992 | { |
| 1993 | // Find the line numbers that need to be updated: The lines |
| 1994 | // between the old cursor position and the current cursor |
| 1995 | // position. Also check if the Visual position changed. |
| 1996 | if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) |
| 1997 | { |
| 1998 | from = curwin->w_cursor.lnum; |
| 1999 | to = wp->w_old_cursor_lnum; |
| 2000 | } |
| 2001 | else |
| 2002 | { |
| 2003 | from = wp->w_old_cursor_lnum; |
| 2004 | to = curwin->w_cursor.lnum; |
| 2005 | if (from == 0) // Visual mode just started |
| 2006 | from = to; |
| 2007 | } |
| 2008 | |
| 2009 | if (VIsual.lnum != wp->w_old_visual_lnum |
| 2010 | || VIsual.col != wp->w_old_visual_col) |
| 2011 | { |
| 2012 | if (wp->w_old_visual_lnum < from |
| 2013 | && wp->w_old_visual_lnum != 0) |
| 2014 | from = wp->w_old_visual_lnum; |
| 2015 | if (wp->w_old_visual_lnum > to) |
| 2016 | to = wp->w_old_visual_lnum; |
| 2017 | if (VIsual.lnum < from) |
| 2018 | from = VIsual.lnum; |
| 2019 | if (VIsual.lnum > to) |
| 2020 | to = VIsual.lnum; |
| 2021 | } |
| 2022 | } |
| 2023 | |
| 2024 | // If in block mode and changed column or curwin->w_curswant: |
| 2025 | // update all lines. |
| 2026 | // First compute the actual start and end column. |
| 2027 | if (VIsual_mode == Ctrl_V) |
| 2028 | { |
| 2029 | colnr_T fromc, toc; |
| 2030 | #if defined(FEAT_LINEBREAK) |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 2031 | int save_ve_flags = curwin->w_ve_flags; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2032 | |
| 2033 | if (curwin->w_p_lbr) |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 2034 | curwin->w_ve_flags = VE_ALL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2035 | #endif |
| 2036 | getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); |
Bram Moolenaar | b17ab86 | 2021-07-03 22:15:17 +0200 | [diff] [blame] | 2037 | ++toc; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2038 | #if defined(FEAT_LINEBREAK) |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 2039 | curwin->w_ve_flags = save_ve_flags; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2040 | #endif |
Bram Moolenaar | 9cee4a1 | 2021-07-03 15:08:37 +0200 | [diff] [blame] | 2041 | // Highlight to the end of the line, unless 'virtualedit' has |
| 2042 | // "block". |
Bram Moolenaar | b17ab86 | 2021-07-03 22:15:17 +0200 | [diff] [blame] | 2043 | if (curwin->w_curswant == MAXCOL) |
| 2044 | { |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 2045 | if (get_ve_flags() & VE_BLOCK) |
Bram Moolenaar | b17ab86 | 2021-07-03 22:15:17 +0200 | [diff] [blame] | 2046 | { |
| 2047 | pos_T pos; |
| 2048 | int cursor_above = |
| 2049 | curwin->w_cursor.lnum < VIsual.lnum; |
| 2050 | |
| 2051 | // Need to find the longest line. |
| 2052 | toc = 0; |
| 2053 | pos.coladd = 0; |
| 2054 | for (pos.lnum = curwin->w_cursor.lnum; cursor_above |
| 2055 | ? pos.lnum <= VIsual.lnum |
| 2056 | : pos.lnum >= VIsual.lnum; |
| 2057 | pos.lnum += cursor_above ? 1 : -1) |
| 2058 | { |
| 2059 | colnr_T t; |
| 2060 | |
John Marriott | a21240b | 2025-01-08 20:10:59 +0100 | [diff] [blame] | 2061 | pos.col = (int)ml_get_buf_len(wp->w_buffer, pos.lnum); |
Bram Moolenaar | b17ab86 | 2021-07-03 22:15:17 +0200 | [diff] [blame] | 2062 | getvvcol(wp, &pos, NULL, NULL, &t); |
| 2063 | if (toc < t) |
| 2064 | toc = t; |
| 2065 | } |
| 2066 | ++toc; |
| 2067 | } |
| 2068 | else |
| 2069 | toc = MAXCOL; |
| 2070 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2071 | |
| 2072 | if (fromc != wp->w_old_cursor_fcol |
| 2073 | || toc != wp->w_old_cursor_lcol) |
| 2074 | { |
| 2075 | if (from > VIsual.lnum) |
| 2076 | from = VIsual.lnum; |
| 2077 | if (to < VIsual.lnum) |
| 2078 | to = VIsual.lnum; |
| 2079 | } |
| 2080 | wp->w_old_cursor_fcol = fromc; |
| 2081 | wp->w_old_cursor_lcol = toc; |
| 2082 | } |
| 2083 | } |
| 2084 | else |
| 2085 | { |
| 2086 | // Use the line numbers of the old Visual area. |
| 2087 | if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) |
| 2088 | { |
| 2089 | from = wp->w_old_cursor_lnum; |
| 2090 | to = wp->w_old_visual_lnum; |
| 2091 | } |
| 2092 | else |
| 2093 | { |
| 2094 | from = wp->w_old_visual_lnum; |
| 2095 | to = wp->w_old_cursor_lnum; |
| 2096 | } |
| 2097 | } |
| 2098 | |
| 2099 | // There is no need to update lines above the top of the window. |
| 2100 | if (from < wp->w_topline) |
| 2101 | from = wp->w_topline; |
| 2102 | |
| 2103 | // If we know the value of w_botline, use it to restrict the update to |
| 2104 | // the lines that are visible in the window. |
| 2105 | if (wp->w_valid & VALID_BOTLINE) |
| 2106 | { |
| 2107 | if (from >= wp->w_botline) |
| 2108 | from = wp->w_botline - 1; |
| 2109 | if (to >= wp->w_botline) |
| 2110 | to = wp->w_botline - 1; |
| 2111 | } |
| 2112 | |
| 2113 | // Find the minimal part to be updated. |
| 2114 | // Watch out for scrolling that made entries in w_lines[] invalid. |
| 2115 | // E.g., CTRL-U makes the first half of w_lines[] invalid and sets |
| 2116 | // top_end; need to redraw from top_end to the "to" line. |
| 2117 | // A middle mouse click with a Visual selection may change the text |
| 2118 | // above the Visual area and reset wl_valid, do count these for |
| 2119 | // mid_end (in srow). |
| 2120 | if (mid_start > 0) |
| 2121 | { |
| 2122 | lnum = wp->w_topline; |
| 2123 | idx = 0; |
| 2124 | srow = 0; |
| 2125 | if (scrolled_down) |
| 2126 | mid_start = top_end; |
| 2127 | else |
| 2128 | mid_start = 0; |
| 2129 | while (lnum < from && idx < wp->w_lines_valid) // find start |
| 2130 | { |
| 2131 | if (wp->w_lines[idx].wl_valid) |
| 2132 | mid_start += wp->w_lines[idx].wl_size; |
| 2133 | else if (!scrolled_down) |
| 2134 | srow += wp->w_lines[idx].wl_size; |
| 2135 | ++idx; |
| 2136 | # ifdef FEAT_FOLDING |
| 2137 | if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) |
| 2138 | lnum = wp->w_lines[idx].wl_lnum; |
| 2139 | else |
| 2140 | # endif |
| 2141 | ++lnum; |
| 2142 | } |
| 2143 | srow += mid_start; |
| 2144 | mid_end = wp->w_height; |
| 2145 | for ( ; idx < wp->w_lines_valid; ++idx) // find end |
| 2146 | { |
| 2147 | if (wp->w_lines[idx].wl_valid |
| 2148 | && wp->w_lines[idx].wl_lnum >= to + 1) |
| 2149 | { |
| 2150 | // Only update until first row of this line |
| 2151 | mid_end = srow; |
| 2152 | break; |
| 2153 | } |
| 2154 | srow += wp->w_lines[idx].wl_size; |
| 2155 | } |
| 2156 | } |
| 2157 | } |
| 2158 | |
| 2159 | if (VIsual_active && buf == curwin->w_buffer) |
| 2160 | { |
| 2161 | wp->w_old_visual_mode = VIsual_mode; |
| 2162 | wp->w_old_cursor_lnum = curwin->w_cursor.lnum; |
| 2163 | wp->w_old_visual_lnum = VIsual.lnum; |
| 2164 | wp->w_old_visual_col = VIsual.col; |
| 2165 | wp->w_old_curswant = curwin->w_curswant; |
| 2166 | } |
| 2167 | else |
| 2168 | { |
| 2169 | wp->w_old_visual_mode = 0; |
| 2170 | wp->w_old_cursor_lnum = 0; |
| 2171 | wp->w_old_visual_lnum = 0; |
| 2172 | wp->w_old_visual_col = 0; |
| 2173 | } |
| 2174 | |
| 2175 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 2176 | // reset got_int, otherwise regexp won't work |
| 2177 | save_got_int = got_int; |
| 2178 | got_int = 0; |
| 2179 | #endif |
| 2180 | #ifdef SYN_TIME_LIMIT |
| 2181 | // Set the time limit to 'redrawtime'. |
Bram Moolenaar | 6f0cf62 | 2022-06-19 12:27:45 +0100 | [diff] [blame] | 2182 | redrawtime_limit_set = TRUE; |
Paul Ollis | 6574577 | 2022-06-05 16:55:54 +0100 | [diff] [blame] | 2183 | init_regexp_timeout(p_rdt); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2184 | #endif |
| 2185 | #ifdef FEAT_FOLDING |
| 2186 | win_foldinfo.fi_level = 0; |
| 2187 | #endif |
| 2188 | |
| 2189 | #ifdef FEAT_MENU |
| 2190 | // Draw the window toolbar, if there is one. |
| 2191 | // TODO: only when needed. |
| 2192 | if (winbar_height(wp) > 0) |
| 2193 | redraw_win_toolbar(wp); |
| 2194 | #endif |
| 2195 | |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 2196 | lnum = wp->w_topline; // first line shown in window |
| 2197 | |
| 2198 | spellvars_T spv; |
| 2199 | #ifdef FEAT_SPELL |
| 2200 | // Initialize spell related variables for the first drawn line. |
| 2201 | CLEAR_FIELD(spv); |
Luuk van Baal | e84c773 | 2023-05-31 18:57:36 +0100 | [diff] [blame] | 2202 | if (spell_check_window(wp)) |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 2203 | { |
Luuk van Baal | e84c773 | 2023-05-31 18:57:36 +0100 | [diff] [blame] | 2204 | spv.spv_has_spell = TRUE; |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 2205 | spv.spv_unchanged = mod_top == 0; |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 2206 | } |
| 2207 | #endif |
| 2208 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2209 | // Update all the window rows. |
| 2210 | idx = 0; // first entry in w_lines[].wl_size |
| 2211 | row = 0; |
| 2212 | srow = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2213 | for (;;) |
| 2214 | { |
| 2215 | // stop updating when reached the end of the window (check for _past_ |
| 2216 | // the end of the window is at the end of the loop) |
| 2217 | if (row == wp->w_height) |
| 2218 | { |
| 2219 | didline = TRUE; |
| 2220 | break; |
| 2221 | } |
| 2222 | |
| 2223 | // stop updating when hit the end of the file |
| 2224 | if (lnum > buf->b_ml.ml_line_count) |
| 2225 | { |
| 2226 | eof = TRUE; |
| 2227 | break; |
| 2228 | } |
| 2229 | |
| 2230 | // Remember the starting row of the line that is going to be dealt |
| 2231 | // with. It is used further down when the line doesn't fit. |
| 2232 | srow = row; |
| 2233 | |
| 2234 | // Update a line when it is in an area that needs updating, when it |
| 2235 | // has changes or w_lines[idx] is invalid. |
| 2236 | // "bot_start" may be halfway a wrapped line after using |
| 2237 | // win_del_lines(), check if the current line includes it. |
| 2238 | // When syntax folding is being used, the saved syntax states will |
| 2239 | // already have been updated, we can't see where the syntax state is |
| 2240 | // the same again, just update until the end of the window. |
| 2241 | if (row < top_end |
| 2242 | || (row >= mid_start && row < mid_end) |
| 2243 | #ifdef FEAT_SEARCH_EXTRA |
| 2244 | || top_to_mod |
| 2245 | #endif |
| 2246 | || idx >= wp->w_lines_valid |
| 2247 | || (row + wp->w_lines[idx].wl_size > bot_start) |
| 2248 | || (mod_top != 0 |
| 2249 | && (lnum == mod_top |
| 2250 | || (lnum >= mod_top |
| 2251 | && (lnum < mod_bot |
| 2252 | #ifdef FEAT_SYN_HL |
| 2253 | || did_update == DID_FOLD |
| 2254 | || (did_update == DID_LINE |
| 2255 | && syntax_present(wp) |
| 2256 | && ( |
| 2257 | # ifdef FEAT_FOLDING |
| 2258 | (foldmethodIsSyntax(wp) |
| 2259 | && hasAnyFolding(wp)) || |
| 2260 | # endif |
| 2261 | syntax_check_changed(lnum))) |
| 2262 | #endif |
| 2263 | #ifdef FEAT_SEARCH_EXTRA |
| 2264 | // match in fixed position might need redraw |
| 2265 | // if lines were inserted or deleted |
| 2266 | || (wp->w_match_head != NULL |
zeertzjq | 9f25a3a | 2024-11-26 15:08:02 +0100 | [diff] [blame] | 2267 | && buf->b_mod_set |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2268 | && buf->b_mod_xlines != 0) |
| 2269 | #endif |
Bram Moolenaar | 11a58af | 2019-10-24 22:32:31 +0200 | [diff] [blame] | 2270 | )))) |
| 2271 | #ifdef FEAT_SYN_HL |
zeertzjq | c20e46a | 2022-03-23 14:55:23 +0000 | [diff] [blame] | 2272 | || (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 2273 | || lnum == wp->w_last_cursorline |
Bram Moolenaar | 11a58af | 2019-10-24 22:32:31 +0200 | [diff] [blame] | 2274 | #endif |
| 2275 | ) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2276 | { |
| 2277 | #ifdef FEAT_SEARCH_EXTRA |
| 2278 | if (lnum == mod_top) |
| 2279 | top_to_mod = FALSE; |
| 2280 | #endif |
| 2281 | |
| 2282 | // When at start of changed lines: May scroll following lines |
| 2283 | // up or down to minimize redrawing. |
| 2284 | // Don't do this when the change continues until the end. |
| 2285 | // Don't scroll when dollar_vcol >= 0, keep the "$". |
Bram Moolenaar | c9e7e34 | 2021-07-22 21:33:03 +0200 | [diff] [blame] | 2286 | // Don't scroll when redrawing the top, scrolled already above. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2287 | if (lnum == mod_top |
| 2288 | && mod_bot != MAXLNUM |
Bram Moolenaar | c9e7e34 | 2021-07-22 21:33:03 +0200 | [diff] [blame] | 2289 | && !(dollar_vcol >= 0 && mod_bot == mod_top + 1) |
| 2290 | && row >= top_end) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2291 | { |
| 2292 | int old_rows = 0; |
| 2293 | int new_rows = 0; |
| 2294 | int xtra_rows; |
| 2295 | linenr_T l; |
| 2296 | |
| 2297 | // Count the old number of window rows, using w_lines[], which |
| 2298 | // should still contain the sizes for the lines as they are |
| 2299 | // currently displayed. |
| 2300 | for (i = idx; i < wp->w_lines_valid; ++i) |
| 2301 | { |
| 2302 | // Only valid lines have a meaningful wl_lnum. Invalid |
| 2303 | // lines are part of the changed area. |
| 2304 | if (wp->w_lines[i].wl_valid |
| 2305 | && wp->w_lines[i].wl_lnum == mod_bot) |
| 2306 | break; |
| 2307 | old_rows += wp->w_lines[i].wl_size; |
| 2308 | #ifdef FEAT_FOLDING |
| 2309 | if (wp->w_lines[i].wl_valid |
| 2310 | && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) |
| 2311 | { |
| 2312 | // Must have found the last valid entry above mod_bot. |
| 2313 | // Add following invalid entries. |
| 2314 | ++i; |
| 2315 | while (i < wp->w_lines_valid |
| 2316 | && !wp->w_lines[i].wl_valid) |
| 2317 | old_rows += wp->w_lines[i++].wl_size; |
| 2318 | break; |
| 2319 | } |
| 2320 | #endif |
| 2321 | } |
| 2322 | |
| 2323 | if (i >= wp->w_lines_valid) |
| 2324 | { |
| 2325 | // We can't find a valid line below the changed lines, |
| 2326 | // need to redraw until the end of the window. |
| 2327 | // Inserting/deleting lines has no use. |
| 2328 | bot_start = 0; |
| 2329 | } |
| 2330 | else |
| 2331 | { |
| 2332 | // Able to count old number of rows: Count new window |
| 2333 | // rows, and may insert/delete lines |
| 2334 | j = idx; |
| 2335 | for (l = lnum; l < mod_bot; ++l) |
| 2336 | { |
| 2337 | #ifdef FEAT_FOLDING |
| 2338 | if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) |
| 2339 | ++new_rows; |
| 2340 | else |
| 2341 | #endif |
Dominique Pelle | 9b0b844 | 2021-10-18 20:56:39 +0100 | [diff] [blame] | 2342 | { |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2343 | #ifdef FEAT_DIFF |
| 2344 | if (l == wp->w_topline) |
Luuk van Baal | c8502f9 | 2023-05-06 12:40:15 +0100 | [diff] [blame] | 2345 | { |
| 2346 | int n = plines_win_nofill(wp, l, FALSE) |
| 2347 | + wp->w_topfill; |
zeertzjq | 6235a10 | 2023-08-19 14:12:42 +0200 | [diff] [blame] | 2348 | n -= adjust_plines_for_skipcol(wp); |
Luuk van Baal | c8502f9 | 2023-05-06 12:40:15 +0100 | [diff] [blame] | 2349 | if (n > wp->w_height) |
| 2350 | n = wp->w_height; |
| 2351 | new_rows += n; |
| 2352 | } |
Dominique Pelle | 9b0b844 | 2021-10-18 20:56:39 +0100 | [diff] [blame] | 2353 | else |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2354 | #endif |
Dominique Pelle | 9b0b844 | 2021-10-18 20:56:39 +0100 | [diff] [blame] | 2355 | new_rows += plines_win(wp, l, TRUE); |
| 2356 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2357 | ++j; |
| 2358 | if (new_rows > wp->w_height - row - 2) |
| 2359 | { |
| 2360 | // it's getting too much, must redraw the rest |
| 2361 | new_rows = 9999; |
| 2362 | break; |
| 2363 | } |
| 2364 | } |
| 2365 | xtra_rows = new_rows - old_rows; |
| 2366 | if (xtra_rows < 0) |
| 2367 | { |
| 2368 | // May scroll text up. If there is not enough |
| 2369 | // remaining text or scrolling fails, must redraw the |
| 2370 | // rest. If scrolling works, must redraw the text |
| 2371 | // below the scrolled text. |
| 2372 | if (row - xtra_rows >= wp->w_height - 2) |
| 2373 | mod_bot = MAXLNUM; |
| 2374 | else |
| 2375 | { |
| 2376 | check_for_delay(FALSE); |
| 2377 | if (win_del_lines(wp, row, |
| 2378 | -xtra_rows, FALSE, FALSE, 0) == FAIL) |
| 2379 | mod_bot = MAXLNUM; |
| 2380 | else |
| 2381 | bot_start = wp->w_height + xtra_rows; |
| 2382 | } |
| 2383 | } |
| 2384 | else if (xtra_rows > 0) |
| 2385 | { |
| 2386 | // May scroll text down. If there is not enough |
| 2387 | // remaining text of scrolling fails, must redraw the |
| 2388 | // rest. |
| 2389 | if (row + xtra_rows >= wp->w_height - 2) |
| 2390 | mod_bot = MAXLNUM; |
| 2391 | else |
| 2392 | { |
| 2393 | check_for_delay(FALSE); |
| 2394 | if (win_ins_lines(wp, row + old_rows, |
| 2395 | xtra_rows, FALSE, FALSE) == FAIL) |
| 2396 | mod_bot = MAXLNUM; |
| 2397 | else if (top_end > row + old_rows) |
| 2398 | // Scrolled the part at the top that requires |
| 2399 | // updating down. |
| 2400 | top_end += xtra_rows; |
| 2401 | } |
| 2402 | } |
| 2403 | |
| 2404 | // When not updating the rest, may need to move w_lines[] |
| 2405 | // entries. |
| 2406 | if (mod_bot != MAXLNUM && i != j) |
| 2407 | { |
| 2408 | if (j < i) |
| 2409 | { |
| 2410 | int x = row + new_rows; |
| 2411 | |
| 2412 | // move entries in w_lines[] upwards |
| 2413 | for (;;) |
| 2414 | { |
| 2415 | // stop at last valid entry in w_lines[] |
| 2416 | if (i >= wp->w_lines_valid) |
| 2417 | { |
| 2418 | wp->w_lines_valid = j; |
| 2419 | break; |
| 2420 | } |
| 2421 | wp->w_lines[j] = wp->w_lines[i]; |
| 2422 | // stop at a line that won't fit |
| 2423 | if (x + (int)wp->w_lines[j].wl_size |
| 2424 | > wp->w_height) |
| 2425 | { |
| 2426 | wp->w_lines_valid = j + 1; |
| 2427 | break; |
| 2428 | } |
| 2429 | x += wp->w_lines[j++].wl_size; |
| 2430 | ++i; |
| 2431 | } |
| 2432 | if (bot_start > x) |
| 2433 | bot_start = x; |
| 2434 | } |
| 2435 | else // j > i |
| 2436 | { |
| 2437 | // move entries in w_lines[] downwards |
| 2438 | j -= i; |
| 2439 | wp->w_lines_valid += j; |
| 2440 | if (wp->w_lines_valid > wp->w_height) |
| 2441 | wp->w_lines_valid = wp->w_height; |
| 2442 | for (i = wp->w_lines_valid; i - j >= idx; --i) |
Bram Moolenaar | a2a8973 | 2022-08-31 14:46:18 +0100 | [diff] [blame] | 2443 | wp->w_lines[i] = wp->w_lines[i - j]; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2444 | |
| 2445 | // The w_lines[] entries for inserted lines are |
| 2446 | // now invalid, but wl_size may be used above. |
| 2447 | // Reset to zero. |
| 2448 | while (i >= idx) |
| 2449 | { |
| 2450 | wp->w_lines[i].wl_size = 0; |
| 2451 | wp->w_lines[i--].wl_valid = FALSE; |
| 2452 | } |
| 2453 | } |
| 2454 | } |
| 2455 | } |
| 2456 | } |
| 2457 | |
| 2458 | #ifdef FEAT_FOLDING |
| 2459 | // When lines are folded, display one line for all of them. |
| 2460 | // Otherwise, display normally (can be several display lines when |
| 2461 | // 'wrap' is on). |
| 2462 | fold_count = foldedCount(wp, lnum, &win_foldinfo); |
| 2463 | if (fold_count != 0) |
| 2464 | { |
| 2465 | fold_line(wp, fold_count, &win_foldinfo, lnum, row); |
| 2466 | ++row; |
| 2467 | --fold_count; |
| 2468 | wp->w_lines[idx].wl_folded = TRUE; |
Luuk van Baal | e84c773 | 2023-05-31 18:57:36 +0100 | [diff] [blame] | 2469 | wp->w_lines[idx].wl_lastlnum = lnum + fold_count; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2470 | # ifdef FEAT_SYN_HL |
| 2471 | did_update = DID_FOLD; |
| 2472 | # endif |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 2473 | # ifdef FEAT_SPELL |
Luuk van Baal | e84c773 | 2023-05-31 18:57:36 +0100 | [diff] [blame] | 2474 | spv.spv_capcol_lnum = 0; |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 2475 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2476 | } |
| 2477 | else |
| 2478 | #endif |
| 2479 | if (idx < wp->w_lines_valid |
| 2480 | && wp->w_lines[idx].wl_valid |
| 2481 | && wp->w_lines[idx].wl_lnum == lnum |
| 2482 | && lnum > wp->w_topline |
| 2483 | && !(dy_flags & (DY_LASTLINE | DY_TRUNCATE)) |
| 2484 | && !WIN_IS_POPUP(wp) |
| 2485 | && srow + wp->w_lines[idx].wl_size > wp->w_height |
| 2486 | #ifdef FEAT_DIFF |
| 2487 | && diff_check_fill(wp, lnum) == 0 |
| 2488 | #endif |
| 2489 | ) |
| 2490 | { |
| 2491 | // This line is not going to fit. Don't draw anything here, |
| 2492 | // will draw "@ " lines below. |
| 2493 | row = wp->w_height + 1; |
| 2494 | } |
| 2495 | else |
| 2496 | { |
| 2497 | #ifdef FEAT_SEARCH_EXTRA |
| 2498 | prepare_search_hl(wp, &screen_search_hl, lnum); |
| 2499 | #endif |
| 2500 | #ifdef FEAT_SYN_HL |
| 2501 | // Let the syntax stuff know we skipped a few lines. |
| 2502 | if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum |
| 2503 | && syntax_present(wp)) |
Bram Moolenaar | 0abd6cf | 2022-10-14 17:04:09 +0100 | [diff] [blame] | 2504 | syntax_end_parsing(wp, syntax_last_parsed + 1); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2505 | #endif |
| 2506 | |
| 2507 | // Display one line. |
zeertzjq | ebfd856 | 2024-02-06 10:59:03 +0100 | [diff] [blame] | 2508 | row = win_line(wp, lnum, srow, wp->w_height, 0, &spv); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2509 | |
| 2510 | #ifdef FEAT_FOLDING |
| 2511 | wp->w_lines[idx].wl_folded = FALSE; |
| 2512 | wp->w_lines[idx].wl_lastlnum = lnum; |
| 2513 | #endif |
| 2514 | #ifdef FEAT_SYN_HL |
| 2515 | did_update = DID_LINE; |
| 2516 | syntax_last_parsed = lnum; |
| 2517 | #endif |
| 2518 | } |
| 2519 | |
| 2520 | wp->w_lines[idx].wl_lnum = lnum; |
| 2521 | wp->w_lines[idx].wl_valid = TRUE; |
| 2522 | |
| 2523 | // Past end of the window or end of the screen. Note that after |
| 2524 | // resizing wp->w_height may be end up too big. That's a problem |
| 2525 | // elsewhere, but prevent a crash here. |
Bram Moolenaar | a2a8973 | 2022-08-31 14:46:18 +0100 | [diff] [blame] | 2526 | if (row > wp->w_height || row + wp->w_winrow >= Rows) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2527 | { |
| 2528 | // we may need the size of that too long line later on |
| 2529 | if (dollar_vcol == -1) |
| 2530 | wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); |
| 2531 | ++idx; |
| 2532 | break; |
| 2533 | } |
| 2534 | if (dollar_vcol == -1) |
| 2535 | wp->w_lines[idx].wl_size = row - srow; |
| 2536 | ++idx; |
| 2537 | #ifdef FEAT_FOLDING |
| 2538 | lnum += fold_count + 1; |
| 2539 | #else |
| 2540 | ++lnum; |
| 2541 | #endif |
| 2542 | } |
| 2543 | else |
| 2544 | { |
zeertzjq | ae07ebc | 2024-02-08 11:37:40 +0100 | [diff] [blame] | 2545 | // If: |
| 2546 | // - 'number' is set and below inserted/deleted lines, or |
| 2547 | // - 'relativenumber' is set and cursor moved vertically, |
| 2548 | // the text doesn't need to be redrawn, but the number column does. |
zeertzjq | 9f25a3a | 2024-11-26 15:08:02 +0100 | [diff] [blame] | 2549 | if ((wp->w_p_nu && mod_top != 0 && lnum >= mod_bot |
| 2550 | && buf->b_mod_set && buf->b_mod_xlines != 0) |
zeertzjq | ae07ebc | 2024-02-08 11:37:40 +0100 | [diff] [blame] | 2551 | || (wp->w_p_rnu |
| 2552 | && wp->w_last_cursor_lnum_rnu != wp->w_cursor.lnum)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2553 | { |
| 2554 | #ifdef FEAT_FOLDING |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2555 | fold_count = foldedCount(wp, lnum, &win_foldinfo); |
| 2556 | if (fold_count != 0) |
| 2557 | fold_line(wp, fold_count, &win_foldinfo, lnum, row); |
| 2558 | else |
| 2559 | #endif |
zeertzjq | ebfd856 | 2024-02-06 10:59:03 +0100 | [diff] [blame] | 2560 | (void)win_line(wp, lnum, srow, wp->w_height, |
| 2561 | wp->w_lines[idx].wl_size, &spv); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2562 | } |
| 2563 | |
| 2564 | // This line does not need to be drawn, advance to the next one. |
| 2565 | row += wp->w_lines[idx++].wl_size; |
| 2566 | if (row > wp->w_height) // past end of screen |
| 2567 | break; |
| 2568 | #ifdef FEAT_FOLDING |
| 2569 | lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; |
| 2570 | #else |
| 2571 | ++lnum; |
| 2572 | #endif |
| 2573 | #ifdef FEAT_SYN_HL |
| 2574 | did_update = DID_NONE; |
| 2575 | #endif |
Luuk van Baal | e84c773 | 2023-05-31 18:57:36 +0100 | [diff] [blame] | 2576 | #ifdef FEAT_SPELL |
| 2577 | spv.spv_capcol_lnum = 0; |
| 2578 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2579 | } |
| 2580 | |
| 2581 | if (lnum > buf->b_ml.ml_line_count) |
| 2582 | { |
| 2583 | eof = TRUE; |
| 2584 | break; |
| 2585 | } |
Bram Moolenaar | fa1a457 | 2022-01-16 11:42:20 +0000 | [diff] [blame] | 2586 | |
| 2587 | // Safety check: if any of the wl_size values is wrong we might go over |
| 2588 | // the end of w_lines[]. |
Bram Moolenaar | a2a8973 | 2022-08-31 14:46:18 +0100 | [diff] [blame] | 2589 | if (idx >= Rows) |
Bram Moolenaar | fa1a457 | 2022-01-16 11:42:20 +0000 | [diff] [blame] | 2590 | break; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2591 | } |
| 2592 | |
| 2593 | // End of loop over all window lines. |
| 2594 | |
zeertzjq | c20e46a | 2022-03-23 14:55:23 +0000 | [diff] [blame] | 2595 | #ifdef FEAT_SYN_HL |
| 2596 | // Now that the window has been redrawn with the old and new cursor line, |
| 2597 | // update w_last_cursorline. |
| 2598 | wp->w_last_cursorline = wp->w_p_cul ? wp->w_cursor.lnum : 0; |
| 2599 | #endif |
Lewis Russell | 1624639 | 2022-03-29 11:38:17 +0100 | [diff] [blame] | 2600 | wp->w_last_cursor_lnum_rnu = wp->w_p_rnu ? wp->w_cursor.lnum : 0; |
zeertzjq | c20e46a | 2022-03-23 14:55:23 +0000 | [diff] [blame] | 2601 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2602 | #ifdef FEAT_VTP |
| 2603 | // Rewrite the character at the end of the screen line. |
Bram Moolenaar | 7ed8f59 | 2020-04-28 20:44:42 +0200 | [diff] [blame] | 2604 | // See the version that was fixed. |
| 2605 | if (use_vtp() && get_conpty_fix_type() < 1) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2606 | { |
K.Takata | 5411910 | 2022-02-03 13:33:03 +0000 | [diff] [blame] | 2607 | int k; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2608 | |
K.Takata | 5411910 | 2022-02-03 13:33:03 +0000 | [diff] [blame] | 2609 | for (k = 0; k < Rows; ++k) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2610 | if (enc_utf8) |
Hirohito Higashi | 3b9b95d | 2025-06-01 20:22:55 +0200 | [diff] [blame] | 2611 | if ((*mb_off2cells)(LineOffset[k] + topframe->fr_width - 2, |
K.Takata | 5411910 | 2022-02-03 13:33:03 +0000 | [diff] [blame] | 2612 | LineOffset[k] + screen_Columns) > 1) |
Hirohito Higashi | 3b9b95d | 2025-06-01 20:22:55 +0200 | [diff] [blame] | 2613 | screen_draw_rectangle(k, topframe->fr_width - 2, 1, 2, |
| 2614 | FALSE); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2615 | else |
Hirohito Higashi | 3b9b95d | 2025-06-01 20:22:55 +0200 | [diff] [blame] | 2616 | screen_draw_rectangle(k, topframe->fr_width - 1, 1, 1, |
| 2617 | FALSE); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2618 | else |
Hirohito Higashi | 3b9b95d | 2025-06-01 20:22:55 +0200 | [diff] [blame] | 2619 | screen_char(LineOffset[k] + topframe->fr_width - 1, k, |
| 2620 | Columns - 1); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2621 | } |
| 2622 | #endif |
| 2623 | |
| 2624 | if (idx > wp->w_lines_valid) |
| 2625 | wp->w_lines_valid = idx; |
| 2626 | |
| 2627 | #ifdef FEAT_SYN_HL |
| 2628 | // Let the syntax stuff know we stop parsing here. |
| 2629 | if (syntax_last_parsed != 0 && syntax_present(wp)) |
Bram Moolenaar | 0abd6cf | 2022-10-14 17:04:09 +0100 | [diff] [blame] | 2630 | syntax_end_parsing(wp, syntax_last_parsed + 1); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2631 | #endif |
| 2632 | |
| 2633 | // If we didn't hit the end of the file, and we didn't finish the last |
| 2634 | // line we were working on, then the line didn't fit. |
| 2635 | wp->w_empty_rows = 0; |
| 2636 | #ifdef FEAT_DIFF |
| 2637 | wp->w_filler_rows = 0; |
| 2638 | #endif |
| 2639 | if (!eof && !didline) |
| 2640 | { |
| 2641 | if (lnum == wp->w_topline) |
| 2642 | { |
| 2643 | // Single line that does not fit! |
| 2644 | // Don't overwrite it, it can be edited. |
| 2645 | wp->w_botline = lnum + 1; |
| 2646 | } |
| 2647 | #ifdef FEAT_DIFF |
| 2648 | else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) |
| 2649 | { |
| 2650 | // Window ends in filler lines. |
| 2651 | wp->w_botline = lnum; |
| 2652 | wp->w_filler_rows = wp->w_height - srow; |
| 2653 | } |
| 2654 | #endif |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 2655 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2656 | else if (WIN_IS_POPUP(wp)) |
| 2657 | { |
| 2658 | // popup line that doesn't fit is left as-is |
| 2659 | wp->w_botline = lnum; |
| 2660 | } |
| 2661 | #endif |
| 2662 | else if (dy_flags & DY_TRUNCATE) // 'display' has "truncate" |
| 2663 | { |
Bram Moolenaar | 4ba5f1d | 2022-10-04 14:36:29 +0100 | [diff] [blame] | 2664 | int scr_row = W_WINROW(wp) + wp->w_height - 1; |
| 2665 | int symbol = wp->w_fill_chars.lastline; |
zeertzjq | 18b3500 | 2022-10-04 20:35:37 +0100 | [diff] [blame] | 2666 | int charlen; |
Bram Moolenaar | 4ba5f1d | 2022-10-04 14:36:29 +0100 | [diff] [blame] | 2667 | char_u fillbuf[12]; // 2 characters of 6 bytes |
| 2668 | |
zeertzjq | 18b3500 | 2022-10-04 20:35:37 +0100 | [diff] [blame] | 2669 | charlen = mb_char2bytes(symbol, &fillbuf[0]); |
| 2670 | mb_char2bytes(symbol, &fillbuf[charlen]); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2671 | |
| 2672 | // Last line isn't finished: Display "@@@" in the last screen line. |
Bram Moolenaar | 4ba5f1d | 2022-10-04 14:36:29 +0100 | [diff] [blame] | 2673 | screen_puts_len(fillbuf, |
zeertzjq | 18b3500 | 2022-10-04 20:35:37 +0100 | [diff] [blame] | 2674 | (wp->w_width > 2 ? 2 : wp->w_width) * charlen, |
Bram Moolenaar | 4ba5f1d | 2022-10-04 14:36:29 +0100 | [diff] [blame] | 2675 | scr_row, wp->w_wincol, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2676 | screen_fill(scr_row, scr_row + 1, |
| 2677 | (int)wp->w_wincol + 2, (int)W_ENDCOL(wp), |
Bram Moolenaar | 4ba5f1d | 2022-10-04 14:36:29 +0100 | [diff] [blame] | 2678 | symbol, ' ', HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2679 | set_empty_rows(wp, srow); |
| 2680 | wp->w_botline = lnum; |
| 2681 | } |
| 2682 | else if (dy_flags & DY_LASTLINE) // 'display' has "lastline" |
| 2683 | { |
Bram Moolenaar | cee9c84 | 2022-04-09 12:40:13 +0100 | [diff] [blame] | 2684 | int start_col = (int)W_ENDCOL(wp) - 3; |
Bram Moolenaar | 4ba5f1d | 2022-10-04 14:36:29 +0100 | [diff] [blame] | 2685 | int symbol = wp->w_fill_chars.lastline; |
Bram Moolenaar | cee9c84 | 2022-04-09 12:40:13 +0100 | [diff] [blame] | 2686 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2687 | // Last line isn't finished: Display "@@@" at the end. |
| 2688 | screen_fill(W_WINROW(wp) + wp->w_height - 1, |
| 2689 | W_WINROW(wp) + wp->w_height, |
Hirohito Higashi | 3b9b95d | 2025-06-01 20:22:55 +0200 | [diff] [blame] | 2690 | (start_col < wp->w_wincol ? wp->w_wincol : start_col), |
| 2691 | (int)W_ENDCOL(wp), |
Bram Moolenaar | 4ba5f1d | 2022-10-04 14:36:29 +0100 | [diff] [blame] | 2692 | symbol, symbol, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2693 | set_empty_rows(wp, srow); |
| 2694 | wp->w_botline = lnum; |
| 2695 | } |
| 2696 | else |
| 2697 | { |
Bram Moolenaar | 4ba5f1d | 2022-10-04 14:36:29 +0100 | [diff] [blame] | 2698 | win_draw_end(wp, wp->w_fill_chars.lastline, ' ', TRUE, |
| 2699 | srow, wp->w_height, HLF_AT); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2700 | wp->w_botline = lnum; |
| 2701 | } |
| 2702 | } |
| 2703 | else |
| 2704 | { |
| 2705 | draw_vsep_win(wp, row); |
| 2706 | if (eof) // we hit the end of the file |
| 2707 | { |
| 2708 | wp->w_botline = buf->b_ml.ml_line_count + 1; |
| 2709 | #ifdef FEAT_DIFF |
| 2710 | j = diff_check_fill(wp, wp->w_botline); |
| 2711 | if (j > 0 && !wp->w_botfill) |
| 2712 | { |
| 2713 | // Display filler lines at the end of the file. |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 2714 | if (char2cells(wp->w_fill_chars.diff) > 1) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2715 | i = '-'; |
| 2716 | else |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 2717 | i = wp->w_fill_chars.diff; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2718 | if (row + j > wp->w_height) |
| 2719 | j = wp->w_height - row; |
| 2720 | win_draw_end(wp, i, i, TRUE, row, row + (int)j, HLF_DED); |
| 2721 | row += j; |
| 2722 | } |
| 2723 | #endif |
| 2724 | } |
| 2725 | else if (dollar_vcol == -1) |
| 2726 | wp->w_botline = lnum; |
| 2727 | |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 2728 | // Make sure the rest of the screen is blank. |
| 2729 | // write the "eob" character from 'fillchars' to rows that aren't part |
| 2730 | // of the file. |
Bram Moolenaar | 1666ac9 | 2019-11-10 17:22:31 +0100 | [diff] [blame] | 2731 | if (WIN_IS_POPUP(wp)) |
| 2732 | win_draw_end(wp, ' ', ' ', FALSE, row, wp->w_height, HLF_AT); |
| 2733 | else |
Bram Moolenaar | 96ba25a | 2022-07-04 17:34:33 +0100 | [diff] [blame] | 2734 | win_draw_end(wp, wp->w_fill_chars.eob, ' ', FALSE, |
| 2735 | row, wp->w_height, HLF_EOB); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2736 | } |
| 2737 | |
| 2738 | #ifdef SYN_TIME_LIMIT |
Paul Ollis | 6574577 | 2022-06-05 16:55:54 +0100 | [diff] [blame] | 2739 | disable_regexp_timeout(); |
Bram Moolenaar | 6f0cf62 | 2022-06-19 12:27:45 +0100 | [diff] [blame] | 2740 | redrawtime_limit_set = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2741 | #endif |
| 2742 | |
| 2743 | // Reset the type of redrawing required, the window has been updated. |
| 2744 | wp->w_redr_type = 0; |
| 2745 | #ifdef FEAT_DIFF |
| 2746 | wp->w_old_topfill = wp->w_topfill; |
| 2747 | wp->w_old_botfill = wp->w_botfill; |
| 2748 | #endif |
| 2749 | |
| 2750 | if (dollar_vcol == -1) |
| 2751 | { |
| 2752 | // There is a trick with w_botline. If we invalidate it on each |
| 2753 | // change that might modify it, this will cause a lot of expensive |
| 2754 | // calls to plines() in update_topline() each time. Therefore the |
| 2755 | // value of w_botline is often approximated, and this value is used to |
| 2756 | // compute the value of w_topline. If the value of w_botline was |
| 2757 | // wrong, check that the value of w_topline is correct (cursor is on |
| 2758 | // the visible part of the text). If it's not, we need to redraw |
| 2759 | // again. Mostly this just means scrolling up a few lines, so it |
| 2760 | // doesn't look too bad. Only do this for the current window (where |
| 2761 | // changes are relevant). |
| 2762 | wp->w_valid |= VALID_BOTLINE; |
| 2763 | if (wp == curwin && wp->w_botline != old_botline && !recursive) |
| 2764 | { |
Bram Moolenaar | cbee635 | 2019-11-12 20:49:15 +0100 | [diff] [blame] | 2765 | win_T *wwp; |
| 2766 | #if defined(FEAT_CONCEAL) |
| 2767 | linenr_T old_topline = wp->w_topline; |
| 2768 | int new_wcol = wp->w_wcol; |
| 2769 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2770 | recursive = TRUE; |
| 2771 | curwin->w_valid &= ~VALID_TOPLINE; |
| 2772 | update_topline(); // may invalidate w_botline again |
Bram Moolenaar | cbee635 | 2019-11-12 20:49:15 +0100 | [diff] [blame] | 2773 | |
| 2774 | #if defined(FEAT_CONCEAL) |
| 2775 | if (old_wcol != new_wcol && (wp->w_valid & (VALID_WCOL|VALID_WROW)) |
| 2776 | != (VALID_WCOL|VALID_WROW)) |
| 2777 | { |
| 2778 | // A win_line() call applied a fix to screen cursor column to |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 2779 | // accommodate concealment of cursor line, but in this call to |
Bram Moolenaar | cbee635 | 2019-11-12 20:49:15 +0100 | [diff] [blame] | 2780 | // update_topline() the cursor's row or column got invalidated. |
| 2781 | // If they are left invalid, setcursor() will recompute them |
| 2782 | // but there won't be any further win_line() call to re-fix the |
| 2783 | // column and the cursor will end up misplaced. So we call |
| 2784 | // cursor validation now and reapply the fix again (or call |
| 2785 | // win_line() to do it for us). |
| 2786 | validate_cursor(); |
| 2787 | if (wp->w_wcol == old_wcol && wp->w_wrow == old_wrow |
| 2788 | && old_topline == wp->w_topline) |
| 2789 | wp->w_wcol = new_wcol; |
| 2790 | else |
| 2791 | redrawWinline(wp, wp->w_cursor.lnum); |
| 2792 | } |
| 2793 | #endif |
Luuk van Baal | 3d5065f | 2024-09-01 10:33:56 +0200 | [diff] [blame] | 2794 | // New redraw either due to updated topline, wcol fix or reset skipcol. |
Bram Moolenaar | cbee635 | 2019-11-12 20:49:15 +0100 | [diff] [blame] | 2795 | if (wp->w_redr_type != 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2796 | { |
| 2797 | // Don't update for changes in buffer again. |
| 2798 | i = curbuf->b_mod_set; |
| 2799 | curbuf->b_mod_set = FALSE; |
Bram Moolenaar | cbee635 | 2019-11-12 20:49:15 +0100 | [diff] [blame] | 2800 | j = curbuf->b_mod_xlines; |
| 2801 | curbuf->b_mod_xlines = 0; |
Luuk van Baal | 3d5065f | 2024-09-01 10:33:56 +0200 | [diff] [blame] | 2802 | curs_columns(TRUE); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2803 | win_update(curwin); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2804 | curbuf->b_mod_set = i; |
Bram Moolenaar | cbee635 | 2019-11-12 20:49:15 +0100 | [diff] [blame] | 2805 | curbuf->b_mod_xlines = j; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2806 | } |
Bram Moolenaar | cbee635 | 2019-11-12 20:49:15 +0100 | [diff] [blame] | 2807 | // Other windows might have w_redr_type raised in update_topline(). |
| 2808 | must_redraw = 0; |
| 2809 | FOR_ALL_WINDOWS(wwp) |
| 2810 | if (wwp->w_redr_type > must_redraw) |
| 2811 | must_redraw = wwp->w_redr_type; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2812 | recursive = FALSE; |
| 2813 | } |
| 2814 | } |
| 2815 | |
| 2816 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 2817 | // restore got_int, unless CTRL-C was hit while redrawing |
| 2818 | if (!got_int) |
| 2819 | got_int = save_got_int; |
| 2820 | #endif |
| 2821 | } |
| 2822 | |
| 2823 | #if defined(FEAT_NETBEANS_INTG) || defined(FEAT_GUI) |
| 2824 | /* |
| 2825 | * Prepare for updating one or more windows. |
| 2826 | * Caller must check for "updating_screen" already set to avoid recursiveness. |
| 2827 | */ |
| 2828 | static void |
| 2829 | update_prepare(void) |
| 2830 | { |
| 2831 | cursor_off(); |
| 2832 | updating_screen = TRUE; |
| 2833 | #ifdef FEAT_GUI |
| 2834 | // Remove the cursor before starting to do anything, because scrolling may |
| 2835 | // make it difficult to redraw the text under it. |
| 2836 | if (gui.in_use) |
| 2837 | gui_undraw_cursor(); |
| 2838 | #endif |
| 2839 | #ifdef FEAT_SEARCH_EXTRA |
| 2840 | start_search_hl(); |
| 2841 | #endif |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 2842 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2843 | // Update popup_mask if needed. |
| 2844 | may_update_popup_mask(must_redraw); |
| 2845 | #endif |
| 2846 | } |
| 2847 | |
| 2848 | /* |
| 2849 | * Finish updating one or more windows. |
| 2850 | */ |
| 2851 | static void |
| 2852 | update_finish(void) |
| 2853 | { |
| 2854 | if (redraw_cmdline || redraw_mode) |
| 2855 | showmode(); |
| 2856 | |
| 2857 | # ifdef FEAT_SEARCH_EXTRA |
| 2858 | end_search_hl(); |
| 2859 | # endif |
| 2860 | |
| 2861 | after_updating_screen(TRUE); |
| 2862 | |
| 2863 | # ifdef FEAT_GUI |
| 2864 | // Redraw the cursor and update the scrollbars when all screen updating is |
| 2865 | // done. |
| 2866 | if (gui.in_use) |
| 2867 | { |
| 2868 | out_flush_cursor(FALSE, FALSE); |
| 2869 | gui_update_scrollbars(FALSE); |
| 2870 | } |
| 2871 | # endif |
| 2872 | } |
| 2873 | #endif |
| 2874 | |
| 2875 | #if defined(FEAT_NETBEANS_INTG) || defined(PROTO) |
| 2876 | void |
| 2877 | update_debug_sign(buf_T *buf, linenr_T lnum) |
| 2878 | { |
| 2879 | win_T *wp; |
| 2880 | int doit = FALSE; |
| 2881 | |
| 2882 | # ifdef FEAT_FOLDING |
| 2883 | win_foldinfo.fi_level = 0; |
| 2884 | # endif |
| 2885 | |
| 2886 | // update/delete a specific sign |
| 2887 | redraw_buf_line_later(buf, lnum); |
| 2888 | |
| 2889 | // check if it resulted in the need to redraw a window |
| 2890 | FOR_ALL_WINDOWS(wp) |
| 2891 | if (wp->w_redr_type != 0) |
| 2892 | doit = TRUE; |
| 2893 | |
| 2894 | // Return when there is nothing to do, screen updating is already |
| 2895 | // happening (recursive call), messages on the screen or still starting up. |
| 2896 | if (!doit || updating_screen |
Bram Moolenaar | 2495910 | 2022-05-07 20:01:16 +0100 | [diff] [blame] | 2897 | || State == MODE_ASKMORE || State == MODE_HITRETURN |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2898 | || msg_scrolled |
| 2899 | #ifdef FEAT_GUI |
| 2900 | || gui.starting |
| 2901 | #endif |
| 2902 | || starting) |
| 2903 | return; |
| 2904 | |
| 2905 | // update all windows that need updating |
| 2906 | update_prepare(); |
| 2907 | |
| 2908 | FOR_ALL_WINDOWS(wp) |
| 2909 | { |
| 2910 | if (wp->w_redr_type != 0) |
| 2911 | win_update(wp); |
| 2912 | if (wp->w_redr_status) |
| 2913 | win_redr_status(wp, FALSE); |
| 2914 | } |
| 2915 | |
Naruhiko Nishino | be5bd4d | 2025-05-14 21:20:28 +0200 | [diff] [blame] | 2916 | #if defined(FEAT_TABPANEL) |
| 2917 | if (redraw_tabpanel) |
| 2918 | draw_tabpanel(); |
| 2919 | #endif |
| 2920 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2921 | update_finish(); |
| 2922 | } |
| 2923 | #endif |
| 2924 | |
| 2925 | #if defined(FEAT_GUI) || defined(PROTO) |
| 2926 | /* |
| 2927 | * Update a single window, its status line and maybe the command line msg. |
| 2928 | * Used for the GUI scrollbar. |
| 2929 | */ |
| 2930 | void |
| 2931 | updateWindow(win_T *wp) |
| 2932 | { |
| 2933 | // return if already busy updating |
| 2934 | if (updating_screen) |
| 2935 | return; |
| 2936 | |
| 2937 | update_prepare(); |
| 2938 | |
| 2939 | #ifdef FEAT_CLIPBOARD |
| 2940 | // When Visual area changed, may have to update selection. |
| 2941 | if (clip_star.available && clip_isautosel_star()) |
| 2942 | clip_update_selection(&clip_star); |
| 2943 | if (clip_plus.available && clip_isautosel_plus()) |
| 2944 | clip_update_selection(&clip_plus); |
| 2945 | #endif |
| 2946 | |
| 2947 | win_update(wp); |
| 2948 | |
| 2949 | // When the screen was cleared redraw the tab pages line. |
| 2950 | if (redraw_tabline) |
| 2951 | draw_tabline(); |
| 2952 | |
Naruhiko Nishino | be5bd4d | 2025-05-14 21:20:28 +0200 | [diff] [blame] | 2953 | #if defined(FEAT_TABPANEL) |
| 2954 | if (redraw_tabpanel) |
| 2955 | draw_tabpanel(); |
| 2956 | #endif |
| 2957 | |
Martin Tournoij | ba43e76 | 2022-10-13 22:12:15 +0100 | [diff] [blame] | 2958 | if (wp->w_redr_status || p_ru |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2959 | # ifdef FEAT_STL_OPT |
| 2960 | || *p_stl != NUL || *wp->w_p_stl != NUL |
| 2961 | # endif |
| 2962 | ) |
| 2963 | win_redr_status(wp, FALSE); |
| 2964 | |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 2965 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2966 | // Display popup windows on top of everything. |
| 2967 | update_popups(win_update); |
| 2968 | #endif |
| 2969 | |
| 2970 | update_finish(); |
| 2971 | } |
| 2972 | #endif |
| 2973 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2974 | /* |
| 2975 | * Redraw as soon as possible. When the command line is not scrolled redraw |
| 2976 | * right away and restore what was on the command line. |
| 2977 | * Return a code indicating what happened. |
| 2978 | */ |
| 2979 | int |
| 2980 | redraw_asap(int type) |
| 2981 | { |
| 2982 | int rows; |
| 2983 | int cols = screen_Columns; |
| 2984 | int r; |
| 2985 | int ret = 0; |
| 2986 | schar_T *screenline; // copy from ScreenLines[] |
| 2987 | sattr_T *screenattr; // copy from ScreenAttrs[] |
| 2988 | int i; |
| 2989 | u8char_T *screenlineUC = NULL; // copy from ScreenLinesUC[] |
| 2990 | u8char_T *screenlineC[MAX_MCO]; // copy from ScreenLinesC[][] |
| 2991 | schar_T *screenline2 = NULL; // copy from ScreenLines2[] |
| 2992 | |
| 2993 | redraw_later(type); |
Shougo Matsushita | f39cfb7 | 2022-07-30 16:54:05 +0100 | [diff] [blame] | 2994 | if (msg_scrolled |
| 2995 | || (State != MODE_NORMAL && State != MODE_NORMAL_BUSY) |
Bram Moolenaar | a2a8973 | 2022-08-31 14:46:18 +0100 | [diff] [blame] | 2996 | || exiting) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2997 | return ret; |
| 2998 | |
| 2999 | // Allocate space to save the text displayed in the command line area. |
| 3000 | rows = screen_Rows - cmdline_row; |
| 3001 | screenline = LALLOC_MULT(schar_T, rows * cols); |
| 3002 | screenattr = LALLOC_MULT(sattr_T, rows * cols); |
| 3003 | if (screenline == NULL || screenattr == NULL) |
| 3004 | ret = 2; |
| 3005 | if (enc_utf8) |
| 3006 | { |
| 3007 | screenlineUC = LALLOC_MULT(u8char_T, rows * cols); |
| 3008 | if (screenlineUC == NULL) |
| 3009 | ret = 2; |
| 3010 | for (i = 0; i < p_mco; ++i) |
| 3011 | { |
| 3012 | screenlineC[i] = LALLOC_MULT(u8char_T, rows * cols); |
| 3013 | if (screenlineC[i] == NULL) |
| 3014 | ret = 2; |
| 3015 | } |
| 3016 | } |
| 3017 | if (enc_dbcs == DBCS_JPNU) |
| 3018 | { |
| 3019 | screenline2 = LALLOC_MULT(schar_T, rows * cols); |
| 3020 | if (screenline2 == NULL) |
| 3021 | ret = 2; |
| 3022 | } |
| 3023 | |
| 3024 | if (ret != 2) |
| 3025 | { |
| 3026 | // Save the text displayed in the command line area. |
| 3027 | for (r = 0; r < rows; ++r) |
| 3028 | { |
| 3029 | mch_memmove(screenline + r * cols, |
| 3030 | ScreenLines + LineOffset[cmdline_row + r], |
| 3031 | (size_t)cols * sizeof(schar_T)); |
| 3032 | mch_memmove(screenattr + r * cols, |
| 3033 | ScreenAttrs + LineOffset[cmdline_row + r], |
| 3034 | (size_t)cols * sizeof(sattr_T)); |
| 3035 | if (enc_utf8) |
| 3036 | { |
| 3037 | mch_memmove(screenlineUC + r * cols, |
| 3038 | ScreenLinesUC + LineOffset[cmdline_row + r], |
| 3039 | (size_t)cols * sizeof(u8char_T)); |
| 3040 | for (i = 0; i < p_mco; ++i) |
| 3041 | mch_memmove(screenlineC[i] + r * cols, |
| 3042 | ScreenLinesC[i] + LineOffset[cmdline_row + r], |
| 3043 | (size_t)cols * sizeof(u8char_T)); |
| 3044 | } |
| 3045 | if (enc_dbcs == DBCS_JPNU) |
| 3046 | mch_memmove(screenline2 + r * cols, |
| 3047 | ScreenLines2 + LineOffset[cmdline_row + r], |
| 3048 | (size_t)cols * sizeof(schar_T)); |
| 3049 | } |
| 3050 | |
| 3051 | update_screen(0); |
| 3052 | ret = 3; |
| 3053 | |
| 3054 | if (must_redraw == 0) |
| 3055 | { |
| 3056 | int off = (int)(current_ScreenLine - ScreenLines); |
| 3057 | |
| 3058 | // Restore the text displayed in the command line area. |
| 3059 | for (r = 0; r < rows; ++r) |
| 3060 | { |
| 3061 | mch_memmove(current_ScreenLine, |
| 3062 | screenline + r * cols, |
| 3063 | (size_t)cols * sizeof(schar_T)); |
| 3064 | mch_memmove(ScreenAttrs + off, |
| 3065 | screenattr + r * cols, |
| 3066 | (size_t)cols * sizeof(sattr_T)); |
| 3067 | if (enc_utf8) |
| 3068 | { |
| 3069 | mch_memmove(ScreenLinesUC + off, |
| 3070 | screenlineUC + r * cols, |
| 3071 | (size_t)cols * sizeof(u8char_T)); |
| 3072 | for (i = 0; i < p_mco; ++i) |
| 3073 | mch_memmove(ScreenLinesC[i] + off, |
| 3074 | screenlineC[i] + r * cols, |
| 3075 | (size_t)cols * sizeof(u8char_T)); |
| 3076 | } |
| 3077 | if (enc_dbcs == DBCS_JPNU) |
| 3078 | mch_memmove(ScreenLines2 + off, |
| 3079 | screenline2 + r * cols, |
| 3080 | (size_t)cols * sizeof(schar_T)); |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 3081 | screen_line(curwin, cmdline_row + r, 0, cols, cols, -1, 0); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3082 | } |
| 3083 | ret = 4; |
| 3084 | } |
| 3085 | } |
| 3086 | |
| 3087 | vim_free(screenline); |
| 3088 | vim_free(screenattr); |
| 3089 | if (enc_utf8) |
| 3090 | { |
| 3091 | vim_free(screenlineUC); |
| 3092 | for (i = 0; i < p_mco; ++i) |
| 3093 | vim_free(screenlineC[i]); |
| 3094 | } |
| 3095 | if (enc_dbcs == DBCS_JPNU) |
| 3096 | vim_free(screenline2); |
| 3097 | |
| 3098 | // Show the intro message when appropriate. |
| 3099 | maybe_intro_message(); |
| 3100 | |
| 3101 | setcursor(); |
| 3102 | |
| 3103 | return ret; |
| 3104 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3105 | |
| 3106 | /* |
| 3107 | * Invoked after an asynchronous callback is called. |
| 3108 | * If an echo command was used the cursor needs to be put back where |
| 3109 | * it belongs. If highlighting was changed a redraw is needed. |
| 3110 | * If "call_update_screen" is FALSE don't call update_screen() when at the |
| 3111 | * command line. |
Bram Moolenaar | e505071 | 2021-12-09 10:51:05 +0000 | [diff] [blame] | 3112 | * If "redraw_message" is TRUE. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3113 | */ |
| 3114 | void |
Bram Moolenaar | e505071 | 2021-12-09 10:51:05 +0000 | [diff] [blame] | 3115 | redraw_after_callback(int call_update_screen, int do_message) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3116 | { |
| 3117 | ++redrawing_for_callback; |
| 3118 | |
Bram Moolenaar | 2495910 | 2022-05-07 20:01:16 +0100 | [diff] [blame] | 3119 | if (State == MODE_HITRETURN || State == MODE_ASKMORE |
| 3120 | || State == MODE_SETWSIZE || State == MODE_EXTERNCMD |
| 3121 | || State == MODE_CONFIRM || exmode_active) |
Bram Moolenaar | e505071 | 2021-12-09 10:51:05 +0000 | [diff] [blame] | 3122 | { |
| 3123 | if (do_message) |
| 3124 | repeat_message(); |
| 3125 | } |
Bram Moolenaar | 2495910 | 2022-05-07 20:01:16 +0100 | [diff] [blame] | 3126 | else if (State & MODE_CMDLINE) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3127 | { |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 3128 | if (pum_visible()) |
| 3129 | cmdline_pum_display(); |
Bram Moolenaar | 5416232 | 2022-08-26 16:58:51 +0100 | [diff] [blame] | 3130 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3131 | // Don't redraw when in prompt_for_number(). |
| 3132 | if (cmdline_row > 0) |
| 3133 | { |
| 3134 | // Redrawing only works when the screen didn't scroll. Don't clear |
| 3135 | // wildmenu entries. |
| 3136 | if (msg_scrolled == 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3137 | && wild_menu_showing == 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3138 | && call_update_screen) |
| 3139 | update_screen(0); |
| 3140 | |
| 3141 | // Redraw in the same position, so that the user can continue |
| 3142 | // editing the command. |
| 3143 | redrawcmdline_ex(FALSE); |
| 3144 | } |
| 3145 | } |
Bram Moolenaar | 2495910 | 2022-05-07 20:01:16 +0100 | [diff] [blame] | 3146 | else if (State & (MODE_NORMAL | MODE_INSERT | MODE_TERMINAL)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3147 | { |
zeertzjq | 3e559cd | 2022-03-27 19:26:55 +0100 | [diff] [blame] | 3148 | update_topline(); |
| 3149 | validate_cursor(); |
| 3150 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3151 | // keep the command line if possible |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 3152 | update_screen(UPD_VALID_NO_UPDATE); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3153 | setcursor(); |
Bram Moolenaar | 9f28416 | 2021-04-22 21:39:30 +0200 | [diff] [blame] | 3154 | |
| 3155 | if (msg_scrolled == 0) |
| 3156 | { |
| 3157 | // don't want a hit-enter prompt when something else is displayed |
| 3158 | msg_didany = FALSE; |
| 3159 | need_wait_return = FALSE; |
| 3160 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3161 | } |
| 3162 | cursor_on(); |
| 3163 | #ifdef FEAT_GUI |
| 3164 | if (gui.in_use && !gui_mch_is_blink_off()) |
| 3165 | // Don't update the cursor when it is blinking and off to avoid |
| 3166 | // flicker. |
| 3167 | out_flush_cursor(FALSE, FALSE); |
| 3168 | else |
| 3169 | #endif |
| 3170 | out_flush(); |
| 3171 | |
| 3172 | --redrawing_for_callback; |
| 3173 | } |
| 3174 | |
| 3175 | /* |
| 3176 | * Redraw the current window later, with update_screen(type). |
| 3177 | * Set must_redraw only if not already set to a higher value. |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 3178 | * E.g. if must_redraw is UPD_CLEAR, type UPD_NOT_VALID will do nothing. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3179 | */ |
| 3180 | void |
| 3181 | redraw_later(int type) |
| 3182 | { |
| 3183 | redraw_win_later(curwin, type); |
| 3184 | } |
| 3185 | |
| 3186 | void |
| 3187 | redraw_win_later( |
| 3188 | win_T *wp, |
| 3189 | int type) |
| 3190 | { |
Bram Moolenaar | 471c0fa | 2022-08-22 15:19:16 +0100 | [diff] [blame] | 3191 | if (!exiting && !redraw_not_allowed && wp->w_redr_type < type) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3192 | { |
| 3193 | wp->w_redr_type = type; |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 3194 | if (type >= UPD_NOT_VALID) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3195 | wp->w_lines_valid = 0; |
| 3196 | if (must_redraw < type) // must_redraw is the maximum of all windows |
| 3197 | must_redraw = type; |
| 3198 | } |
| 3199 | } |
| 3200 | |
| 3201 | /* |
| 3202 | * Force a complete redraw later. Also resets the highlighting. To be used |
| 3203 | * after executing a shell command that messes up the screen. |
| 3204 | */ |
| 3205 | void |
| 3206 | redraw_later_clear(void) |
| 3207 | { |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 3208 | redraw_all_later(UPD_CLEAR); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3209 | reset_screen_attr(); |
| 3210 | } |
| 3211 | |
| 3212 | /* |
Bram Moolenaar | 13608d8 | 2022-08-29 15:06:50 +0100 | [diff] [blame] | 3213 | * Mark all windows to be redrawn later. Except popup windows. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3214 | */ |
| 3215 | void |
| 3216 | redraw_all_later(int type) |
| 3217 | { |
| 3218 | win_T *wp; |
| 3219 | |
| 3220 | FOR_ALL_WINDOWS(wp) |
| 3221 | redraw_win_later(wp, type); |
| 3222 | // This may be needed when switching tabs. |
Bram Moolenaar | 471c0fa | 2022-08-22 15:19:16 +0100 | [diff] [blame] | 3223 | set_must_redraw(type); |
| 3224 | } |
| 3225 | |
Bram Moolenaar | 13608d8 | 2022-08-29 15:06:50 +0100 | [diff] [blame] | 3226 | #if 0 // not actually used yet, it probably should |
| 3227 | /* |
| 3228 | * Mark all windows, including popup windows, to be redrawn. |
| 3229 | */ |
| 3230 | void |
| 3231 | redraw_all_windows_later(int type) |
| 3232 | { |
| 3233 | redraw_all_later(type); |
| 3234 | #ifdef FEAT_PROP_POPUP |
| 3235 | popup_redraw_all(); // redraw all popup windows |
| 3236 | #endif |
| 3237 | } |
| 3238 | #endif |
| 3239 | |
Bram Moolenaar | 471c0fa | 2022-08-22 15:19:16 +0100 | [diff] [blame] | 3240 | /* |
| 3241 | * Set "must_redraw" to "type" unless it already has a higher value |
| 3242 | * or it is currently not allowed. |
| 3243 | */ |
| 3244 | void |
| 3245 | set_must_redraw(int type) |
| 3246 | { |
| 3247 | if (!redraw_not_allowed && must_redraw < type) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3248 | must_redraw = type; |
| 3249 | } |
| 3250 | |
| 3251 | /* |
| 3252 | * Mark all windows that are editing the current buffer to be updated later. |
| 3253 | */ |
| 3254 | void |
| 3255 | redraw_curbuf_later(int type) |
| 3256 | { |
| 3257 | redraw_buf_later(curbuf, type); |
| 3258 | } |
| 3259 | |
| 3260 | void |
| 3261 | redraw_buf_later(buf_T *buf, int type) |
| 3262 | { |
| 3263 | win_T *wp; |
| 3264 | |
| 3265 | FOR_ALL_WINDOWS(wp) |
| 3266 | { |
| 3267 | if (wp->w_buffer == buf) |
| 3268 | redraw_win_later(wp, type); |
| 3269 | } |
Bram Moolenaar | e52e0c8 | 2020-02-28 22:20:10 +0100 | [diff] [blame] | 3270 | #if defined(FEAT_TERMINAL) && defined(FEAT_PROP_POPUP) |
| 3271 | // terminal in popup window is not in list of windows |
| 3272 | if (curwin->w_buffer == buf) |
| 3273 | redraw_win_later(curwin, type); |
| 3274 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3275 | } |
| 3276 | |
| 3277 | #if defined(FEAT_SIGNS) || defined(PROTO) |
| 3278 | void |
| 3279 | redraw_buf_line_later(buf_T *buf, linenr_T lnum) |
| 3280 | { |
| 3281 | win_T *wp; |
| 3282 | |
| 3283 | FOR_ALL_WINDOWS(wp) |
| 3284 | if (wp->w_buffer == buf && lnum >= wp->w_topline |
| 3285 | && lnum < wp->w_botline) |
| 3286 | redrawWinline(wp, lnum); |
| 3287 | } |
| 3288 | #endif |
| 3289 | |
| 3290 | #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) |
| 3291 | void |
| 3292 | redraw_buf_and_status_later(buf_T *buf, int type) |
| 3293 | { |
| 3294 | win_T *wp; |
| 3295 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3296 | if (wild_menu_showing != 0) |
| 3297 | // Don't redraw while the command line completion is displayed, it |
| 3298 | // would disappear. |
| 3299 | return; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3300 | FOR_ALL_WINDOWS(wp) |
| 3301 | { |
| 3302 | if (wp->w_buffer == buf) |
| 3303 | { |
| 3304 | redraw_win_later(wp, type); |
| 3305 | wp->w_redr_status = TRUE; |
| 3306 | } |
| 3307 | } |
| 3308 | } |
| 3309 | #endif |
| 3310 | |
| 3311 | /* |
| 3312 | * mark all status lines for redraw; used after first :cd |
| 3313 | */ |
| 3314 | void |
| 3315 | status_redraw_all(void) |
| 3316 | { |
| 3317 | win_T *wp; |
| 3318 | |
| 3319 | FOR_ALL_WINDOWS(wp) |
| 3320 | if (wp->w_status_height) |
| 3321 | { |
| 3322 | wp->w_redr_status = TRUE; |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 3323 | redraw_later(UPD_VALID); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3324 | } |
| 3325 | } |
| 3326 | |
| 3327 | /* |
| 3328 | * mark all status lines of the current buffer for redraw |
| 3329 | */ |
| 3330 | void |
| 3331 | status_redraw_curbuf(void) |
| 3332 | { |
| 3333 | win_T *wp; |
| 3334 | |
| 3335 | FOR_ALL_WINDOWS(wp) |
| 3336 | if (wp->w_status_height != 0 && wp->w_buffer == curbuf) |
| 3337 | { |
| 3338 | wp->w_redr_status = TRUE; |
Bram Moolenaar | a4d158b | 2022-08-14 14:17:45 +0100 | [diff] [blame] | 3339 | redraw_later(UPD_VALID); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3340 | } |
| 3341 | } |
| 3342 | |
| 3343 | /* |
| 3344 | * Redraw all status lines that need to be redrawn. |
| 3345 | */ |
| 3346 | void |
| 3347 | redraw_statuslines(void) |
| 3348 | { |
| 3349 | win_T *wp; |
| 3350 | |
| 3351 | FOR_ALL_WINDOWS(wp) |
| 3352 | if (wp->w_redr_status) |
| 3353 | win_redr_status(wp, FALSE); |
| 3354 | if (redraw_tabline) |
| 3355 | draw_tabline(); |
Naruhiko Nishino | be5bd4d | 2025-05-14 21:20:28 +0200 | [diff] [blame] | 3356 | |
| 3357 | #if defined(FEAT_TABPANEL) |
| 3358 | if (redraw_tabpanel) |
| 3359 | draw_tabpanel(); |
| 3360 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3361 | } |
| 3362 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3363 | /* |
| 3364 | * Redraw all status lines at the bottom of frame "frp". |
| 3365 | */ |
| 3366 | void |
| 3367 | win_redraw_last_status(frame_T *frp) |
| 3368 | { |
| 3369 | if (frp->fr_layout == FR_LEAF) |
| 3370 | frp->fr_win->w_redr_status = TRUE; |
| 3371 | else if (frp->fr_layout == FR_ROW) |
| 3372 | { |
| 3373 | FOR_ALL_FRAMES(frp, frp->fr_child) |
| 3374 | win_redraw_last_status(frp); |
| 3375 | } |
| 3376 | else // frp->fr_layout == FR_COL |
| 3377 | { |
| 3378 | frp = frp->fr_child; |
| 3379 | while (frp->fr_next != NULL) |
| 3380 | frp = frp->fr_next; |
| 3381 | win_redraw_last_status(frp); |
| 3382 | } |
| 3383 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3384 | |
| 3385 | /* |
| 3386 | * Changed something in the current window, at buffer line "lnum", that |
| 3387 | * requires that line and possibly other lines to be redrawn. |
| 3388 | * Used when entering/leaving Insert mode with the cursor on a folded line. |
| 3389 | * Used to remove the "$" from a change command. |
| 3390 | * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot |
| 3391 | * may become invalid and the whole window will have to be redrawn. |
| 3392 | */ |
| 3393 | void |
| 3394 | redrawWinline( |
| 3395 | win_T *wp, |
| 3396 | linenr_T lnum) |
| 3397 | { |
Luuk van Baal | 7bbb0f3 | 2025-02-22 09:19:04 +0100 | [diff] [blame] | 3398 | redraw_win_range_later(wp, lnum, lnum); |
| 3399 | } |
| 3400 | |
| 3401 | void |
| 3402 | redraw_win_range_later( |
| 3403 | win_T *wp, |
| 3404 | linenr_T first, |
| 3405 | linenr_T last) |
| 3406 | { |
| 3407 | if (last >= wp->w_topline && first < wp->w_botline) |
| 3408 | { |
| 3409 | if (wp->w_redraw_top == 0 || wp->w_redraw_top > first) |
| 3410 | wp->w_redraw_top = first; |
| 3411 | if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < last) |
| 3412 | wp->w_redraw_bot = last; |
| 3413 | redraw_win_later(wp, UPD_VALID); |
| 3414 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3415 | } |