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