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