diff options
Diffstat (limited to 'src/nvim/screen.c')
-rw-r--r-- | src/nvim/screen.c | 258 |
1 files changed, 163 insertions, 95 deletions
diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 095c020fe4..5151d82c1b 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -2082,7 +2082,10 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int change_start = MAXCOL; // first col of changed area int change_end = -1; // last col of changed area colnr_T trailcol = MAXCOL; // start of trailing spaces + colnr_T leadcol = 0; // start of leading spaces bool need_showbreak = false; // overlong line, skip first x chars + sign_attrs_T sattrs[SIGN_SHOW_MAX]; // attributes for signs + int num_signs; // number of signs for line int line_attr = 0; // attribute for the whole line int line_attr_lowprio = 0; // low-priority attribute for the line matchitem_T *cur; // points to the match list @@ -2098,6 +2101,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool search_attr_from_match = false; // if search_attr is from :match bool has_decor = false; // this buffer has decoration bool do_virttext = false; // draw virtual text for this line + int win_col_offset; // offsett for window columns char_u buf_fold[FOLD_TEXT_LEN + 1]; // Hold value returned by get_foldtext @@ -2322,7 +2326,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); } // do at least one character; happens when past end of line - if (fromcol == tocol) { + if (fromcol == tocol && search_match_endcol) { tocol = fromcol + 1; } area_highlighting = true; @@ -2374,11 +2378,14 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, wp->w_last_cursorline = wp->w_cursor.lnum; } + memset(sattrs, 0, sizeof(sattrs)); + num_signs = buf_get_signattrs(wp->w_buffer, lnum, sattrs); + // If this line has a sign with line highlighting set line_attr. // TODO(bfredl, vigoux): this should not take priority over decoration! - v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL, 0, 1); - if (v != 0) { - line_attr = sign_get_attr((int)v, SIGN_LINEHL); + sign_attrs_T * sattr = sign_get_attr(SIGN_LINEHL, sattrs, 0, 1); + if (sattr != NULL) { + line_attr = sattr->sat_linehl; } // Highlight the current line in the quickfix window. @@ -2427,6 +2434,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, if (wp->w_p_list && !has_fold) { if (wp->w_p_lcs_chars.space || wp->w_p_lcs_chars.trail + || wp->w_p_lcs_chars.lead || wp->w_p_lcs_chars.nbsp) { extra_check = true; } @@ -2438,6 +2446,20 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, } trailcol += (colnr_T) (ptr - line); } + // find end of leading whitespace + if (wp->w_p_lcs_chars.lead) { + leadcol = 0; + while (ascii_iswhite(ptr[leadcol])) { + leadcol++; + } + if (ptr[leadcol] == NUL) { + // in a line full of spaces all of them are treated as trailing + leadcol = (colnr_T)0; + } else { + // keep track of the first column not filled with spaces + leadcol += (colnr_T)(ptr - line) + 1; + } + } } /* @@ -2680,7 +2702,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int count = win_signcol_count(wp); if (count > 0) { get_sign_display_info( - false, wp, lnum, row, + false, wp, sattrs, row, startrow, filler_lines, filler_todo, count, &c_extra, &c_final, extra, sizeof(extra), &p_extra, &n_extra, @@ -2699,10 +2721,10 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, // in 'lnum', then display the sign instead of the line // number. if (*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u' - && buf_findsign_id(wp->w_buffer, lnum, (char_u *)"*") != 0) { + && num_signs > 0) { int count = win_signcol_count(wp); get_sign_display_info( - true, wp, lnum, row, + true, wp, sattrs, row, startrow, filler_lines, filler_todo, count, &c_extra, &c_final, extra, sizeof(extra), &p_extra, &n_extra, @@ -2752,11 +2774,10 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, n_extra = number_width(wp) + 1; char_attr = win_hl_attr(wp, HLF_N); - int num_sign = buf_getsigntype( - wp->w_buffer, lnum, SIGN_NUMHL, 0, 1); - if (num_sign != 0) { + sign_attrs_T *num_sattr = sign_get_attr(SIGN_NUMHL, sattrs, 0, 1); + if (num_sattr != NULL) { // :sign defined with "numhl" highlight. - char_attr = sign_get_attr(num_sign, SIGN_NUMHL); + char_attr = num_sattr->sat_numhl; } else if ((wp->w_p_cul || wp->w_p_rnu) && lnum == wp->w_cursor.lnum && filler_todo == 0) { @@ -2770,6 +2791,10 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, } } + if (draw_state == WL_NR && n_extra == 0) { + win_col_offset = off; + } + if (wp->w_briopt_sbr && draw_state == WL_BRI - 1 && n_extra == 0 && *p_sbr != NUL) { // draw indent after showbreak value @@ -2884,7 +2909,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, && vcol >= (long)wp->w_virtcol) || (number_only && draw_state > WL_NR)) && filler_todo <= 0) { - draw_virt_text(buf, &col, grid->Columns); + draw_virt_text(buf, win_col_offset, &col, grid->Columns); grid_put_linebuf(grid, row, 0, col, -grid->Columns, wp->w_p_rl, wp, wp->w_hl_attr_normal, false); // Pretend we have finished updating the window. Except when @@ -3138,6 +3163,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, mb_utf8 = false; } } else { + assert(p_extra != NULL); c = *p_extra; mb_c = c; // If the UTF-8 character is more than one byte: @@ -3441,8 +3467,8 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, // TODO: is passing p for start of the line OK? n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol, NULL) - 1; if (c == TAB && n_extra + col > grid->Columns) { - n_extra = (int)wp->w_buffer->b_p_ts - - vcol % (int)wp->w_buffer->b_p_ts - 1; + n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts, + wp->w_buffer->b_p_vts_array) - 1; } c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' '; c_final = NUL; @@ -3462,6 +3488,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, || (mb_utf8 && (mb_c == 160 || mb_c == 0x202f))) && curwin->w_p_lcs_chars.nbsp) || (c == ' ' && curwin->w_p_lcs_chars.space + && ptr - line >= leadcol && ptr - line <= trailcol))) { c = (c == ' ') ? wp->w_p_lcs_chars.space : wp->w_p_lcs_chars.nbsp; n_attr = 1; @@ -3477,8 +3504,10 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, } } - if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') { - c = wp->w_p_lcs_chars.trail; + if ((trailcol != MAXCOL && ptr > line + trailcol && c == ' ') + || (leadcol != 0 && ptr < line + leadcol && c == ' ')) { + c = (ptr > line + trailcol) ? wp->w_p_lcs_chars.trail + : wp->w_p_lcs_chars.lead; n_attr = 1; extra_attr = win_hl_attr(wp, HLF_0); saved_attr2 = char_attr; // save current attr @@ -3508,8 +3537,9 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, vcol_adjusted = vcol - MB_CHARLEN(p_sbr); } // tab amount depends on current column - tab_len = (int)wp->w_buffer->b_p_ts - - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1; + tab_len = tabstop_padding(vcol_adjusted, + wp->w_buffer->b_p_ts, + wp->w_buffer->b_p_vts_array) - 1; if (!wp->w_p_lbr || !wp->w_p_list) { n_extra = tab_len; @@ -3542,6 +3572,10 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, xfree(p_extra_free); p_extra_free = p; for (i = 0; i < tab_len; i++) { + if (*p == NUL) { + tab_len = i; + break; + } int lcs = wp->w_p_lcs_chars.tab2; // if tab3 is given, need to change the char @@ -3916,13 +3950,15 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, draw_color_col = advance_color_col(VCOL_HLC, &color_cols); VirtText virt_text = KV_INITIAL_VALUE; + bool has_aligned = false; if (err_text) { int hl_err = syn_check_group((char_u *)S_LEN("ErrorMsg")); kv_push(virt_text, ((VirtTextChunk){ .text = err_text, .hl_id = hl_err })); do_virttext = true; } else if (has_decor) { - virt_text = decor_redraw_virt_text(wp->w_buffer, &decor_state); + virt_text = decor_redraw_eol(wp->w_buffer, &decor_state, &line_attr, + &has_aligned); if (kv_size(virt_text)) { do_virttext = true; } @@ -3934,7 +3970,8 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, grid->Columns * (row - startrow + 1) + v && lnum != wp->w_cursor.lnum) || draw_color_col || line_attr_lowprio || line_attr - || diff_hlf != (hlf_T)0 || do_virttext)) { + || diff_hlf != (hlf_T)0 || do_virttext + || has_aligned)) { int rightmost_vcol = 0; int i; @@ -3972,7 +4009,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, } int base_attr = hl_combine_attr(line_attr_lowprio, diff_attr); - if (base_attr || line_attr) { + if (base_attr || line_attr || has_aligned) { rightmost_vcol = INT_MAX; } @@ -4050,7 +4087,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, } } - draw_virt_text(buf, &col, grid->Columns); + draw_virt_text(buf, win_col_offset, &col, grid->Columns); grid_put_linebuf(grid, row, 0, col, grid->Columns, wp->w_p_rl, wp, wp->w_hl_attr_normal, false); row++; @@ -4271,7 +4308,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, && !wp->w_p_rl; // Not right-to-left. int draw_col = col - boguscols; - draw_virt_text(buf, &draw_col, grid->Columns); + draw_virt_text(buf, win_col_offset, &draw_col, grid->Columns); grid_put_linebuf(grid, row, 0, draw_col, grid->Columns, wp->w_p_rl, wp, wp->w_hl_attr_normal, wrap); if (wrap) { @@ -4348,51 +4385,62 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, return row; } -void draw_virt_text(buf_T *buf, int *end_col, int max_col) +void draw_virt_text(buf_T *buf, int col_off, int *end_col, int max_col) { DecorState *state = &decor_state; + int right_pos = max_col; for (size_t i = 0; i < kv_size(state->active); i++) { - HlRange *item = &kv_A(state->active, i); - if (item->start_row == state->row && kv_size(item->virt_text) - && item->virt_text_pos == kVTOverlay - && item->virt_col >= 0) { - VirtText vt = item->virt_text; - LineState s = LINE_STATE(""); - int virt_attr = 0; - int col = item->virt_col; - size_t virt_pos = 0; - item->virt_col = -2; // deactivate + DecorRange *item = &kv_A(state->active, i); + if (item->start_row == state->row && kv_size(item->decor.virt_text)) { + if (item->win_col == -1) { + if (item->decor.virt_text_pos == kVTRightAlign) { + right_pos -= item->decor.col; + item->win_col = right_pos; + } else if (item->decor.virt_text_pos == kVTWinCol) { + item->win_col = MAX(item->decor.col+col_off, 0); + } + } + if (item->win_col < 0) { + continue; + } + VirtText vt = item->decor.virt_text; + HlMode hl_mode = item->decor.hl_mode; + LineState s = LINE_STATE(""); + int virt_attr = 0; + int col = item->win_col; + size_t virt_pos = 0; + item->win_col = -2; // deactivate - while (col < max_col) { - if (!*s.p) { - if (virt_pos == kv_size(vt)) { - break; - } - s.p = kv_A(vt, virt_pos).text; - int hl_id = kv_A(vt, virt_pos).hl_id; - virt_attr = hl_id > 0 ? syn_id2attr(hl_id) : 0; - virt_pos++; - continue; - } - int attr; - bool through = false; - if (item->hl_mode == kHlModeCombine) { - attr = hl_combine_attr(linebuf_attr[col], virt_attr); - } else if (item->hl_mode == kHlModeBlend) { - through = (*s.p == ' '); - attr = hl_blend_attrs(linebuf_attr[col], virt_attr, &through); - } else { - attr = virt_attr; + while (col < max_col) { + if (!*s.p) { + if (virt_pos == kv_size(vt)) { + break; } - schar_T dummy[2]; - int cells = line_putchar(&s, through ? dummy : &linebuf_char[col], - max_col-col, false); + s.p = kv_A(vt, virt_pos).text; + int hl_id = kv_A(vt, virt_pos).hl_id; + virt_attr = hl_id > 0 ? syn_id2attr(hl_id) : 0; + virt_pos++; + continue; + } + int attr; + bool through = false; + if (hl_mode == kHlModeCombine) { + attr = hl_combine_attr(linebuf_attr[col], virt_attr); + } else if (hl_mode == kHlModeBlend) { + through = (*s.p == ' '); + attr = hl_blend_attrs(linebuf_attr[col], virt_attr, &through); + } else { + attr = virt_attr; + } + schar_T dummy[2]; + int cells = line_putchar(&s, through ? dummy : &linebuf_char[col], + max_col-col, false); + linebuf_attr[col++] = attr; + if (cells > 1) { linebuf_attr[col++] = attr; - if (cells > 1) { - linebuf_attr[col++] = attr; - } } - *end_col = MAX(*end_col, col); + } + *end_col = MAX(*end_col, col); } } } @@ -4426,7 +4474,7 @@ void screen_adjust_grid(ScreenGrid **grid, int *row_off, int *col_off) static void get_sign_display_info( bool nrcol, win_T *wp, - linenr_T lnum, + sign_attrs_T sattrs[], int row, int startrow, int filler_lines, @@ -4443,8 +4491,6 @@ static void get_sign_display_info( int *sign_idxp ) { - int text_sign; - // Draw cells with the sign value or blank. *c_extrap = ' '; *c_finalp = NUL; @@ -4456,10 +4502,9 @@ static void get_sign_display_info( } if (row == startrow + filler_lines && filler_todo <= 0) { - text_sign = buf_getsigntype(wp->w_buffer, lnum, SIGN_TEXT, - *sign_idxp, count); - if (text_sign != 0) { - *pp_extra = sign_get_text(text_sign); + sign_attrs_T *sattr = sign_get_attr(SIGN_TEXT, sattrs, *sign_idxp, count); + if (sattr != NULL) { + *pp_extra = sattr->sat_text; if (*pp_extra != NULL) { *c_extrap = NUL; *c_finalp = NUL; @@ -4492,7 +4537,7 @@ static void get_sign_display_info( (*pp_extra)[*n_extrap] = NUL; } } - *char_attrp = sign_get_attr(text_sign, SIGN_TEXT); + *char_attrp = sattr->sat_texthl; } } @@ -5428,32 +5473,50 @@ static void win_redr_border(win_T *wp) schar_T *chars = wp->w_float_config.border_chars; int *attrs = wp->w_float_config.border_attr; - int endrow = grid->Rows-1, endcol = grid->Columns-1; - grid_puts_line_start(grid, 0); - grid_put_schar(grid, 0, 0, chars[0], attrs[0]); - for (int i = 1; i < endcol; i++) { - grid_put_schar(grid, 0, i, chars[1], attrs[1]); - } - grid_put_schar(grid, 0, endcol, chars[2], attrs[2]); - grid_puts_line_flush(false); + int *adj = wp->w_border_adj; + int irow = wp->w_height_inner, icol = wp->w_width_inner; - for (int i = 1; i < endrow; i++) { - grid_puts_line_start(grid, i); - grid_put_schar(grid, i, 0, chars[7], attrs[7]); - grid_puts_line_flush(false); - grid_puts_line_start(grid, i); - grid_put_schar(grid, i, endcol, chars[3], attrs[3]); + if (adj[0]) { + grid_puts_line_start(grid, 0); + if (adj[3]) { + grid_put_schar(grid, 0, 0, chars[0], attrs[0]); + } + for (int i = 0; i < icol; i++) { + grid_put_schar(grid, 0, i+adj[3], chars[1], attrs[1]); + } + if (adj[1]) { + grid_put_schar(grid, 0, icol+adj[3], chars[2], attrs[2]); + } grid_puts_line_flush(false); } - grid_puts_line_start(grid, endrow); - grid_put_schar(grid, endrow, 0, chars[6], attrs[6]); - for (int i = 1; i < endcol; i++) { - grid_put_schar(grid, endrow, i, chars[5], attrs[5]); + for (int i = 0; i < irow; i++) { + if (adj[3]) { + grid_puts_line_start(grid, i+adj[0]); + grid_put_schar(grid, i+adj[0], 0, chars[7], attrs[7]); + grid_puts_line_flush(false); + } + if (adj[1]) { + int ic = (i == 0 && !adj[0] && chars[2][0]) ? 2 : 3; + grid_puts_line_start(grid, i+adj[0]); + grid_put_schar(grid, i+adj[0], icol+adj[3], chars[ic], attrs[ic]); + grid_puts_line_flush(false); + } + } + + if (adj[2]) { + grid_puts_line_start(grid, irow+adj[0]); + if (adj[3]) { + grid_put_schar(grid, irow+adj[0], 0, chars[6], attrs[6]); + } + for (int i = 0; i < icol; i++) { + int ic = (i == 0 && !adj[3] && chars[6][0]) ? 6 : 5; + grid_put_schar(grid, irow+adj[0], i+adj[3], chars[ic], attrs[ic]); + } + grid_put_schar(grid, irow+adj[0], icol+adj[3], chars[4], attrs[4]); + grid_puts_line_flush(false); } - grid_put_schar(grid, endrow, endcol, chars[4], attrs[4]); - grid_puts_line_flush(false); } // Low-level functions to manipulate invidual character cells on the @@ -6182,7 +6245,7 @@ void check_for_delay(int check_msg_scroll) && !did_wait_return && emsg_silent == 0) { ui_flush(); - os_delay(1000L, true); + os_delay(1006L, true); emsg_on_display = false; if (check_msg_scroll) { msg_scroll = false; @@ -6221,7 +6284,7 @@ void win_grid_alloc(win_T *wp) grid_alloc(grid_allocated, total_rows, total_cols, wp->w_grid_alloc.valid, false); grid_allocated->valid = true; - if (wp->w_border_adj) { + if (wp->w_floating && wp->w_float_config.border) { wp->w_redr_border = true; } was_resized = true; @@ -6241,8 +6304,8 @@ void win_grid_alloc(win_T *wp) if (want_allocation) { grid->target = grid_allocated; - grid->row_offset = wp->w_border_adj; - grid->col_offset = wp->w_border_adj; + grid->row_offset = wp->w_border_adj[0]; + grid->col_offset = wp->w_border_adj[3]; } else { grid->target = &default_grid; grid->row_offset = wp->w_winrow; @@ -7483,6 +7546,10 @@ void screen_resize(int width, int height) Rows = height; Columns = width; check_shellsize(); + int max_p_ch = Rows - min_rows() + 1; + if (!ui_has(kUIMessages) && p_ch > max_p_ch) { + p_ch = max_p_ch ? max_p_ch : 1; + } height = Rows; width = Columns; p_lines = Rows; @@ -7585,8 +7652,9 @@ void win_new_shellsize(void) static long old_Columns = 0; if (old_Rows != Rows) { - // if 'window' uses the whole screen, keep it using that */ - if (p_window == old_Rows - 1 || old_Rows == 0) { + // If 'window' uses the whole screen, keep it using that. + // Don't change it when set with "-w size" on the command line. + if (p_window == old_Rows - 1 || (old_Rows == 0 && p_window == 0)) { p_window = Rows - 1; } old_Rows = Rows; |