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