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