From 27177e581902967dcf4f2f426464da1b636ca420 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 14:14:24 +0100 Subject: refactor: reduce scope of locals as per the style guide (#22211) --- src/nvim/grid.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 46f8a59710..8815ac726a 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -204,15 +204,11 @@ void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, int len = textlen; int c; size_t max_off; - int mbyte_blen = 1; - int mbyte_cells = 1; - int u8c = 0; int u8cc[MAX_MCO]; bool clear_next_cell = false; int prev_c = 0; // previous Arabic character int pc, nc, nc1; int pcc[MAX_MCO]; - int need_redraw; bool do_flush = false; grid_adjust(&grid, &row, &col); @@ -249,13 +245,13 @@ void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, && *ptr != NUL) { c = (unsigned char)(*ptr); // check if this is the first byte of a multibyte - mbyte_blen = len > 0 + int mbyte_blen = len > 0 ? utfc_ptr2len_len(ptr, (int)((text + len) - ptr)) : utfc_ptr2len(ptr); - u8c = len >= 0 + int u8c = len >= 0 ? utfc_ptr2char_len(ptr, u8cc, (int)((text + len) - ptr)) : utfc_ptr2char(ptr, u8cc); - mbyte_cells = utf_char2cells(u8c); + int mbyte_cells = utf_char2cells(u8c); if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) { // Do Arabic shaping. if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) { @@ -287,11 +283,11 @@ void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, schar_T buf; schar_from_cc(buf, u8c, u8cc); - need_redraw = schar_cmp(grid->chars[off], buf) - || (mbyte_cells == 2 && grid->chars[off + 1][0] != 0) - || grid->attrs[off] != attr - || exmode_active - || rdb_flags & RDB_NODELTA; + int need_redraw = schar_cmp(grid->chars[off], buf) + || (mbyte_cells == 2 && grid->chars[off + 1][0] != 0) + || grid->attrs[off] != attr + || exmode_active + || rdb_flags & RDB_NODELTA; if (need_redraw) { // When at the end of the text and overwriting a two-cell @@ -497,7 +493,6 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle size_t max_off_from; size_t max_off_to; int col = 0; - bool redraw_this; // Does character need redraw? bool redraw_next; // redraw_this for next character bool clear_next = false; int char_cells; // 1: normal char @@ -559,7 +554,7 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle if (col + 1 < endcol) { char_cells = line_off2cells(linebuf_char, off_from, max_off_from); } - redraw_this = redraw_next; + bool redraw_this = redraw_next; // Does character need redraw? redraw_next = grid_char_needs_redraw(grid, off_from + (size_t)char_cells, off_to + (size_t)char_cells, endcol - col - char_cells); -- cgit From 5f72ab77bff1f1224be5cbbf9423bdddbc25635c Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 12 Feb 2023 18:48:49 +0100 Subject: refactor: reduce scope of locals as per the style guide 3 (#22221) refactor: reduce scope of locals as per the style guide --- src/nvim/grid.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 8815ac726a..16ebbfbb90 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -805,7 +805,6 @@ void grid_assign_handle(ScreenGrid *grid) /// 'row', 'col' and 'end' are relative to the start of the region. void grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end, int col, int width) { - int i; int j; unsigned temp; @@ -820,7 +819,7 @@ void grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end, int col, // Shift line_offset[] line_count down to reflect the inserted lines. // Clear the inserted lines. - for (i = 0; i < line_count; i++) { + for (int i = 0; i < line_count; i++) { if (width != grid->cols) { // need to copy part of a line j = end - 1 - i; @@ -855,7 +854,6 @@ void grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end, int col, void grid_del_lines(ScreenGrid *grid, int row, int line_count, int end, int col, int width) { int j; - int i; unsigned temp; int row_off = 0; @@ -869,7 +867,7 @@ void grid_del_lines(ScreenGrid *grid, int row, int line_count, int end, int col, // Now shift line_offset[] line_count up to reflect the deleted lines. // Clear the inserted lines. - for (i = 0; i < line_count; i++) { + for (int i = 0; i < line_count; i++) { if (width != grid->cols) { // need to copy part of a line j = row + i; -- cgit From 39f8aaeb815c2e31cffec12ef36ad4f25df91602 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Fri, 24 Jan 2020 09:48:58 +0100 Subject: fix(status): handle unprintable chars in the statusline --- src/nvim/grid.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 16ebbfbb90..efbeac4f3f 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -158,9 +158,9 @@ void grid_getbytes(ScreenGrid *grid, int row, int col, char *bytes, int *attrp) /// attributes 'attr', and update chars[] and attrs[]. /// Note: only outputs within one row, message is truncated at grid boundary! /// Note: if grid, row and/or col is invalid, nothing is done. -void grid_puts(ScreenGrid *grid, char *text, int row, int col, int attr) +int grid_puts(ScreenGrid *grid, char *text, int row, int col, int attr) { - grid_puts_len(grid, text, -1, row, col, attr); + return grid_puts_len(grid, text, -1, row, col, attr); } static ScreenGrid *put_dirty_grid = NULL; @@ -197,7 +197,7 @@ void grid_put_schar(ScreenGrid *grid, int row, int col, char *schar, int attr) /// like grid_puts(), but output "text[len]". When "len" is -1 output up to /// a NUL. -void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, int attr) +int grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, int attr) { size_t off; char *ptr = text; @@ -218,7 +218,7 @@ void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, if (grid->chars == NULL || row >= grid->rows || row < 0 || col >= grid->cols || col < 0) { - return; + return 0; } if (put_dirty_row == -1) { @@ -230,6 +230,7 @@ void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, } } off = grid->line_offset[row] + (size_t)col; + int start_col = col; // When drawing over the right half of a double-wide char clear out the // left half. Only needed in a terminal. @@ -252,6 +253,12 @@ void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, ? utfc_ptr2char_len(ptr, u8cc, (int)((text + len) - ptr)) : utfc_ptr2char(ptr, u8cc); int mbyte_cells = utf_char2cells(u8c); + if (mbyte_cells > 2) { + mbyte_cells = 1; + u8c = 0xFFFD; + u8cc[0] = 0; + } + if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) { // Do Arabic shaping. if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) { @@ -336,6 +343,7 @@ void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, if (do_flush) { grid_puts_line_flush(true); } + return col - start_col; } /// End a group of grid_puts_len calls and send the screen buffer to the UI -- cgit From 172227a44642b67ec8af5b438e5373a3daf61fdb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 12 Mar 2023 12:10:27 +0800 Subject: fix(screen): correctly draw background and eob with 'rightleft' (#22640) --- src/nvim/grid.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index efbeac4f3f..f20a9a847d 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -550,8 +550,7 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle if (bg_attr) { for (int c = col; c < endcol; c++) { - linebuf_attr[off_from + (size_t)c] = - hl_combine_attr(bg_attr, linebuf_attr[off_from + (size_t)c]); + linebuf_attr[c] = hl_combine_attr(bg_attr, linebuf_attr[c]); } } -- cgit From 314f20a44fdfdc382b0ce9d124290d3e7d702d42 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 12 Mar 2023 15:41:39 +0800 Subject: test: use a wider screen in the rightleft winhl test (#22641) With a wide screen this actually previously caused an overflow. --- src/nvim/grid.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index f20a9a847d..cd70e98047 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -549,6 +549,7 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle } if (bg_attr) { + assert(off_from == (size_t)col); for (int c = col; c < endcol; c++) { linebuf_attr[c] = hl_combine_attr(bg_attr, linebuf_attr[c]); } -- cgit From d5f6176e6dc4b4e12fc5061ca6e87f4af533e46a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Sat, 1 Apr 2023 02:49:51 +0200 Subject: refactor: add const and remove unnecessary casts (#22841) --- src/nvim/grid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index cd70e98047..3c4b1e9d70 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -197,10 +197,10 @@ void grid_put_schar(ScreenGrid *grid, int row, int col, char *schar, int attr) /// like grid_puts(), but output "text[len]". When "len" is -1 output up to /// a NUL. -int grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, int attr) +int grid_puts_len(ScreenGrid *grid, const char *text, int textlen, int row, int col, int attr) { size_t off; - char *ptr = text; + const char *ptr = text; int len = textlen; int c; size_t max_off; -- cgit From 7190dba017e3aac0409c73ff1c954d18858cb3c9 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Thu, 6 Apr 2023 22:39:50 +0200 Subject: refactor: remove use of reserved c++ keywords libnvim couldn't be easily used in C++ due to the use of reserved keywords. Additionally, add explicit casts to *alloc function calls used in inline functions, as C++ doesn't allow implicit casts from void pointers. --- src/nvim/grid.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 3c4b1e9d70..7745daf69a 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -657,22 +657,22 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle void grid_alloc(ScreenGrid *grid, int rows, int columns, bool copy, bool valid) { int new_row; - ScreenGrid new = *grid; + ScreenGrid ngrid = *grid; assert(rows >= 0 && columns >= 0); size_t ncells = (size_t)rows * (size_t)columns; - new.chars = xmalloc(ncells * sizeof(schar_T)); - new.attrs = xmalloc(ncells * sizeof(sattr_T)); - new.line_offset = xmalloc((size_t)rows * sizeof(*new.line_offset)); - new.line_wraps = xmalloc((size_t)rows * sizeof(*new.line_wraps)); + ngrid.chars = xmalloc(ncells * sizeof(schar_T)); + ngrid.attrs = xmalloc(ncells * sizeof(sattr_T)); + ngrid.line_offset = xmalloc((size_t)rows * sizeof(*ngrid.line_offset)); + ngrid.line_wraps = xmalloc((size_t)rows * sizeof(*ngrid.line_wraps)); - new.rows = rows; - new.cols = columns; + ngrid.rows = rows; + ngrid.cols = columns; - for (new_row = 0; new_row < new.rows; new_row++) { - new.line_offset[new_row] = (size_t)new_row * (size_t)new.cols; - new.line_wraps[new_row] = false; + for (new_row = 0; new_row < ngrid.rows; new_row++) { + ngrid.line_offset[new_row] = (size_t)new_row * (size_t)ngrid.cols; + ngrid.line_wraps[new_row] = false; - grid_clear_line(&new, new.line_offset[new_row], columns, valid); + grid_clear_line(&ngrid, ngrid.line_offset[new_row], columns, valid); if (copy) { // If the screen is not going to be cleared, copy as much as @@ -680,18 +680,18 @@ void grid_alloc(ScreenGrid *grid, int rows, int columns, bool copy, bool valid) // (used when resizing the window at the "--more--" prompt or when // executing an external command, for the GUI). if (new_row < grid->rows && grid->chars != NULL) { - int len = MIN(grid->cols, new.cols); - memmove(new.chars + new.line_offset[new_row], + int len = MIN(grid->cols, ngrid.cols); + memmove(ngrid.chars + ngrid.line_offset[new_row], grid->chars + grid->line_offset[new_row], (size_t)len * sizeof(schar_T)); - memmove(new.attrs + new.line_offset[new_row], + memmove(ngrid.attrs + ngrid.line_offset[new_row], grid->attrs + grid->line_offset[new_row], (size_t)len * sizeof(sattr_T)); } } } grid_free(grid); - *grid = new; + *grid = ngrid; // Share a single scratch buffer for all grids, by // ensuring it is as wide as the widest grid. -- cgit From a43b28a34c568eb3e280e75a81424f80f0ed980b Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Wed, 26 Apr 2023 13:11:33 +0200 Subject: vim-patch:9.0.0649: no indication the first line is broken for 'smoothscroll' Problem: No indication when the first line is broken for 'smoothscroll'. Solution: Show "<<<" in the first line. https://github.com/vim/vim/commit/406b5d89e18742ac6e6256ffc72fb70a27f0148b Co-authored-by: Bram Moolenaar --- src/nvim/grid.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 7745daf69a..2c548e11f1 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -503,6 +503,7 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle int col = 0; bool redraw_next; // redraw_this for next character bool clear_next = false; + bool topline = row == 0; int char_cells; // 1: normal char // 2: occupies two display cells int start_dirty = -1, end_dirty = 0; @@ -529,6 +530,14 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle max_off_from = linebuf_size; max_off_to = grid->line_offset[row] + (size_t)grid->cols; + if (topline && wp->w_skipcol > 0) { + // Take care of putting "<<<" on the first line for 'smoothscroll'. + for (int i = 0; i < 3; i++) { + schar_from_ascii(linebuf_char[i], '<'); + linebuf_attr[i] = HL_ATTR(HLF_AT); + } + } + if (rlflag) { // Clear rest first, because it's left of the text. if (clear_width > 0) { -- cgit From 2918720addd3837abcf06f457e8e2cf674ece5e7 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Wed, 26 Apr 2023 20:30:39 +0200 Subject: vim-patch:9.0.0681: "<<<" shows for 'smoothscroll' even when 'showbreak is set Problem: "<<<" shows for 'smoothscroll' even when 'showbreak is set. Solution: When 'showbreak' is set do not display "<<<". https://github.com/vim/vim/commit/0937b9fb244949b7ce9bfcf8398d7495b9b6aa85 Co-authored-by: Bram Moolenaar --- src/nvim/grid.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 2c548e11f1..0ceaeaa8b2 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -22,7 +22,7 @@ #include "nvim/highlight.h" #include "nvim/log.h" #include "nvim/message.h" -#include "nvim/option_defs.h" +#include "nvim/option.h" #include "nvim/types.h" #include "nvim/ui.h" #include "nvim/vim.h" @@ -530,8 +530,9 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle max_off_from = linebuf_size; max_off_to = grid->line_offset[row] + (size_t)grid->cols; - if (topline && wp->w_skipcol > 0) { - // Take care of putting "<<<" on the first line for 'smoothscroll'. + if (topline && wp->w_skipcol > 0 && *get_showbreak_value(wp) == NUL) { + // Take care of putting "<<<" on the first line for 'smoothscroll' + // when 'showbreak' is not set. for (int i = 0; i < 3; i++) { schar_from_ascii(linebuf_char[i], '<'); linebuf_attr[i] = HL_ATTR(HLF_AT); -- cgit From 6146400605af93ac48dae4393569c44e8a2e39d2 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Thu, 27 Apr 2023 00:57:48 +0200 Subject: vim-patch:9.0.0757: line number not visisble with 'smoothscroll', 'nu' and 'rnu' Problem: Line number not visisble with 'smoothscroll', 'nu' and 'rnu'. Solution: Put the ">>>" after the line number instead of on top. https://github.com/vim/vim/commit/eb4de629315f2682d8b314462d02422ec98d751a Co-authored-by: Bram Moolenaar --- src/nvim/grid.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 0ceaeaa8b2..8431c078b9 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -533,9 +533,21 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle if (topline && wp->w_skipcol > 0 && *get_showbreak_value(wp) == NUL) { // Take care of putting "<<<" on the first line for 'smoothscroll' // when 'showbreak' is not set. - for (int i = 0; i < 3; i++) { - schar_from_ascii(linebuf_char[i], '<'); - linebuf_attr[i] = HL_ATTR(HLF_AT); + int off = 0; + int skip = 0; + if (wp->w_p_nu && wp->w_p_rnu) { + // do not overwrite the line number, change "123 text" to + // "123>>>xt". + while (skip < wp->w_width && ascii_isdigit(*linebuf_char[off])) { + off++; + skip++; + } + } + + for (int i = 0; i < 3 && i + skip < wp->w_width; i++) { + schar_from_ascii(linebuf_char[off], '<'); + linebuf_attr[off] = HL_ATTR(HLF_AT); + off++; } } -- cgit From 72c525d5675bc017fa52bcc74a394db7d01e6359 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Thu, 27 Apr 2023 02:54:51 +0200 Subject: vim-patch:9.0.0758: "precedes" from 'listchars' overwritten by <<< Problem: "precedes" from 'listchars' overwritten by <<< for 'smoothscroll'. Solution: Keep the "precedes" character. https://github.com/vim/vim/commit/13cdde39520220bb856cba16626327c706752b51 Co-authored-by: Bram Moolenaar --- src/nvim/grid.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 8431c078b9..9e830413bd 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -530,9 +530,12 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle max_off_from = linebuf_size; max_off_to = grid->line_offset[row] + (size_t)grid->cols; - if (topline && wp->w_skipcol > 0 && *get_showbreak_value(wp) == NUL) { - // Take care of putting "<<<" on the first line for 'smoothscroll' - // when 'showbreak' is not set. + // Take care of putting "<<<" on the first line for 'smoothscroll'. + if (topline && wp->w_skipcol > 0 + // do not overwrite the 'showbreak' text with "<<<" + && *get_showbreak_value(wp) == NUL + // do not overwrite the 'listchars' "precedes" text with "<<<" + && !(wp->w_p_list && wp->w_p_lcs_chars.prec != 0)) { int off = 0; int skip = 0; if (wp->w_p_nu && wp->w_p_rnu) { -- cgit From 5b111a8f00f8dbe458a3d437c9f06c9419d24840 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Tue, 2 May 2023 12:00:42 +0200 Subject: fix(ui): adjust 'smoothscroll' for inner dimensions --- src/nvim/grid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 9e830413bd..037606c38f 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -541,13 +541,13 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle if (wp->w_p_nu && wp->w_p_rnu) { // do not overwrite the line number, change "123 text" to // "123>>>xt". - while (skip < wp->w_width && ascii_isdigit(*linebuf_char[off])) { + while (skip < wp->w_width_inner && ascii_isdigit(*linebuf_char[off])) { off++; skip++; } } - for (int i = 0; i < 3 && i + skip < wp->w_width; i++) { + for (int i = 0; i < 3 && i + skip < wp->w_width_inner; i++) { schar_from_ascii(linebuf_char[off], '<'); linebuf_attr[off] = HL_ATTR(HLF_AT); off++; -- cgit From cb34d0ddd086141d6afcb9c48eae180abbeffecc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 22 May 2023 18:22:47 +0800 Subject: fix(redraw): overwrite double-width char with virt_text properly (#23708) --- src/nvim/grid.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 037606c38f..76dd2a073a 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -316,8 +316,7 @@ int grid_puts_len(ScreenGrid *grid, const char *text, int textlen, int row, int // When at the start of the text and overwriting the right half of a // two-cell character in the same grid, truncate that into a '>'. if (ptr == text && col > 0 && grid->chars[off][0] == 0) { - grid->chars[off - 1][0] = '>'; - grid->chars[off - 1][1] = 0; + schar_from_ascii(grid->chars[off - 1], '>'); } schar_copy(grid->chars[off], buf); -- cgit From a0375b68c1803e7453071a20b28249020abe7260 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 2 Jun 2023 04:31:17 +0800 Subject: vim-patch:9.0.1598: screenchar() and others are wrong with DBCS 'encoding' (#23872) Problem: screenchar(), screenchars() and screenstring() do not work properly when 'encoding' is set to a double-byte encoding. Solution: Fix the way the bytes of the characters are obtained. (issue vim/vim#12469) https://github.com/vim/vim/commit/47eec6716b8621fd43bac8ecc9c19089df26705e --- src/nvim/grid.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 76dd2a073a..aa542c5a2f 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -138,8 +138,9 @@ void grid_putchar(ScreenGrid *grid, int c, int row, int col, int attr) grid_puts(grid, buf, row, col, attr); } -/// get a single character directly from grid.chars into "bytes[]". -/// Also return its attribute in *attrp; +/// Get a single character directly from grid.chars into "bytes", which must +/// have a size of "MB_MAXBYTES + 1". +/// If "attrp" is not NULL, return the character's attribute in "*attrp". void grid_getbytes(ScreenGrid *grid, int row, int col, char *bytes, int *attrp) { grid_adjust(&grid, &row, &col); @@ -150,7 +151,9 @@ void grid_getbytes(ScreenGrid *grid, int row, int col, char *bytes, int *attrp) } size_t off = grid->line_offset[row] + (size_t)col; - *attrp = grid->attrs[off]; + if (attrp != NULL) { + *attrp = grid->attrs[off]; + } schar_copy(bytes, grid->chars[off]); } -- cgit From 53f30de2becded95f9113b75367a9dd7563c183e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 4 Jun 2023 07:39:05 +0800 Subject: vim-patch:9.0.1602: stray character visible if marker on top of double-wide char (#23897) Problem: Stray character is visible if 'smoothscroll' marker is displayed on top of a double-wide character. Solution: When overwriting a double-width character with the 'smoothscroll' marker clear the second half. (closes vim/vim#12469) https://github.com/vim/vim/commit/ecb87dd7d3f7b9291092a7dd8fae1e59b9903252 --- src/nvim/grid.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index aa542c5a2f..f2ceb2ac24 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -500,8 +500,6 @@ static int grid_char_needs_redraw(ScreenGrid *grid, size_t off_from, size_t off_ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int clear_width, int rlflag, win_T *wp, int bg_attr, bool wrap) { - size_t max_off_from; - size_t max_off_to; int col = 0; bool redraw_next; // redraw_this for next character bool clear_next = false; @@ -519,6 +517,7 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle endcol = grid->cols; } + const size_t max_off_from = (size_t)grid->cols; grid_adjust(&grid, &row, &coloff); // Safety check. Avoids clang warnings down the call stack. @@ -529,8 +528,7 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle size_t off_from = 0; size_t off_to = grid->line_offset[row] + (size_t)coloff; - max_off_from = linebuf_size; - max_off_to = grid->line_offset[row] + (size_t)grid->cols; + const size_t max_off_to = grid->line_offset[row] + (size_t)grid->cols; // Take care of putting "<<<" on the first line for 'smoothscroll'. if (topline && wp->w_skipcol > 0 @@ -538,18 +536,23 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle && *get_showbreak_value(wp) == NUL // do not overwrite the 'listchars' "precedes" text with "<<<" && !(wp->w_p_list && wp->w_p_lcs_chars.prec != 0)) { - int off = 0; - int skip = 0; + size_t off = 0; + size_t skip = 0; if (wp->w_p_nu && wp->w_p_rnu) { // do not overwrite the line number, change "123 text" to // "123>>>xt". - while (skip < wp->w_width_inner && ascii_isdigit(*linebuf_char[off])) { + while (skip < max_off_from && ascii_isdigit(*linebuf_char[off])) { off++; skip++; } } - for (int i = 0; i < 3 && i + skip < wp->w_width_inner; i++) { + for (size_t i = 0; i < 3 && i + skip < max_off_from; i++) { + if (line_off2cells(linebuf_char, off, max_off_from) > 1) { + // When the first half of a double-width character is + // overwritten, change the second half to a space. + schar_from_ascii(linebuf_char[off + 1], ' '); + } schar_from_ascii(linebuf_char[off], '<'); linebuf_attr[off] = HL_ATTR(HLF_AT); off++; -- cgit From 2237b384e4027af7c977a4be01d792fcb790819c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 11 Jun 2023 11:29:39 +0800 Subject: vim-patch:9.0.1626: Visual area not shown when using 'showbreak' (#23978) Problem: Visual area not shown when using 'showbreak' and start of line is not visible. (Jaehwang Jung) Solution: Adjust "fromcol" for the space taken by 'showbreak'. (closes vim/vim#12514) https://github.com/vim/vim/commit/f578ca2c8f36b61ac3301fe8b59a8473c964cdc2 Co-authored-by: Bram Moolenaar --- src/nvim/grid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index f2ceb2ac24..11cd691f22 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -540,7 +540,7 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle size_t skip = 0; if (wp->w_p_nu && wp->w_p_rnu) { // do not overwrite the line number, change "123 text" to - // "123>>>xt". + // "123<< Date: Fri, 7 Jul 2023 09:49:58 +0800 Subject: fix(folds): fix missing virt_lines above when fold is hidden (#24274) --- src/nvim/grid.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 11cd691f22..aef10db414 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -508,11 +508,9 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle // 2: occupies two display cells int start_dirty = -1, end_dirty = 0; + assert(row < grid->rows); // TODO(bfredl): check all callsites and eliminate - // Check for illegal row and col, just in case - if (row >= grid->rows) { - row = grid->rows - 1; - } + // Check for illegal col, just in case if (endcol > grid->cols) { endcol = grid->cols; } -- cgit From 551998b7eed7dd411e4d14f65b108ae8a93c4081 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 18 Aug 2023 15:00:03 +0800 Subject: vim-patch:9.0.1725: cursor pos wrong after concealed text with 'virtualedit' Problem: Wrong cursor position when clicking after concealed text with 'virtualedit'. Solution: Store virtual columns in ScreenCols[] instead of text columns, and always use coladvance() when clicking. This also fixes incorrect curswant when clicking on a TAB, so now Test_normal_click_on_ctrl_char() asserts the same results as the ones before patch 9.0.0048. closes: vim/vim#12808 https://github.com/vim/vim/commit/e500ae8e29ad921378085f5d70ee5c0c537be1ba Remove the mouse_adjust_click() function. There is a difference in behavior with the old mouse_adjust_click() approach: when clicking on the character immediately after concealed text that is completely hidden, cursor is put on the clicked character rather than at the start of the concealed text. The new behavior is better, but it causes unnecessary scrolling in a functional test (which is an existing issue unrelated to these patches), so adjust the test. Now fully merged: vim-patch:9.0.0177: cursor position wrong with 'virtualedit' and mouse click --- src/nvim/grid.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index aef10db414..e25b1b1a73 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -78,6 +78,7 @@ void grid_clear_line(ScreenGrid *grid, size_t off, int width, bool valid) } int fill = valid ? 0 : -1; (void)memset(grid->attrs + off, fill, (size_t)width * sizeof(sattr_T)); + (void)memset(grid->vcols + off, -1, (size_t)width * sizeof(colnr_T)); } void grid_invalidate(ScreenGrid *grid) @@ -196,6 +197,7 @@ void grid_put_schar(ScreenGrid *grid, int row, int col, char *schar, int attr) // TODO(bfredl): Y U NO DOUBLEWIDTH? put_dirty_last = MAX(put_dirty_last, col + 1); } + grid->vcols[off] = -1; } /// like grid_puts(), but output "text[len]". When "len" is -1 output up to @@ -324,9 +326,11 @@ int grid_puts_len(ScreenGrid *grid, const char *text, int textlen, int row, int schar_copy(grid->chars[off], buf); grid->attrs[off] = attr; + grid->vcols[off] = -1; if (mbyte_cells == 2) { grid->chars[off + 1][0] = 0; grid->attrs[off + 1] = attr; + grid->vcols[off + 1] = -1; } put_dirty_first = MIN(put_dirty_first, col); put_dirty_last = MAX(put_dirty_last, col + mbyte_cells); @@ -437,6 +441,7 @@ void grid_fill(ScreenGrid *grid, int start_row, int end_row, int start_col, int } dirty_last = col + 1; } + grid->vcols[off] = -1; if (col == start_col) { schar_from_char(sc, c2); } @@ -620,13 +625,20 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle } grid->attrs[off_to] = linebuf_attr[off_from]; + grid->vcols[off_to] = linebuf_vcol[off_from]; // For simplicity set the attributes of second half of a // double-wide character equal to the first half. if (char_cells == 2) { grid->attrs[off_to + 1] = linebuf_attr[off_from]; + grid->vcols[off_to + 1] = linebuf_vcol[off_from + 1]; } } + grid->vcols[off_to] = linebuf_vcol[off_from]; + if (char_cells == 2) { + grid->vcols[off_to + 1] = linebuf_vcol[off_from]; + } + off_to += (size_t)char_cells; off_from += (size_t)char_cells; col += char_cells; @@ -659,6 +671,7 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle } clear_end = col + 1; } + grid->vcols[off_to] = MAXCOL; col++; off_to++; } @@ -690,6 +703,8 @@ void grid_alloc(ScreenGrid *grid, int rows, int columns, bool copy, bool valid) size_t ncells = (size_t)rows * (size_t)columns; ngrid.chars = xmalloc(ncells * sizeof(schar_T)); ngrid.attrs = xmalloc(ncells * sizeof(sattr_T)); + ngrid.vcols = xmalloc(ncells * sizeof(colnr_T)); + memset(ngrid.vcols, -1, ncells * sizeof(colnr_T)); ngrid.line_offset = xmalloc((size_t)rows * sizeof(*ngrid.line_offset)); ngrid.line_wraps = xmalloc((size_t)rows * sizeof(*ngrid.line_wraps)); @@ -715,6 +730,9 @@ void grid_alloc(ScreenGrid *grid, int rows, int columns, bool copy, bool valid) memmove(ngrid.attrs + ngrid.line_offset[new_row], grid->attrs + grid->line_offset[new_row], (size_t)len * sizeof(sattr_T)); + memmove(ngrid.vcols + ngrid.line_offset[new_row], + grid->vcols + grid->line_offset[new_row], + (size_t)len * sizeof(colnr_T)); } } } @@ -726,8 +744,10 @@ void grid_alloc(ScreenGrid *grid, int rows, int columns, bool copy, bool valid) if (linebuf_size < (size_t)columns) { xfree(linebuf_char); xfree(linebuf_attr); + xfree(linebuf_vcol); linebuf_char = xmalloc((size_t)columns * sizeof(schar_T)); linebuf_attr = xmalloc((size_t)columns * sizeof(sattr_T)); + linebuf_vcol = xmalloc((size_t)columns * sizeof(colnr_T)); linebuf_size = (size_t)columns; } } @@ -736,11 +756,13 @@ void grid_free(ScreenGrid *grid) { xfree(grid->chars); xfree(grid->attrs); + xfree(grid->vcols); xfree(grid->line_offset); xfree(grid->line_wraps); grid->chars = NULL; grid->attrs = NULL; + grid->vcols = NULL; grid->line_offset = NULL; grid->line_wraps = NULL; } @@ -751,6 +773,7 @@ void grid_free_all_mem(void) grid_free(&default_grid); xfree(linebuf_char); xfree(linebuf_attr); + xfree(linebuf_vcol); } /// (Re)allocates a window grid if size changed while in ext_multigrid mode. @@ -939,6 +962,7 @@ static void linecopy(ScreenGrid *grid, int to, int from, int col, int width) memmove(grid->chars + off_to, grid->chars + off_from, (size_t)width * sizeof(schar_T)); memmove(grid->attrs + off_to, grid->attrs + off_from, (size_t)width * sizeof(sattr_T)); + memmove(grid->vcols + off_to, grid->vcols + off_from, (size_t)width * sizeof(colnr_T)); } win_T *get_win_by_grid_handle(handle_T handle) -- cgit From f0e6e2ae463aa5f9c5e64e6fe01c1bab82131933 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 18 Aug 2023 21:00:58 +0800 Subject: refactor(grid.c): remove duplicate assignments They were removed from Vim in patch 9.0.0638. --- src/nvim/grid.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index e25b1b1a73..e6817cd8be 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -625,12 +625,10 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle } grid->attrs[off_to] = linebuf_attr[off_from]; - grid->vcols[off_to] = linebuf_vcol[off_from]; // For simplicity set the attributes of second half of a // double-wide character equal to the first half. if (char_cells == 2) { grid->attrs[off_to + 1] = linebuf_attr[off_from]; - grid->vcols[off_to + 1] = linebuf_vcol[off_from + 1]; } } -- cgit From c8e58bf09c4abc92c8689a80eb90150c5ff3cdfc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 19 Aug 2023 19:40:26 +0800 Subject: vim-patch:9.0.1742: wrong curswant when clicking on second cell of double-width char (#24789) Problem: Wrong curswant when clicking and the second cell of a double-width char. Solution: Don't copy virtcol of the first char to the second one. closes: vim/vim#12842 https://github.com/vim/vim/commit/9994160bfe74501886bbbf5631aec8ea2ae05991 --- src/nvim/grid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index e6817cd8be..fa7f270172 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -634,7 +634,7 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle grid->vcols[off_to] = linebuf_vcol[off_from]; if (char_cells == 2) { - grid->vcols[off_to + 1] = linebuf_vcol[off_from]; + grid->vcols[off_to + 1] = linebuf_vcol[off_from + 1]; } off_to += (size_t)char_cells; -- cgit From 8da986ea877b07a5eb117446f410f2a7fc8cd9cb Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 13 Sep 2023 13:39:18 +0200 Subject: refactor(grid): change schar_T representation to be more compact Previously, a screen cell would occupy 28+4=32 bytes per cell as we always made space for up to MAX_MCO+1 codepoints in a cell. As an example, even a pretty modest 50*80 screen would consume 50*80*2*32 = 256000, i e a quarter megabyte With the factor of two due to the TUI side buffer, and even more when using msg_grid and/or ext_multigrid. This instead stores a 4-byte union of either: - a valid UTF-8 sequence up to 4 bytes - an escape char which is invalid UTF-8 (0xFF) plus a 24-bit index to a glyph cache This avoids allocating space for huge composed glyphs _upfront_, while still keeping rendering such glyphs reasonably fast (1 hash table lookup + one plain index lookup). If the same large glyphs are using repeatedly on the screen, this is still a net reduction of memory/cache consumption. The only case which really gets worse is if you blast the screen full with crazy emojis and zalgo text and even this case only leads to 4 extra bytes per char. When only <= 4-byte glyphs are used, plus the 4-byte attribute code, i e 8 bytes in total there is a factor of four reduction of memory use. Memory which will be quite hot in cache as the screen buffer is scanned over in win_line() buffer text drawing A slight complication is that the representation depends on host byte order. I've tested this manually by compling and running this in qemu-s390x and it works fine. We might add a qemu based solution to CI at some point. --- src/nvim/grid.c | 178 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 140 insertions(+), 38 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index fa7f270172..cf6cd2f04e 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -17,6 +17,7 @@ #include "nvim/arabic.h" #include "nvim/buffer_defs.h" +#include "nvim/drawscreen.h" #include "nvim/globals.h" #include "nvim/grid.h" #include "nvim/highlight.h" @@ -36,6 +37,15 @@ // Per-cell attributes static size_t linebuf_size = 0; +// Used to cache glyphs which doesn't fit an a sizeof(schar_T) length UTF-8 string. +// Then it instead stores an index into glyph_cache.keys[] which is a flat char array. +// The hash part is used by schar_from_buf() to quickly lookup glyphs which already +// has been interned. schar_get() should used to convert a schar_T value +// back to a string buffer. +// +// The maximum byte size of a glyph is MAX_SCHAR_SIZE (including the final NUL). +static Set(glyph) glyph_cache = SET_INIT; + /// Determine if dedicated window grid should be used or the default_grid /// /// If UI did not request multigrid support, draw all windows on the @@ -56,25 +66,119 @@ void grid_adjust(ScreenGrid **grid, int *row_off, int *col_off) } /// Put a unicode char, and up to MAX_MCO composing chars, in a screen cell. -int schar_from_cc(char *p, int c, int u8cc[MAX_MCO]) +schar_T schar_from_cc(int c, int u8cc[MAX_MCO]) { - int len = utf_char2bytes(c, p); + char buf[MAX_SCHAR_SIZE]; + int len = utf_char2bytes(c, buf); for (int i = 0; i < MAX_MCO; i++) { if (u8cc[i] == 0) { break; } - len += utf_char2bytes(u8cc[i], p + len); + len += utf_char2bytes(u8cc[i], buf + len); + } + buf[len] = 0; + return schar_from_buf(buf, (size_t)len); +} + +schar_T schar_from_str(char *str) +{ + if (str == NULL) { + return 0; + } + return schar_from_buf(str, strlen(str)); +} + +/// @param buf need not be NUL terminated, but may not contain embedded NULs. +/// +/// caller must ensure len < MAX_SCHAR_SIZE (not =, as NUL needs a byte) +schar_T schar_from_buf(const char *buf, size_t len) +{ + assert(len < MAX_SCHAR_SIZE); + if (len <= 4) { + schar_T sc = 0; + memcpy((char *)&sc, buf, len); + return sc; + } else { + String str = { .data = (char *)buf, .size = len }; + + MHPutStatus status; + uint32_t idx = set_put_idx(glyph, &glyph_cache, str, &status); + assert(idx < 0xFFFFFF); +#ifdef ORDER_BIG_ENDIAN + return idx + ((uint32_t)0xFF << 24); +#else + return 0xFF + (idx << 8); +#endif + } +} + +/// Check if cache is full, and if it is, clear it. +/// +/// This should normally only be called in update_screen() +/// +/// @return true if cache was clered, and all your screen buffers now are hosed +/// and you need to use UPD_CLEAR +bool schar_cache_clear_if_full(void) +{ + // note: critical max is really (1<<24)-1. This gives us some marginal + // until next time update_screen() is called + if (glyph_cache.h.n_keys > (1<<21)) { + set_clear(glyph, &glyph_cache); + return true; + } + return false; +} + +/// For testing. The condition in schar_cache_clear_force is hard to +/// reach, so this function can be used to force a cache clear in a test. +void schar_cache_clear_force(void) +{ + set_clear(glyph, &glyph_cache); + must_redraw = UPD_CLEAR; +} + +bool schar_high(schar_T sc) +{ +#ifdef ORDER_BIG_ENDIAN + return ((sc & 0xFF000000) == 0xFF000000); +#else + return ((sc & 0xFF) == 0xFF); +#endif +} + +void schar_get(char *buf_out, schar_T sc) +{ + if (schar_high(sc)) { +#ifdef ORDER_BIG_ENDIAN + uint32_t idx = sc & (0x00FFFFFF); +#else + uint32_t idx = sc >> 8; +#endif + if (idx >= glyph_cache.h.n_keys) { + abort(); + } + xstrlcpy(buf_out, &glyph_cache.keys[idx], 32); + } else { + memcpy(buf_out, (char *)&sc, 4); + buf_out[4] = NUL; } - p[len] = 0; - return len; } +/// @return ascii char or NUL if not ascii +char schar_get_ascii(schar_T sc) +{ +#ifdef ORDER_BIG_ENDIAN + return (!(sc & 0x80FFFFFF)) ? *(char *)&sc : NUL; +#else + return (sc < 0x80) ? (char)sc : NUL; +#endif +} /// clear a line in the grid starting at "off" until "width" characters /// are cleared. void grid_clear_line(ScreenGrid *grid, size_t off, int width, bool valid) { for (int col = 0; col < width; col++) { - schar_from_ascii(grid->chars[off + (size_t)col], ' '); + grid->chars[off + (size_t)col] = schar_from_ascii(' '); } int fill = valid ? 0 : -1; (void)memset(grid->attrs + off, fill, (size_t)width * sizeof(sattr_T)); @@ -93,7 +197,7 @@ bool grid_invalid_row(ScreenGrid *grid, int row) static int line_off2cells(schar_T *line, size_t off, size_t max_off) { - return (off + 1 < max_off && line[off + 1][0] == 0) ? 2 : 1; + return (off + 1 < max_off && line[off + 1] == 0) ? 2 : 1; } /// Return number of display cells for char at grid->chars[off]. @@ -124,7 +228,7 @@ int grid_fix_col(ScreenGrid *grid, int col, int row) col += coloff; if (grid->chars != NULL && col > 0 - && grid->chars[grid->line_offset[row] + (size_t)col][0] == 0) { + && grid->chars[grid->line_offset[row] + (size_t)col] == 0) { return col - 1 - coloff; } return col - coloff; @@ -155,7 +259,7 @@ void grid_getbytes(ScreenGrid *grid, int row, int col, char *bytes, int *attrp) if (attrp != NULL) { *attrp = grid->attrs[off]; } - schar_copy(bytes, grid->chars[off]); + schar_get(bytes, grid->chars[off]); } /// put string '*text' on the window grid at position 'row' and 'col', with @@ -185,12 +289,12 @@ void grid_puts_line_start(ScreenGrid *grid, int row) put_dirty_grid = grid; } -void grid_put_schar(ScreenGrid *grid, int row, int col, char *schar, int attr) +void grid_put_schar(ScreenGrid *grid, int row, int col, schar_T schar, int attr) { assert(put_dirty_row == row); size_t off = grid->line_offset[row] + (size_t)col; - if (grid->attrs[off] != attr || schar_cmp(grid->chars[off], schar) || rdb_flags & RDB_NODELTA) { - schar_copy(grid->chars[off], schar); + if (grid->attrs[off] != attr || grid->chars[off] != schar || rdb_flags & RDB_NODELTA) { + grid->chars[off] = schar; grid->attrs[off] = attr; put_dirty_first = MIN(put_dirty_first, col); @@ -293,10 +397,12 @@ int grid_puts_len(ScreenGrid *grid, const char *text, int textlen, int row, int } schar_T buf; - schar_from_cc(buf, u8c, u8cc); + // TODO(bfredl): why not just keep the original byte sequence. arabshape is + // an edge case, treat it as such.. + buf = schar_from_cc(u8c, u8cc); - int need_redraw = schar_cmp(grid->chars[off], buf) - || (mbyte_cells == 2 && grid->chars[off + 1][0] != 0) + int need_redraw = grid->chars[off] != buf + || (mbyte_cells == 2 && grid->chars[off + 1] != 0) || grid->attrs[off] != attr || exmode_active || rdb_flags & RDB_NODELTA; @@ -320,15 +426,15 @@ int grid_puts_len(ScreenGrid *grid, const char *text, int textlen, int row, int // When at the start of the text and overwriting the right half of a // two-cell character in the same grid, truncate that into a '>'. - if (ptr == text && col > 0 && grid->chars[off][0] == 0) { - schar_from_ascii(grid->chars[off - 1], '>'); + if (ptr == text && col > 0 && grid->chars[off] == 0) { + grid->chars[off - 1] = schar_from_ascii('>'); } - schar_copy(grid->chars[off], buf); + grid->chars[off] = buf; grid->attrs[off] = attr; grid->vcols[off] = -1; if (mbyte_cells == 2) { - grid->chars[off + 1][0] = 0; + grid->chars[off + 1] = 0; grid->attrs[off + 1] = attr; grid->vcols[off + 1] = -1; } @@ -429,12 +535,12 @@ void grid_fill(ScreenGrid *grid, int start_row, int end_row, int start_col, int int dirty_last = 0; int col = start_col; - schar_from_char(sc, c1); + sc = schar_from_char(c1); size_t lineoff = grid->line_offset[row]; for (col = start_col; col < end_col; col++) { size_t off = lineoff + (size_t)col; - if (schar_cmp(grid->chars[off], sc) || grid->attrs[off] != attr || rdb_flags & RDB_NODELTA) { - schar_copy(grid->chars[off], sc); + if (grid->chars[off] != sc || grid->attrs[off] != attr || rdb_flags & RDB_NODELTA) { + grid->chars[off] = sc; grid->attrs[off] = attr; if (dirty_first == INT_MAX) { dirty_first = col; @@ -443,7 +549,7 @@ void grid_fill(ScreenGrid *grid, int start_row, int end_row, int start_col, int } grid->vcols[off] = -1; if (col == start_col) { - schar_from_char(sc, c2); + sc = schar_from_char(c2); } } if (dirty_last > dirty_first) { @@ -483,11 +589,10 @@ void grid_fill(ScreenGrid *grid, int start_row, int end_row, int start_col, int static int grid_char_needs_redraw(ScreenGrid *grid, size_t off_from, size_t off_to, int cols) { return (cols > 0 - && ((schar_cmp(linebuf_char[off_from], grid->chars[off_to]) + && ((linebuf_char[off_from] != grid->chars[off_to] || linebuf_attr[off_from] != grid->attrs[off_to] || (line_off2cells(linebuf_char, off_from, off_from + (size_t)cols) > 1 - && schar_cmp(linebuf_char[off_from + 1], - grid->chars[off_to + 1]))) + && linebuf_char[off_from + 1] != grid->chars[off_to + 1])) || rdb_flags & RDB_NODELTA)); } @@ -544,7 +649,7 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle if (wp->w_p_nu && wp->w_p_rnu) { // do not overwrite the line number, change "123 text" to // "123<< 1) { // When the first half of a double-width character is // overwritten, change the second half to a space. - schar_from_ascii(linebuf_char[off + 1], ' '); + linebuf_char[off + 1] = schar_from_ascii(' '); } - schar_from_ascii(linebuf_char[off], '<'); + linebuf_char[off] = schar_from_ascii('<'); linebuf_attr[off] = HL_ATTR(HLF_AT); off++; } @@ -565,8 +670,7 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle if (rlflag) { // Clear rest first, because it's left of the text. if (clear_width > 0) { - while (col <= endcol && grid->chars[off_to][0] == ' ' - && grid->chars[off_to][1] == NUL + while (col <= endcol && grid->chars[off_to] == schar_from_ascii(' ') && grid->attrs[off_to] == bg_attr) { off_to++; col++; @@ -619,9 +723,9 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle clear_next = true; } - schar_copy(grid->chars[off_to], linebuf_char[off_from]); + grid->chars[off_to] = linebuf_char[off_from]; if (char_cells == 2) { - schar_copy(grid->chars[off_to + 1], linebuf_char[off_from + 1]); + grid->chars[off_to + 1] = linebuf_char[off_from + 1]; } grid->attrs[off_to] = linebuf_attr[off_from]; @@ -645,7 +749,7 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle if (clear_next) { // Clear the second half of a double-wide character of which the left // half was overwritten with a single-wide character. - schar_from_ascii(grid->chars[off_to], ' '); + grid->chars[off_to] = schar_from_ascii(' '); end_dirty++; } @@ -654,12 +758,10 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle // blank out the rest of the line // TODO(bfredl): we could cache winline widths while (col < clear_width) { - if (grid->chars[off_to][0] != ' ' - || grid->chars[off_to][1] != NUL + if (grid->chars[off_to] != schar_from_ascii(' ') || grid->attrs[off_to] != bg_attr || rdb_flags & RDB_NODELTA) { - grid->chars[off_to][0] = ' '; - grid->chars[off_to][1] = NUL; + grid->chars[off_to] = schar_from_ascii(' '); grid->attrs[off_to] = bg_attr; if (start_dirty == -1) { start_dirty = col; -- cgit From ee20e9e66942ce38c8d4a8f4387ac1ec00d1d64f Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 20 Sep 2023 10:18:40 +0200 Subject: refactor(grid): unused grid->line_wraps delenda est This is not used as part of the logic to actually implement TUI line wrapping In vim (especially gvim) it is used to emulate terminal-style text selection. But in nvim we don't do that, and have no plans to reintroduce it. --- src/nvim/grid.c | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index cf6cd2f04e..dc42ab7a89 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -574,10 +574,6 @@ void grid_fill(ScreenGrid *grid, int start_row, int end_row, int start_col, int ui_line(grid, row, dirty_first, last, dirty_last, attr, false); } } - - if (end_col == grid->cols) { - grid->line_wraps[row] = false; - } } } @@ -777,12 +773,6 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle } } - if (clear_width > 0 || wp->w_width != grid->cols) { - // If we cleared after the end of the line, it did not wrap. - // For vsplit, line wrapping is not possible. - grid->line_wraps[row] = false; - } - if (clear_end < end_dirty) { clear_end = end_dirty; } @@ -806,14 +796,12 @@ void grid_alloc(ScreenGrid *grid, int rows, int columns, bool copy, bool valid) ngrid.vcols = xmalloc(ncells * sizeof(colnr_T)); memset(ngrid.vcols, -1, ncells * sizeof(colnr_T)); ngrid.line_offset = xmalloc((size_t)rows * sizeof(*ngrid.line_offset)); - ngrid.line_wraps = xmalloc((size_t)rows * sizeof(*ngrid.line_wraps)); ngrid.rows = rows; ngrid.cols = columns; for (new_row = 0; new_row < ngrid.rows; new_row++) { ngrid.line_offset[new_row] = (size_t)new_row * (size_t)ngrid.cols; - ngrid.line_wraps[new_row] = false; grid_clear_line(&ngrid, ngrid.line_offset[new_row], columns, valid); @@ -858,13 +846,11 @@ void grid_free(ScreenGrid *grid) xfree(grid->attrs); xfree(grid->vcols); xfree(grid->line_offset); - xfree(grid->line_wraps); grid->chars = NULL; grid->attrs = NULL; grid->vcols = NULL; grid->line_offset = NULL; - grid->line_wraps = NULL; } /// Doesn't allow reinit, so must only be called by free_all_mem! @@ -987,16 +973,13 @@ void grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end, int col, } j += line_count; grid_clear_line(grid, grid->line_offset[j] + (size_t)col, width, false); - grid->line_wraps[j] = false; } else { j = end - 1 - i; temp = (unsigned)grid->line_offset[j]; while ((j -= line_count) >= row) { grid->line_offset[j + line_count] = grid->line_offset[j]; - grid->line_wraps[j + line_count] = grid->line_wraps[j]; } grid->line_offset[j + line_count] = temp; - grid->line_wraps[j + line_count] = false; grid_clear_line(grid, temp, grid->cols, false); } } @@ -1035,17 +1018,14 @@ void grid_del_lines(ScreenGrid *grid, int row, int line_count, int end, int col, } j -= line_count; grid_clear_line(grid, grid->line_offset[j] + (size_t)col, width, false); - grid->line_wraps[j] = false; } else { // whole width, moving the line pointers is faster j = row + i; temp = (unsigned)grid->line_offset[j]; while ((j += line_count) <= end - 1) { grid->line_offset[j - line_count] = grid->line_offset[j]; - grid->line_wraps[j - line_count] = grid->line_wraps[j]; } grid->line_offset[j - line_count] = temp; - grid->line_wraps[j - line_count] = false; grid_clear_line(grid, temp, grid->cols, false); } } -- cgit From 3a7cb72dcbe4aaaed47999ab5afaf3d1cb8d4df8 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 20 Sep 2023 13:42:37 +0200 Subject: refactor(grid): properly namespace and separate stateful grid functions This is a step in an ongoing refactor where the "grid_puts" and "grid_put_linebuf" code paths will share more of the implementation (in particular for delta calculation, doublewidth and 'arabicshape' handling). But it also makes sense by its own as a cleanup, and is thus committed separately. Before this change many of the low level grid functions grid_puts, grid_fill etc could both be used in a standalone fashion but also as part of a batched line update which would be finally transmitted as a single grid_line call (via ui_line() ). This was initially useful to quickly refactor pre-existing vim code to use batched logic safely. However, this pattern is not really helpful for maintainable and newly written code, where the "grid" and "row" arguments are just needlessly repeated. This simplifies these calls to just use grid and row as specified in the initial grid_line_start(grid, row) call. This also makes the intent clear whether any grid_puts() call is actually part of a batch or not, which is better in the long run when more things get refactored to use effective (properly batched) updates. --- src/nvim/grid.c | 185 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 105 insertions(+), 80 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index dc42ab7a89..2eeefab27d 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -239,8 +239,7 @@ void grid_putchar(ScreenGrid *grid, int c, int row, int col, int attr) { char buf[MB_MAXBYTES + 1]; - buf[utf_char2bytes(c, buf)] = NUL; - grid_puts(grid, buf, row, col, attr); + grid_puts(grid, buf, utf_char2bytes(c, buf), row, col, attr); } /// Get a single character directly from grid.chars into "bytes", which must @@ -262,51 +261,81 @@ void grid_getbytes(ScreenGrid *grid, int row, int col, char *bytes, int *attrp) schar_get(bytes, grid->chars[off]); } -/// put string '*text' on the window grid at position 'row' and 'col', with -/// attributes 'attr', and update chars[] and attrs[]. -/// Note: only outputs within one row, message is truncated at grid boundary! -/// Note: if grid, row and/or col is invalid, nothing is done. -int grid_puts(ScreenGrid *grid, char *text, int row, int col, int attr) +static bool check_grid(ScreenGrid *grid, int row, int col) { - return grid_puts_len(grid, text, -1, row, col, attr); + grid_adjust(&grid, &row, &col); + // Safety check. The check for negative row and column is to fix issue + // vim/vim#4102. TODO(neovim): find out why row/col could be negative. + if (grid->chars == NULL + || row >= grid->rows || row < 0 + || col >= grid->cols || col < 0) { + return false; + } + return true; } -static ScreenGrid *put_dirty_grid = NULL; -static int put_dirty_row = -1; -static int put_dirty_first = INT_MAX; -static int put_dirty_last = 0; +/// put string 'text' on the window grid at position 'row' and 'col', with +/// attributes 'attr', and update contents of 'grid' +/// @param textlen length of string or -1 to use strlen(text) +/// Note: only outputs within one row! +int grid_puts(ScreenGrid *grid, const char *text, int textlen, int row, int col, int attr) +{ + if (!check_grid(grid, row, col)) { + if (rdb_flags & RDB_INVALID) { + abort(); + } + return 0; + } + + grid_line_start(grid, row); + int len = grid_line_puts(col, text, textlen, attr); + grid_line_flush(true); + return len; +} -/// Start a group of grid_puts_len calls that builds a single grid line. +static ScreenGrid *grid_line_grid = NULL; +static int grid_line_row = -1; +static int grid_line_coloff = 0; +static int grid_line_first = INT_MAX; +static int grid_line_last = 0; +static bool grid_line_was_invalid = false; + +/// Start a group of grid_line_puts calls that builds a single grid line. /// -/// Must be matched with a grid_puts_line_flush call before moving to +/// Must be matched with a grid_line_flush call before moving to /// another line. -void grid_puts_line_start(ScreenGrid *grid, int row) +void grid_line_start(ScreenGrid *grid, int row) { - int col = 0; // unused + int col = 0; grid_adjust(&grid, &row, &col); - assert(put_dirty_row == -1); - put_dirty_row = row; - put_dirty_grid = grid; + assert(grid_line_row == -1); + grid_line_row = row; + grid_line_grid = grid; + grid_line_coloff = col; + // TODO(bfredl): ugly hackaround, will be fixed in STAGE 2 + grid_line_was_invalid = grid != &default_grid && grid_invalid_row(grid, row); } -void grid_put_schar(ScreenGrid *grid, int row, int col, schar_T schar, int attr) +void grid_line_put_schar(int col, schar_T schar, int attr) { - assert(put_dirty_row == row); - size_t off = grid->line_offset[row] + (size_t)col; + assert(grid_line_row >= 0); + ScreenGrid *grid = grid_line_grid; + + size_t off = grid->line_offset[grid_line_row] + (size_t)col; if (grid->attrs[off] != attr || grid->chars[off] != schar || rdb_flags & RDB_NODELTA) { grid->chars[off] = schar; grid->attrs[off] = attr; - put_dirty_first = MIN(put_dirty_first, col); + grid_line_first = MIN(grid_line_first, col); // TODO(bfredl): Y U NO DOUBLEWIDTH? - put_dirty_last = MAX(put_dirty_last, col + 1); + grid_line_last = MAX(grid_line_last, col + 1); } grid->vcols[off] = -1; } /// like grid_puts(), but output "text[len]". When "len" is -1 output up to /// a NUL. -int grid_puts_len(ScreenGrid *grid, const char *text, int textlen, int row, int col, int attr) +int grid_line_puts(int col, const char *text, int textlen, int attr) { size_t off; const char *ptr = text; @@ -318,37 +347,15 @@ int grid_puts_len(ScreenGrid *grid, const char *text, int textlen, int row, int int prev_c = 0; // previous Arabic character int pc, nc, nc1; int pcc[MAX_MCO]; - bool do_flush = false; - grid_adjust(&grid, &row, &col); + assert(grid_line_row >= 0); + ScreenGrid *grid = grid_line_grid; + int row = grid_line_row; + col += grid_line_coloff; - // Safety check. The check for negative row and column is to fix issue - // vim/vim#4102. TODO(neovim): find out why row/col could be negative. - if (grid->chars == NULL - || row >= grid->rows || row < 0 - || col >= grid->cols || col < 0) { - return 0; - } - - if (put_dirty_row == -1) { - grid_puts_line_start(grid, row); - do_flush = true; - } else { - if (grid != put_dirty_grid || row != put_dirty_row) { - abort(); - } - } off = grid->line_offset[row] + (size_t)col; int start_col = col; - // When drawing over the right half of a double-wide char clear out the - // left half. Only needed in a terminal. - if (grid != &default_grid && col == 0 && grid_invalid_row(grid, row)) { - // redraw the previous cell, make it empty - put_dirty_first = -1; - put_dirty_last = MAX(put_dirty_last, 1); - } - max_off = grid->line_offset[row] + (size_t)grid->cols; while (col < grid->cols && (len < 0 || (int)(ptr - text) < len) @@ -438,8 +445,8 @@ int grid_puts_len(ScreenGrid *grid, const char *text, int textlen, int row, int grid->attrs[off + 1] = attr; grid->vcols[off + 1] = -1; } - put_dirty_first = MIN(put_dirty_first, col); - put_dirty_last = MAX(put_dirty_last, col + mbyte_cells); + grid_line_first = MIN(grid_line_first, col); + grid_line_last = MAX(grid_line_last, col + mbyte_cells); } off += (size_t)mbyte_cells; @@ -452,39 +459,61 @@ int grid_puts_len(ScreenGrid *grid, const char *text, int textlen, int row, int } } - if (do_flush) { - grid_puts_line_flush(true); - } return col - start_col; } -/// End a group of grid_puts_len calls and send the screen buffer to the UI -/// layer. +void grid_line_fill(int start_col, int end_col, int c, int attr) +{ + ScreenGrid *grid = grid_line_grid; + size_t lineoff = grid->line_offset[grid_line_row]; + start_col += grid_line_coloff; + end_col += grid_line_coloff; + + schar_T sc = schar_from_char(c); + for (int col = start_col; col < end_col; col++) { + size_t off = lineoff + (size_t)col; + if (grid->chars[off] != sc || grid->attrs[off] != attr || rdb_flags & RDB_NODELTA) { + grid->chars[off] = sc; + grid->attrs[off] = attr; + grid_line_first = MIN(grid_line_first, col); + grid_line_last = MAX(grid_line_last, col + 1); + } + grid->vcols[off] = -1; + } +} + +/// End a group of grid_line_puts calls and send the screen buffer to the UI layer. /// /// @param set_cursor Move the visible cursor to the end of the changed region. /// This is a workaround for not yet refactored code paths /// and shouldn't be used in new code. -void grid_puts_line_flush(bool set_cursor) +void grid_line_flush(bool set_cursor) { - assert(put_dirty_row != -1); - if (put_dirty_first < put_dirty_last) { + assert(grid_line_row != -1); + if (grid_line_first < grid_line_last) { + // When drawing over the right half of a double-wide char clear out the + // left half. Only needed in a terminal. + if (grid_line_was_invalid && grid_line_first == 0) { + // redraw the previous cell, make it empty + grid_line_first = -1; + } if (set_cursor) { - ui_grid_cursor_goto(put_dirty_grid->handle, put_dirty_row, - MIN(put_dirty_last, put_dirty_grid->cols - 1)); + ui_grid_cursor_goto(grid_line_grid->handle, grid_line_row, + MIN(grid_line_last, grid_line_grid->cols - 1)); } - if (!put_dirty_grid->throttled) { - ui_line(put_dirty_grid, put_dirty_row, put_dirty_first, put_dirty_last, - put_dirty_last, 0, false); - } else if (put_dirty_grid->dirty_col) { - if (put_dirty_last > put_dirty_grid->dirty_col[put_dirty_row]) { - put_dirty_grid->dirty_col[put_dirty_row] = put_dirty_last; + if (!grid_line_grid->throttled) { + ui_line(grid_line_grid, grid_line_row, grid_line_first, grid_line_last, + grid_line_last, 0, false); + } else if (grid_line_grid->dirty_col) { + if (grid_line_last > grid_line_grid->dirty_col[grid_line_row]) { + grid_line_grid->dirty_col[grid_line_row] = grid_line_last; } } - put_dirty_first = INT_MAX; - put_dirty_last = 0; + grid_line_first = INT_MAX; + grid_line_last = 0; } - put_dirty_row = -1; - put_dirty_grid = NULL; + grid_line_row = -1; + grid_line_grid = NULL; } /// Fill the grid from "start_row" to "end_row" (exclusive), from "start_col" @@ -521,11 +550,11 @@ void grid_fill(ScreenGrid *grid, int start_row, int end_row, int start_col, int // double wide-char clear out the right half. Only needed in a // terminal. if (start_col > 0 && grid_fix_col(grid, start_col, row) != start_col) { - grid_puts_len(grid, " ", 1, row, start_col - 1, 0); + grid_puts(grid, " ", 1, row, start_col - 1, 0); } if (end_col < grid->cols && grid_fix_col(grid, end_col, row) != end_col) { - grid_puts_len(grid, " ", 1, row, end_col, 0); + grid_puts(grid, " ", 1, row, end_col, 0); } // if grid was resized (in ext_multigrid mode), the UI has no redraw updates @@ -553,11 +582,7 @@ void grid_fill(ScreenGrid *grid, int start_row, int end_row, int start_col, int } } if (dirty_last > dirty_first) { - // TODO(bfredl): support a cleared suffix even with a batched line? - if (put_dirty_row == row) { - put_dirty_first = MIN(put_dirty_first, dirty_first); - put_dirty_last = MAX(put_dirty_last, dirty_last); - } else if (grid->throttled) { + if (grid->throttled) { // Note: assumes msg_grid is the only throttled grid assert(grid == &msg_grid); int dirty = 0; -- cgit From 10cabf787724871173a294f2fc1a5dbc62f2ee91 Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 26 Sep 2023 14:28:58 +0200 Subject: refactor(grid): use batched updates for statusline and ruler --- src/nvim/grid.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 2eeefab27d..da72054540 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -953,6 +953,7 @@ void win_grid_alloc(win_T *wp) if ((resizing_screen || was_resized) && want_allocation) { ui_call_grid_resize(grid_allocated->handle, grid_allocated->cols, grid_allocated->rows); + ui_check_cursor_grid(grid_allocated->handle); } } -- cgit From e33269578b5bea2528cc48afc5b009eb8d4ad1d6 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 20 Sep 2023 10:08:05 +0200 Subject: refactor(grid): unify the two put-text-on-the-screen code paths The screen grid refactors will continue until morale improves. Jokes aside, this is quite a central installment in the series. Before this refactor, there were two fundamentally distinct codepaths for getting some text on the screen: - the win_line() -> grid_put_linebuf() -> ui_line() call chain used for buffer text, with linebuf_char as a temporary scratch buffer - the grid_line_start/grid_line_puts/grid_line_flush() -> ui_line() path used for every thing else: statuslines, messages and the command line. Here the grid->chars[] array itself doubles as a scratch buffer. With this refactor, the later family of functions still exist, however they now as well render to linebuf_char just like win_line() did, and grid_put_linebuf() is called in the end to calculate delta changes. This means we don't need any duplicate logic for delta calculations anymore. Later down the line, it will be possible to share more logic operating on this scratch buffer, like doing 'rightleft' reversal and arabic shaping as a post-processing step. --- src/nvim/grid.c | 345 +++++++++++++++++++++----------------------------------- 1 file changed, 131 insertions(+), 214 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index da72054540..1d9cd80ec3 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -190,21 +190,16 @@ void grid_invalidate(ScreenGrid *grid) (void)memset(grid->attrs, -1, sizeof(sattr_T) * (size_t)grid->rows * (size_t)grid->cols); } -bool grid_invalid_row(ScreenGrid *grid, int row) +static bool grid_invalid_row(ScreenGrid *grid, int row) { return grid->attrs[grid->line_offset[row]] < 0; } -static int line_off2cells(schar_T *line, size_t off, size_t max_off) -{ - return (off + 1 < max_off && line[off + 1] == 0) ? 2 : 1; -} - /// Return number of display cells for char at grid->chars[off]. /// We make sure that the offset used is less than "max_off". static int grid_off2cells(ScreenGrid *grid, size_t off, size_t max_off) { - return line_off2cells(grid->chars, off, max_off); + return (off + 1 < max_off && grid->chars[off + 1] == 0) ? 2 : 1; } /// Return true if the character at "row"/"col" on the screen is the left side @@ -261,18 +256,12 @@ void grid_getbytes(ScreenGrid *grid, int row, int col, char *bytes, int *attrp) schar_get(bytes, grid->chars[off]); } -static bool check_grid(ScreenGrid *grid, int row, int col) -{ - grid_adjust(&grid, &row, &col); - // Safety check. The check for negative row and column is to fix issue - // vim/vim#4102. TODO(neovim): find out why row/col could be negative. - if (grid->chars == NULL - || row >= grid->rows || row < 0 - || col >= grid->cols || col < 0) { - return false; - } - return true; -} +static ScreenGrid *grid_line_grid = NULL; +static int grid_line_row = -1; +static int grid_line_coloff = 0; +static int grid_line_maxcol = 0; +static int grid_line_first = INT_MAX; +static int grid_line_last = 0; /// put string 'text' on the window grid at position 'row' and 'col', with /// attributes 'attr', and update contents of 'grid' @@ -280,26 +269,32 @@ static bool check_grid(ScreenGrid *grid, int row, int col) /// Note: only outputs within one row! int grid_puts(ScreenGrid *grid, const char *text, int textlen, int row, int col, int attr) { - if (!check_grid(grid, row, col)) { + grid_line_start(grid, row); + + // Safety check. The check for negative row and column is to fix issue + // vim/vim#4102. TODO(neovim): find out why row/col could be negative. + int off_col = grid_line_coloff + col; + if (grid_line_grid->chars == NULL + || grid_line_row >= grid_line_grid->rows || grid_line_row < 0 + || off_col >= grid_line_grid->cols || off_col < 0) { if (rdb_flags & RDB_INVALID) { abort(); + } else { + grid_line_grid = NULL; + return 0; } - return 0; } - grid_line_start(grid, row); int len = grid_line_puts(col, text, textlen, attr); - grid_line_flush(true); + if (grid_line_last > grid_line_first) { + // TODO(bfredl): this is bullshit. message.c should manage its own cursor movements + int col_pos = MIN(grid_line_coloff + grid_line_last, grid_line_grid->cols - 1); + ui_grid_cursor_goto(grid_line_grid->handle, grid_line_row, col_pos); + } + grid_line_flush(); return len; } -static ScreenGrid *grid_line_grid = NULL; -static int grid_line_row = -1; -static int grid_line_coloff = 0; -static int grid_line_first = INT_MAX; -static int grid_line_last = 0; -static bool grid_line_was_invalid = false; - /// Start a group of grid_line_puts calls that builds a single grid line. /// /// Must be matched with a grid_line_flush call before moving to @@ -308,56 +303,46 @@ void grid_line_start(ScreenGrid *grid, int row) { int col = 0; grid_adjust(&grid, &row, &col); - assert(grid_line_row == -1); + assert(grid_line_grid == NULL); grid_line_row = row; grid_line_grid = grid; grid_line_coloff = col; - // TODO(bfredl): ugly hackaround, will be fixed in STAGE 2 - grid_line_was_invalid = grid != &default_grid && grid_invalid_row(grid, row); + grid_line_first = (int)linebuf_size; + grid_line_maxcol = grid->cols - grid_line_coloff; + grid_line_last = 0; } void grid_line_put_schar(int col, schar_T schar, int attr) { - assert(grid_line_row >= 0); - ScreenGrid *grid = grid_line_grid; + assert(grid_line_grid); - size_t off = grid->line_offset[grid_line_row] + (size_t)col; - if (grid->attrs[off] != attr || grid->chars[off] != schar || rdb_flags & RDB_NODELTA) { - grid->chars[off] = schar; - grid->attrs[off] = attr; + linebuf_char[col] = schar; + linebuf_attr[col] = attr; - grid_line_first = MIN(grid_line_first, col); - // TODO(bfredl): Y U NO DOUBLEWIDTH? - grid_line_last = MAX(grid_line_last, col + 1); - } - grid->vcols[off] = -1; + grid_line_first = MIN(grid_line_first, col); + // TODO(bfredl): Y U NO DOUBLEWIDTH? + grid_line_last = MAX(grid_line_last, col + 1); + linebuf_vcol[col] = -1; } /// like grid_puts(), but output "text[len]". When "len" is -1 output up to /// a NUL. int grid_line_puts(int col, const char *text, int textlen, int attr) { - size_t off; const char *ptr = text; int len = textlen; int c; - size_t max_off; int u8cc[MAX_MCO]; - bool clear_next_cell = false; int prev_c = 0; // previous Arabic character int pc, nc, nc1; int pcc[MAX_MCO]; - assert(grid_line_row >= 0); - ScreenGrid *grid = grid_line_grid; - int row = grid_line_row; - col += grid_line_coloff; + assert(grid_line_grid); - off = grid->line_offset[row] + (size_t)col; int start_col = col; - max_off = grid->line_offset[row] + (size_t)grid->cols; - while (col < grid->cols + int max_col = grid_line_maxcol; + while (col < max_col && (len < 0 || (int)(ptr - text) < len) && *ptr != NUL) { c = (unsigned char)(*ptr); @@ -394,7 +379,7 @@ int grid_line_puts(int col, const char *text, int textlen, int attr) } else { prev_c = u8c; } - if (col + mbyte_cells > grid->cols) { + if (col + mbyte_cells > max_col) { // Only 1 cell left, but character requires 2 cells: // display a '>' in the last column to avoid wrapping. */ c = '>'; @@ -408,55 +393,29 @@ int grid_line_puts(int col, const char *text, int textlen, int attr) // an edge case, treat it as such.. buf = schar_from_cc(u8c, u8cc); - int need_redraw = grid->chars[off] != buf - || (mbyte_cells == 2 && grid->chars[off + 1] != 0) - || grid->attrs[off] != attr - || exmode_active - || rdb_flags & RDB_NODELTA; - - if (need_redraw) { - // When at the end of the text and overwriting a two-cell - // character with a one-cell character, need to clear the next - // cell. Also when overwriting the left half of a two-cell char - // with the right half of a two-cell char. Do this only once - // (utf8_off2cells() may return 2 on the right half). - if (clear_next_cell) { - clear_next_cell = false; - } else if ((len < 0 ? ptr[mbyte_blen] == NUL : ptr + mbyte_blen >= text + len) - && ((mbyte_cells == 1 - && grid_off2cells(grid, off, max_off) > 1) - || (mbyte_cells == 2 - && grid_off2cells(grid, off, max_off) == 1 - && grid_off2cells(grid, off + 1, max_off) > 1))) { - clear_next_cell = true; - } - - // When at the start of the text and overwriting the right half of a - // two-cell character in the same grid, truncate that into a '>'. - if (ptr == text && col > 0 && grid->chars[off] == 0) { - grid->chars[off - 1] = schar_from_ascii('>'); - } + // When at the start of the text and overwriting the right half of a + // two-cell character in the same grid, truncate that into a '>'. + if (ptr == text && col > grid_line_first && col < grid_line_last + && linebuf_char[col] == 0) { + linebuf_char[col - 1] = schar_from_ascii('>'); + } - grid->chars[off] = buf; - grid->attrs[off] = attr; - grid->vcols[off] = -1; - if (mbyte_cells == 2) { - grid->chars[off + 1] = 0; - grid->attrs[off + 1] = attr; - grid->vcols[off + 1] = -1; - } - grid_line_first = MIN(grid_line_first, col); - grid_line_last = MAX(grid_line_last, col + mbyte_cells); + linebuf_char[col] = buf; + linebuf_attr[col] = attr; + linebuf_vcol[col] = -1; + if (mbyte_cells == 2) { + linebuf_char[col + 1] = 0; + linebuf_attr[col + 1] = attr; + linebuf_vcol[col + 1] = -1; } - off += (size_t)mbyte_cells; col += mbyte_cells; ptr += mbyte_blen; - if (clear_next_cell) { - // This only happens at the end, display one space next. - ptr = " "; - len = -1; - } + } + + if (col > start_col) { + grid_line_first = MIN(grid_line_first, start_col); + grid_line_last = MAX(grid_line_last, col); } return col - start_col; @@ -464,56 +423,30 @@ int grid_line_puts(int col, const char *text, int textlen, int attr) void grid_line_fill(int start_col, int end_col, int c, int attr) { - ScreenGrid *grid = grid_line_grid; - size_t lineoff = grid->line_offset[grid_line_row]; - start_col += grid_line_coloff; - end_col += grid_line_coloff; - schar_T sc = schar_from_char(c); for (int col = start_col; col < end_col; col++) { - size_t off = lineoff + (size_t)col; - if (grid->chars[off] != sc || grid->attrs[off] != attr || rdb_flags & RDB_NODELTA) { - grid->chars[off] = sc; - grid->attrs[off] = attr; - grid_line_first = MIN(grid_line_first, col); - grid_line_last = MAX(grid_line_last, col + 1); - } - grid->vcols[off] = -1; + linebuf_char[col] = sc; + linebuf_attr[col] = attr; + linebuf_vcol[col] = -1; } + grid_line_first = MIN(grid_line_first, start_col); + grid_line_last = MAX(grid_line_last, end_col); } /// End a group of grid_line_puts calls and send the screen buffer to the UI layer. -/// -/// @param set_cursor Move the visible cursor to the end of the changed region. -/// This is a workaround for not yet refactored code paths -/// and shouldn't be used in new code. -void grid_line_flush(bool set_cursor) +void grid_line_flush(void) { - assert(grid_line_row != -1); - if (grid_line_first < grid_line_last) { - // When drawing over the right half of a double-wide char clear out the - // left half. Only needed in a terminal. - if (grid_line_was_invalid && grid_line_first == 0) { - // redraw the previous cell, make it empty - grid_line_first = -1; - } - if (set_cursor) { - ui_grid_cursor_goto(grid_line_grid->handle, grid_line_row, - MIN(grid_line_last, grid_line_grid->cols - 1)); - } - if (!grid_line_grid->throttled) { - ui_line(grid_line_grid, grid_line_row, grid_line_first, grid_line_last, - grid_line_last, 0, false); - } else if (grid_line_grid->dirty_col) { - if (grid_line_last > grid_line_grid->dirty_col[grid_line_row]) { - grid_line_grid->dirty_col[grid_line_row] = grid_line_last; - } - } - grid_line_first = INT_MAX; - grid_line_last = 0; - } - grid_line_row = -1; + ScreenGrid *grid = grid_line_grid; grid_line_grid = NULL; + if (!(grid_line_first < grid_line_last)) { + return; + } + + int row = grid_line_row; + + bool invalid_row = grid != &default_grid && grid_invalid_row(grid, row) && grid_line_first == 0; + grid_put_linebuf(grid, row, grid_line_coloff, grid_line_first, grid_line_last, grid_line_last, + false, 0, false, invalid_row); } /// Fill the grid from "start_row" to "end_row" (exclusive), from "start_col" @@ -607,13 +540,14 @@ void grid_fill(ScreenGrid *grid, int start_row, int end_row, int start_col, int /// - the attributes are different /// - the character is multi-byte and the next byte is different /// - the character is two cells wide and the second cell differs. -static int grid_char_needs_redraw(ScreenGrid *grid, size_t off_from, size_t off_to, int cols) +static int grid_char_needs_redraw(ScreenGrid *grid, int col, size_t off_to, int cols) { return (cols > 0 - && ((linebuf_char[off_from] != grid->chars[off_to] - || linebuf_attr[off_from] != grid->attrs[off_to] - || (line_off2cells(linebuf_char, off_from, off_from + (size_t)cols) > 1 - && linebuf_char[off_from + 1] != grid->chars[off_to + 1])) + && ((linebuf_char[col] != grid->chars[off_to] + || linebuf_attr[col] != grid->attrs[off_to] + || (cols > 1 && linebuf_char[col + 1] == 0 + && linebuf_char[col + 1] != grid->chars[off_to + 1])) + || exmode_active // TODO(bfredl): what in the actual fuck || rdb_flags & RDB_NODELTA)); } @@ -623,30 +557,27 @@ static int grid_char_needs_redraw(ScreenGrid *grid, size_t off_from, size_t off_ /// "endcol" gives the columns where valid characters are. /// "clear_width" is the width of the window. It's > 0 if the rest of the line /// needs to be cleared, negative otherwise. -/// "rlflag" is true in a rightleft window: +/// "rl" is true for rightleft text, like a window with 'rightleft' option set /// When true and "clear_width" > 0, clear columns 0 to "endcol" /// When false and "clear_width" > 0, clear columns "endcol" to "clear_width" /// If "wrap" is true, then hint to the UI that "row" contains a line /// which has wrapped into the next row. -void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int clear_width, - int rlflag, win_T *wp, int bg_attr, bool wrap) +void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int col, int endcol, int clear_width, + int rl, int bg_attr, bool wrap, bool invalid_row) { - int col = 0; bool redraw_next; // redraw_this for next character bool clear_next = false; - bool topline = row == 0; int char_cells; // 1: normal char // 2: occupies two display cells int start_dirty = -1, end_dirty = 0; - assert(row < grid->rows); + assert(0 <= row && row < grid->rows); // TODO(bfredl): check all callsites and eliminate // Check for illegal col, just in case if (endcol > grid->cols) { endcol = grid->cols; } - const size_t max_off_from = (size_t)grid->cols; grid_adjust(&grid, &row, &coloff); // Safety check. Avoids clang warnings down the call stack. @@ -655,45 +586,21 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle return; } - size_t off_from = 0; size_t off_to = grid->line_offset[row] + (size_t)coloff; const size_t max_off_to = grid->line_offset[row] + (size_t)grid->cols; - // Take care of putting "<<<" on the first line for 'smoothscroll'. - if (topline && wp->w_skipcol > 0 - // do not overwrite the 'showbreak' text with "<<<" - && *get_showbreak_value(wp) == NUL - // do not overwrite the 'listchars' "precedes" text with "<<<" - && !(wp->w_p_list && wp->w_p_lcs_chars.prec != 0)) { - size_t off = 0; - size_t skip = 0; - if (wp->w_p_nu && wp->w_p_rnu) { - // do not overwrite the line number, change "123 text" to - // "123<< 1) { - // When the first half of a double-width character is - // overwritten, change the second half to a space. - linebuf_char[off + 1] = schar_from_ascii(' '); - } - linebuf_char[off] = schar_from_ascii('<'); - linebuf_attr[off] = HL_ATTR(HLF_AT); - off++; - } + // When at the start of the text and overwriting the right half of a + // two-cell character in the same grid, truncate that into a '>'. + if (col > 0 && grid->chars[off_to + (size_t)col] == 0) { + linebuf_char[col - 1] = schar_from_ascii('>'); + col--; } - if (rlflag) { + if (rl) { // Clear rest first, because it's left of the text. if (clear_width > 0) { - while (col <= endcol && grid->chars[off_to] == schar_from_ascii(' ') - && grid->attrs[off_to] == bg_attr) { - off_to++; + while (col <= endcol && grid->chars[off_to + (size_t)col] == schar_from_ascii(' ') + && grid->attrs[off_to + (size_t)col] == bg_attr) { col++; } if (col <= endcol) { @@ -701,28 +608,26 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle } } col = endcol + 1; - off_to = grid->line_offset[row] + (size_t)col + (size_t)coloff; - off_from += (size_t)col; endcol = (clear_width > 0 ? clear_width : -clear_width); } if (bg_attr) { - assert(off_from == (size_t)col); for (int c = col; c < endcol; c++) { linebuf_attr[c] = hl_combine_attr(bg_attr, linebuf_attr[c]); } } - redraw_next = grid_char_needs_redraw(grid, off_from, off_to, endcol - col); + redraw_next = grid_char_needs_redraw(grid, col, (size_t)col + off_to, endcol - col); while (col < endcol) { char_cells = 1; - if (col + 1 < endcol) { - char_cells = line_off2cells(linebuf_char, off_from, max_off_from); + if (col + 1 < endcol && linebuf_char[col + 1] == 0) { + char_cells = 2; } bool redraw_this = redraw_next; // Does character need redraw? - redraw_next = grid_char_needs_redraw(grid, off_from + (size_t)char_cells, - off_to + (size_t)char_cells, + size_t off = (size_t)col + off_to; + redraw_next = grid_char_needs_redraw(grid, col + char_cells, + off + (size_t)char_cells, endcol - col - char_cells); if (redraw_this) { @@ -737,53 +642,52 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle // char over the left half of an existing one if (col + char_cells == endcol && ((char_cells == 1 - && grid_off2cells(grid, off_to, max_off_to) > 1) + && grid_off2cells(grid, off, max_off_to) > 1) || (char_cells == 2 - && grid_off2cells(grid, off_to, max_off_to) == 1 - && grid_off2cells(grid, off_to + 1, max_off_to) > 1))) { + && grid_off2cells(grid, off, max_off_to) == 1 + && grid_off2cells(grid, off + 1, max_off_to) > 1))) { clear_next = true; } - grid->chars[off_to] = linebuf_char[off_from]; + grid->chars[off] = linebuf_char[col]; if (char_cells == 2) { - grid->chars[off_to + 1] = linebuf_char[off_from + 1]; + grid->chars[off + 1] = linebuf_char[col + 1]; } - grid->attrs[off_to] = linebuf_attr[off_from]; + grid->attrs[off] = linebuf_attr[col]; // For simplicity set the attributes of second half of a // double-wide character equal to the first half. if (char_cells == 2) { - grid->attrs[off_to + 1] = linebuf_attr[off_from]; + grid->attrs[off + 1] = linebuf_attr[col]; } } - grid->vcols[off_to] = linebuf_vcol[off_from]; + grid->vcols[off] = linebuf_vcol[col]; if (char_cells == 2) { - grid->vcols[off_to + 1] = linebuf_vcol[off_from + 1]; + grid->vcols[off + 1] = linebuf_vcol[col + 1]; } - off_to += (size_t)char_cells; - off_from += (size_t)char_cells; col += char_cells; } if (clear_next) { // Clear the second half of a double-wide character of which the left // half was overwritten with a single-wide character. - grid->chars[off_to] = schar_from_ascii(' '); + grid->chars[(size_t)col + off_to] = schar_from_ascii(' '); end_dirty++; } int clear_end = -1; - if (clear_width > 0 && !rlflag) { + if (clear_width > 0 && !rl) { // blank out the rest of the line // TODO(bfredl): we could cache winline widths while (col < clear_width) { - if (grid->chars[off_to] != schar_from_ascii(' ') - || grid->attrs[off_to] != bg_attr + size_t off = (size_t)col + off_to; + if (grid->chars[off] != schar_from_ascii(' ') + || grid->attrs[off] != bg_attr || rdb_flags & RDB_NODELTA) { - grid->chars[off_to] = schar_from_ascii(' '); - grid->attrs[off_to] = bg_attr; + grid->chars[off] = schar_from_ascii(' '); + grid->attrs[off] = bg_attr; if (start_dirty == -1) { start_dirty = col; end_dirty = col; @@ -792,9 +696,8 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle } clear_end = col + 1; } - grid->vcols[off_to] = MAXCOL; + grid->vcols[off] = MAXCOL; col++; - off_to++; } } @@ -805,8 +708,22 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle start_dirty = end_dirty; } if (clear_end > start_dirty) { - ui_line(grid, row, coloff + start_dirty, coloff + end_dirty, coloff + clear_end, - bg_attr, wrap); + if (!grid->throttled) { + int start_pos = coloff + start_dirty; + // When drawing over the right half of a double-wide char clear out the + // left half. Only needed in a terminal. + if (invalid_row && start_pos == 0) { + start_pos = -1; + } + ui_line(grid, row, start_pos, coloff + end_dirty, coloff + clear_end, + bg_attr, wrap); + } else if (grid->dirty_col) { + // TODO(bfredl): really get rid of the extra psuedo terminal in message.c + // by using a linebuf_char copy for "throttled message line" + if (clear_end > grid->dirty_col[row]) { + grid->dirty_col[row] = clear_end; + } + } } } -- cgit From cf8b2c0e74fd5e723b0c15c2ce84e6900fd322d3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 12:05:28 +0800 Subject: build(iwyu): add a few more _defs.h mappings (#25435) --- src/nvim/grid.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 1d9cd80ec3..5588ef24a9 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -13,15 +13,21 @@ #include #include +#include #include +#include +#include "nvim/api/private/defs.h" #include "nvim/arabic.h" +#include "nvim/ascii.h" #include "nvim/buffer_defs.h" #include "nvim/drawscreen.h" #include "nvim/globals.h" #include "nvim/grid.h" #include "nvim/highlight.h" #include "nvim/log.h" +#include "nvim/map.h" +#include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option.h" #include "nvim/types.h" -- cgit From dc6d0d2daf69e2fdadda81feb97906dbc962a239 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 14:41:34 +0800 Subject: refactor: reorganize option header files (#25437) - Move vimoption_T to option.h - option_defs.h is for option-related types - option_vars.h corresponds to Vim's option.h - option_defs.h and option_vars.h don't include each other --- src/nvim/grid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 5588ef24a9..712688368b 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -29,7 +29,7 @@ #include "nvim/map.h" #include "nvim/memory.h" #include "nvim/message.h" -#include "nvim/option.h" +#include "nvim/option_vars.h" #include "nvim/types.h" #include "nvim/ui.h" #include "nvim/vim.h" -- cgit From a9a48d6b5f00241e16e7131c997f0117bc5e9047 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sat, 30 Sep 2023 10:31:55 +0200 Subject: refactor(message): simplify msg_puts_display and use batched grid updates msg_puts_display was more complex than necessary in nvim, as in nvim, it no longer talks directly with a terminal. In particular we don't need to scroll the grid before emiting the last char. The TUI already takes care of things like that, for terminals where it matters. --- src/nvim/grid.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 712688368b..7a707407d2 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -455,6 +455,22 @@ void grid_line_flush(void) false, 0, false, invalid_row); } +/// flush grid line but only if on a valid row +/// +/// This is a stopgap until message.c has been refactored to behave +void grid_line_flush_if_valid_row(void) +{ + if (grid_line_row < 0 || grid_line_row >= grid_line_grid->rows) { + if (rdb_flags & RDB_INVALID) { + abort(); + } else { + grid_line_grid = NULL; + return; + } + } + grid_line_flush(); +} + /// Fill the grid from "start_row" to "end_row" (exclusive), from "start_col" /// to "end_col" (exclusive) with character "c1" in first column followed by /// "c2" in the other columns. Use attributes "attr". -- cgit From a58bb215449cee65b965b9094e9e996ddfe78315 Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 5 Oct 2023 14:44:13 +0200 Subject: refactor(grid): get rid of unbatched grid_puts and grid_putchar This finalizes the long running refactor from the old TUI-focused grid implementation where text-drawing cursor was not separated from the visible cursor. Still, the pattern of setting cursor position together with updating a line was convenient. Introduce grid_line_cursor_goto() to still allow this but now being explicit about it. Only having batched drawing functions makes code involving drawing a bit longer. But it is better to be explicit, and this highlights cases where multiple small redraws can be grouped together. This was the case for most of the changed places (messages, lastline, and :intro) --- src/nvim/grid.c | 156 ++++++++++++++++++++------------------------------------ 1 file changed, 55 insertions(+), 101 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 7a707407d2..2eab158bc4 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -201,65 +201,23 @@ static bool grid_invalid_row(ScreenGrid *grid, int row) return grid->attrs[grid->line_offset[row]] < 0; } -/// Return number of display cells for char at grid->chars[off]. -/// We make sure that the offset used is less than "max_off". -static int grid_off2cells(ScreenGrid *grid, size_t off, size_t max_off) -{ - return (off + 1 < max_off && grid->chars[off + 1] == 0) ? 2 : 1; -} - -/// Return true if the character at "row"/"col" on the screen is the left side -/// of a double-width character. -/// -/// Caller must make sure "row" and "col" are not invalid! -bool grid_lefthalve(ScreenGrid *grid, int row, int col) -{ - grid_adjust(&grid, &row, &col); - - return grid_off2cells(grid, grid->line_offset[row] + (size_t)col, - grid->line_offset[row] + (size_t)grid->cols) > 1; -} - -/// Correct a position on the screen, if it's the right half of a double-wide -/// char move it to the left half. Returns the corrected column. -int grid_fix_col(ScreenGrid *grid, int col, int row) -{ - int coloff = 0; - grid_adjust(&grid, &row, &coloff); - - col += coloff; - if (grid->chars != NULL && col > 0 - && grid->chars[grid->line_offset[row] + (size_t)col] == 0) { - return col - 1 - coloff; - } - return col - coloff; -} - -/// output a single character directly to the grid -void grid_putchar(ScreenGrid *grid, int c, int row, int col, int attr) -{ - char buf[MB_MAXBYTES + 1]; - - grid_puts(grid, buf, utf_char2bytes(c, buf), row, col, attr); -} - /// Get a single character directly from grid.chars into "bytes", which must /// have a size of "MB_MAXBYTES + 1". /// If "attrp" is not NULL, return the character's attribute in "*attrp". -void grid_getbytes(ScreenGrid *grid, int row, int col, char *bytes, int *attrp) +schar_T grid_getchar(ScreenGrid *grid, int row, int col, int *attrp) { grid_adjust(&grid, &row, &col); // safety check if (grid->chars == NULL || row >= grid->rows || col >= grid->cols) { - return; + return NUL; } size_t off = grid->line_offset[row] + (size_t)col; if (attrp != NULL) { *attrp = grid->attrs[off]; } - schar_get(bytes, grid->chars[off]); + return grid->chars[off]; } static ScreenGrid *grid_line_grid = NULL; @@ -269,38 +227,6 @@ static int grid_line_maxcol = 0; static int grid_line_first = INT_MAX; static int grid_line_last = 0; -/// put string 'text' on the window grid at position 'row' and 'col', with -/// attributes 'attr', and update contents of 'grid' -/// @param textlen length of string or -1 to use strlen(text) -/// Note: only outputs within one row! -int grid_puts(ScreenGrid *grid, const char *text, int textlen, int row, int col, int attr) -{ - grid_line_start(grid, row); - - // Safety check. The check for negative row and column is to fix issue - // vim/vim#4102. TODO(neovim): find out why row/col could be negative. - int off_col = grid_line_coloff + col; - if (grid_line_grid->chars == NULL - || grid_line_row >= grid_line_grid->rows || grid_line_row < 0 - || off_col >= grid_line_grid->cols || off_col < 0) { - if (rdb_flags & RDB_INVALID) { - abort(); - } else { - grid_line_grid = NULL; - return 0; - } - } - - int len = grid_line_puts(col, text, textlen, attr); - if (grid_line_last > grid_line_first) { - // TODO(bfredl): this is bullshit. message.c should manage its own cursor movements - int col_pos = MIN(grid_line_coloff + grid_line_last, grid_line_grid->cols - 1); - ui_grid_cursor_goto(grid_line_grid->handle, grid_line_row, col_pos); - } - grid_line_flush(); - return len; -} - /// Start a group of grid_line_puts calls that builds a single grid line. /// /// Must be matched with a grid_line_flush call before moving to @@ -318,6 +244,25 @@ void grid_line_start(ScreenGrid *grid, int row) grid_line_last = 0; } +/// Get present char from current rendered screen line +/// +/// This indicates what already is on screen, not the pending render buffer. +/// +/// @return char or space if out of bounds +schar_T grid_line_getchar(int col, int *attr) +{ + if (col < grid_line_maxcol) { + size_t off = grid_line_grid->line_offset[grid_line_row] + (size_t)col; + if (attr != NULL) { + *attr = grid_line_grid->attrs[off]; + } + return grid_line_grid->chars[off]; + } else { + // NUL is a very special value (right-half of double width), space is True Neutral™ + return schar_from_ascii(' '); + } +} + void grid_line_put_schar(int col, schar_T schar, int attr) { assert(grid_line_grid); @@ -331,8 +276,13 @@ void grid_line_put_schar(int col, schar_T schar, int attr) linebuf_vcol[col] = -1; } -/// like grid_puts(), but output "text[len]". When "len" is -1 output up to -/// a NUL. +/// Put string "text" at "col" position relative to the grid line from the +/// recent grid_line_start() call. +/// +/// @param textlen length of string or -1 to use strlen(text) +/// Note: only outputs within one row! +/// +/// @return number of grid cells used int grid_line_puts(int col, const char *text, int textlen, int attr) { const char *ptr = text; @@ -435,8 +385,16 @@ void grid_line_fill(int start_col, int end_col, int c, int attr) linebuf_attr[col] = attr; linebuf_vcol[col] = -1; } - grid_line_first = MIN(grid_line_first, start_col); - grid_line_last = MAX(grid_line_last, end_col); + if (start_col < end_col) { + grid_line_first = MIN(grid_line_first, start_col); + grid_line_last = MAX(grid_line_last, end_col); + } +} + +/// move the cursor to a position in a currently rendered line. +void grid_line_cursor_goto(int col) +{ + ui_grid_cursor_goto(grid_line_grid->handle, grid_line_row, col); } /// End a group of grid_line_puts calls and send the screen buffer to the UI layer. @@ -500,27 +458,29 @@ void grid_fill(ScreenGrid *grid, int start_row, int end_row, int start_col, int } for (int row = start_row; row < end_row; row++) { + int dirty_first = INT_MAX; + int dirty_last = 0; + size_t lineoff = grid->line_offset[row]; + // When drawing over the right half of a double-wide char clear // out the left half. When drawing over the left half of a // double wide-char clear out the right half. Only needed in a // terminal. - if (start_col > 0 && grid_fix_col(grid, start_col, row) != start_col) { - grid_puts(grid, " ", 1, row, start_col - 1, 0); + if (start_col > 0 && grid->chars[lineoff + (size_t)start_col] == NUL) { + size_t off = lineoff + (size_t)start_col - 1; + grid->chars[off] = schar_from_ascii(' '); + grid->attrs[off] = attr; + dirty_first = start_col - 1; } - if (end_col < grid->cols - && grid_fix_col(grid, end_col, row) != end_col) { - grid_puts(grid, " ", 1, row, end_col, 0); + if (end_col < grid->cols && grid->chars[lineoff + (size_t)end_col] == NUL) { + size_t off = lineoff + (size_t)end_col; + grid->chars[off] = schar_from_ascii(' '); + grid->attrs[off] = attr; + dirty_last = end_col + 1; } - // if grid was resized (in ext_multigrid mode), the UI has no redraw updates - // for the newly resized grid. It is better mark everything as dirty and - // send all the updates. - int dirty_first = INT_MAX; - int dirty_last = 0; - int col = start_col; sc = schar_from_char(c1); - size_t lineoff = grid->line_offset[row]; for (col = start_col; col < end_col; col++) { size_t off = lineoff + (size_t)col; if (grid->chars[off] != sc || grid->attrs[off] != attr || rdb_flags & RDB_NODELTA) { @@ -600,8 +560,6 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int col, int endcol endcol = grid->cols; } - grid_adjust(&grid, &row, &coloff); - // Safety check. Avoids clang warnings down the call stack. if (grid->chars == NULL || row >= grid->rows || coloff >= grid->cols) { DLOG("invalid state, skipped"); @@ -662,12 +620,8 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int col, int endcol // the right half of the old character. // Also required when writing the right half of a double-width // char over the left half of an existing one - if (col + char_cells == endcol - && ((char_cells == 1 - && grid_off2cells(grid, off, max_off_to) > 1) - || (char_cells == 2 - && grid_off2cells(grid, off, max_off_to) == 1 - && grid_off2cells(grid, off + 1, max_off_to) > 1))) { + if (col + char_cells == endcol && off + (size_t)char_cells < max_off_to + && grid->chars[off + (size_t)char_cells] == NUL) { clear_next = true; } -- cgit From ddef39299f357d3131644647379e88a69749bf40 Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 19 Sep 2023 14:30:02 +0200 Subject: refactor(grid): do arabic shaping in one place The 'arabicshape' feature of vim is a transformation of unicode text to make arabic and some related scripts look better at display time. In particular the content of a cell will be adjusted depending on the (original) content of the cells just before and after it. This is implemented by the arabic_shape() function in nvim. Before this commit, shaping was invoked in four different contexts: - when rendering buffer text in win_line() - in line_putchar() for rendering virtual text - as part of grid_line_puts, used by messages and statuslines and similar - as part of draw_cmdline() for drawing the cmdline This replaces all these with a post-processing step in grid_put_linebuf(), which has become the entry point for all text rendering after recent refactors. An aim of this is to make the handling of multibyte text yet simpler. One of the main reasons multibyte chars needs to be "parsed" into codepoint arrays of composing chars is so that these could be inspected for the purpose of shaping. This can likely be vastly simplified in many contexts where only the total length (in bytes) and width of composed char is needed. --- src/nvim/grid.c | 154 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 116 insertions(+), 38 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 2eab158bc4..7c8823e0d4 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -152,17 +152,17 @@ bool schar_high(schar_T sc) #endif } -void schar_get(char *buf_out, schar_T sc) -{ - if (schar_high(sc)) { #ifdef ORDER_BIG_ENDIAN - uint32_t idx = sc & (0x00FFFFFF); +# define schar_idx(sc) (sc & (0x00FFFFFF)) #else - uint32_t idx = sc >> 8; +# define schar_idx(sc) (sc >> 8) #endif - if (idx >= glyph_cache.h.n_keys) { - abort(); - } + +void schar_get(char *buf_out, schar_T sc) +{ + if (schar_high(sc)) { + uint32_t idx = schar_idx(sc); + assert(idx < glyph_cache.h.n_keys); xstrlcpy(buf_out, &glyph_cache.keys[idx], 32); } else { memcpy(buf_out, (char *)&sc, 4); @@ -170,6 +170,13 @@ void schar_get(char *buf_out, schar_T sc) } } +/// gets first raw UTF-8 byte of an schar +static char schar_get_first_byte(schar_T sc) +{ + assert(!(schar_high(sc) && schar_idx(sc) >= glyph_cache.h.n_keys)); + return schar_high(sc) ? glyph_cache.keys[schar_idx(sc)] : *(char *)≻ +} + /// @return ascii char or NUL if not ascii char schar_get_ascii(schar_T sc) { @@ -179,6 +186,90 @@ char schar_get_ascii(schar_T sc) return (sc < 0x80) ? (char)sc : NUL; #endif } + +static bool schar_in_arabic_block(schar_T sc) +{ + char first_byte = schar_get_first_byte(sc); + return ((uint8_t)first_byte & 0xFE) == 0xD8; +} + +/// Get the first two codepoints of an schar, or NUL when not available +static void schar_get_first_two_codepoints(schar_T sc, int *c0, int *c1) +{ + char sc_buf[MAX_SCHAR_SIZE]; + schar_get(sc_buf, sc); + + *c0 = utf_ptr2char(sc_buf); + int len = utf_ptr2len(sc_buf); + if (*c0 == NUL) { + *c1 = NUL; + } else { + *c1 = utf_ptr2char(sc_buf + len); + } +} + +void line_do_arabic_shape(schar_T *buf, int cols) +{ + int i = 0; + + for (i = 0; i < cols; i++) { + // quickly skip over non-arabic text + if (schar_in_arabic_block(buf[i])) { + break; + } + } + + if (i == cols) { + return; + } + + int c0prev = 0; + int c0, c1; + schar_get_first_two_codepoints(buf[i], &c0, &c1); + + for (; i < cols; i++) { + int c0next, c1next; + schar_get_first_two_codepoints(i + 1 < cols ? buf[i + 1] : 0, &c0next, &c1next); + + if (!ARABIC_CHAR(c0)) { + goto next; + } + + int c1new = c1; + int c0new = arabic_shape(c0, &c1new, c0next, c1next, c0prev); + + if (c0new == c0 && c1new == c1) { + goto next; // unchanged + } + + char scbuf[MAX_SCHAR_SIZE]; + schar_get(scbuf, buf[i]); + + char scbuf_new[MAX_SCHAR_SIZE]; + int len = utf_char2bytes(c0new, scbuf_new); + if (c1new) { + len += utf_char2bytes(c1new, scbuf_new + len); + } + + int off = utf_char2len(c0) + (c1 ? utf_char2len(c1) : 0); + size_t rest = strlen(scbuf + off); + if (rest + (size_t)off + 1 > MAX_SCHAR_SIZE) { + // TODO(bfredl): this cannot happen just yet, as we only construct + // schar_T values with up to MAX_MCO+1 composing codepoints. When code + // is improved so that MAX_SCHAR_SIZE becomes the only/sharp limit, + // we need be able to peel off a composing char which doesn't fit anymore. + abort(); + } + memcpy(scbuf_new + len, scbuf + off, rest); + buf[i] = schar_from_buf(scbuf_new, (size_t)len + rest); + +next: + c0prev = c0; + c0 = c0next; + c1 = c1next; + } +} + /// clear a line in the grid starting at "off" until "width" characters /// are cleared. void grid_clear_line(ScreenGrid *grid, size_t off, int width, bool valid) @@ -242,6 +333,15 @@ void grid_line_start(ScreenGrid *grid, int row) grid_line_first = (int)linebuf_size; grid_line_maxcol = grid->cols - grid_line_coloff; grid_line_last = 0; + + assert((size_t)grid_line_maxcol <= linebuf_size); + + if (rdb_flags & RDB_INVALID) { + // Current batch must not depend on previous contents of linebuf_char. + // Set invalid values which will cause assertion failures later if they are used. + memset(linebuf_char, 0xFF, sizeof(schar_T) * linebuf_size); + memset(linebuf_attr, 0xFF, sizeof(sattr_T) * linebuf_size); + } } /// Get present char from current rendered screen line @@ -287,11 +387,7 @@ int grid_line_puts(int col, const char *text, int textlen, int attr) { const char *ptr = text; int len = textlen; - int c; int u8cc[MAX_MCO]; - int prev_c = 0; // previous Arabic character - int pc, nc, nc1; - int pcc[MAX_MCO]; assert(grid_line_grid); @@ -301,7 +397,6 @@ int grid_line_puts(int col, const char *text, int textlen, int attr) while (col < max_col && (len < 0 || (int)(ptr - text) < len) && *ptr != NUL) { - c = (unsigned char)(*ptr); // check if this is the first byte of a multibyte int mbyte_blen = len > 0 ? utfc_ptr2len_len(ptr, (int)((text + len) - ptr)) @@ -316,37 +411,16 @@ int grid_line_puts(int col, const char *text, int textlen, int attr) u8cc[0] = 0; } - if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) { - // Do Arabic shaping. - if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) { - // Past end of string to be displayed. - nc = NUL; - nc1 = NUL; - } else { - nc = len >= 0 - ? utfc_ptr2char_len(ptr + mbyte_blen, pcc, - (int)((text + len) - ptr - mbyte_blen)) - : utfc_ptr2char(ptr + mbyte_blen, pcc); - nc1 = pcc[0]; - } - pc = prev_c; - prev_c = u8c; - u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); - } else { - prev_c = u8c; - } if (col + mbyte_cells > max_col) { // Only 1 cell left, but character requires 2 cells: // display a '>' in the last column to avoid wrapping. */ - c = '>'; u8c = '>'; u8cc[0] = 0; mbyte_cells = 1; } schar_T buf; - // TODO(bfredl): why not just keep the original byte sequence. arabshape is - // an edge case, treat it as such.. + // TODO(bfredl): why not just keep the original byte sequence. buf = schar_from_cc(u8c, u8cc); // When at the start of the text and overwriting the right half of a @@ -545,14 +619,12 @@ static int grid_char_needs_redraw(ScreenGrid *grid, int col, size_t off_to, int /// If "wrap" is true, then hint to the UI that "row" contains a line /// which has wrapped into the next row. void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int col, int endcol, int clear_width, - int rl, int bg_attr, bool wrap, bool invalid_row) + bool rl, int bg_attr, bool wrap, bool invalid_row) { bool redraw_next; // redraw_this for next character bool clear_next = false; int char_cells; // 1: normal char // 2: occupies two display cells - int start_dirty = -1, end_dirty = 0; - assert(0 <= row && row < grid->rows); // TODO(bfredl): check all callsites and eliminate // Check for illegal col, just in case @@ -591,6 +663,10 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int col, int endcol endcol = (clear_width > 0 ? clear_width : -clear_width); } + if (p_arshape && !p_tbidi) { + line_do_arabic_shape(linebuf_char + col, endcol - col); + } + if (bg_attr) { for (int c = col; c < endcol; c++) { linebuf_attr[c] = hl_combine_attr(bg_attr, linebuf_attr[c]); @@ -599,6 +675,8 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int col, int endcol redraw_next = grid_char_needs_redraw(grid, col, (size_t)col + off_to, endcol - col); + int start_dirty = -1, end_dirty = 0; + while (col < endcol) { char_cells = 1; if (col + 1 < endcol && linebuf_char[col + 1] == 0) { -- cgit From 9f32deba56ea867a8bb9b9ab7f44bcc5142e8bbc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 13 Oct 2023 21:43:06 +0800 Subject: fix(grid): add start column when getting char on line (#25627) --- src/nvim/grid.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 7c8823e0d4..9fe518e9fd 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -352,6 +352,7 @@ void grid_line_start(ScreenGrid *grid, int row) schar_T grid_line_getchar(int col, int *attr) { if (col < grid_line_maxcol) { + col += grid_line_coloff; size_t off = grid_line_grid->line_offset[grid_line_row] + (size_t)col; if (attr != NULL) { *attr = grid_line_grid->attrs[off]; -- cgit From bf70a33f5e7de0218704126c149db24542e39766 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 14 Oct 2023 09:58:30 +0800 Subject: vim-patch:8.1.0822: peeking and flushing output slows down execution (#25629) Problem: Peeking and flushing output slows down execution. Solution: Do not update the mode message when global_busy is set. Do not flush when only peeking for a character. (Ken Takata) https://github.com/vim/vim/commit/cb574f415486adff645ce384979bfecf27f5be8c --- src/nvim/grid.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 9fe518e9fd..c16625a330 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -481,11 +481,8 @@ void grid_line_flush(void) return; } - int row = grid_line_row; - - bool invalid_row = grid != &default_grid && grid_invalid_row(grid, row) && grid_line_first == 0; - grid_put_linebuf(grid, row, grid_line_coloff, grid_line_first, grid_line_last, grid_line_last, - false, 0, false, invalid_row); + grid_put_linebuf(grid, grid_line_row, grid_line_coloff, grid_line_first, grid_line_last, + grid_line_last, false, 0, false); } /// flush grid line but only if on a valid row @@ -620,7 +617,7 @@ static int grid_char_needs_redraw(ScreenGrid *grid, int col, size_t off_to, int /// If "wrap" is true, then hint to the UI that "row" contains a line /// which has wrapped into the next row. void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int col, int endcol, int clear_width, - bool rl, int bg_attr, bool wrap, bool invalid_row) + bool rl, int bg_attr, bool wrap) { bool redraw_next; // redraw_this for next character bool clear_next = false; @@ -639,6 +636,7 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int col, int endcol return; } + bool invalid_row = grid != &default_grid && grid_invalid_row(grid, row) && col == 0; size_t off_to = grid->line_offset[row] + (size_t)coloff; const size_t max_off_to = grid->line_offset[row] + (size_t)grid->cols; -- cgit From 2dc9ceb99c018b15dcf0c443cad46efecccaf94e Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 29 Oct 2023 09:02:32 +0100 Subject: docs: small fixes (#25585) Co-authored-by: tmummert Co-authored-by: parikshit adhikari --- src/nvim/grid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index c16625a330..efc819c26f 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -771,7 +771,7 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int col, int endcol ui_line(grid, row, start_pos, coloff + end_dirty, coloff + clear_end, bg_attr, wrap); } else if (grid->dirty_col) { - // TODO(bfredl): really get rid of the extra psuedo terminal in message.c + // TODO(bfredl): really get rid of the extra pseudo terminal in message.c // by using a linebuf_char copy for "throttled message line" if (clear_end > grid->dirty_col[row]) { grid->dirty_col[row] = clear_end; -- cgit From 44f0480a22af8f87f8784dac430416cb9913adea Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 31 Oct 2023 21:33:00 +0100 Subject: refactor(grid): implement rightleftcmd as a post-processing step Previously, 'rightleftcmd' was implemented by having all code which would affect msg_col or output screen cells be conditional on `cmdmsg_rl`. This change removes all that and instead implements rightleft as a mirroring post-processing step. --- src/nvim/grid.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index efc819c26f..d59c3b4803 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -472,6 +472,45 @@ void grid_line_cursor_goto(int col) ui_grid_cursor_goto(grid_line_grid->handle, grid_line_row, col); } +void grid_line_mirror(void) +{ + if (grid_line_first >= grid_line_last) { + return; + } + + size_t n = (size_t)(grid_line_last - grid_line_first); + int mirror = grid_line_maxcol - 1; // Mirrors are more fun than television. + schar_T *scratch_char = (schar_T *)linebuf_scratch; + memcpy(scratch_char + grid_line_first, linebuf_char + grid_line_first, n * sizeof(schar_T)); + for (int col = grid_line_first; col < grid_line_last; col++) { + int rev = mirror - col; + if (col + 1 < grid_line_last && scratch_char[col + 1] == 0) { + linebuf_char[rev - 1] = scratch_char[col]; + linebuf_char[rev] = 0; + col++; + } else { + linebuf_char[rev] = scratch_char[col]; + } + } + + // for attr and vcol: assumes doublewidth chars are self-consistent + sattr_T *scratch_attr = (sattr_T *)linebuf_scratch; + memcpy(scratch_attr + grid_line_first, linebuf_attr + grid_line_first, n * sizeof(sattr_T)); + for (int col = grid_line_first; col < grid_line_last; col++) { + linebuf_attr[mirror - col] = scratch_attr[col]; + } + + colnr_T *scratch_vcol = (colnr_T *)linebuf_scratch; + memcpy(scratch_vcol + grid_line_first, linebuf_vcol + grid_line_first, n * sizeof(colnr_T)); + for (int col = grid_line_first; col < grid_line_last; col++) { + linebuf_vcol[mirror - col] = scratch_vcol[col]; + } + + int grid_line_last_copy = grid_line_last; + grid_line_last = grid_line_maxcol - grid_line_first; + grid_line_first = grid_line_maxcol - grid_line_last_copy; +} + /// End a group of grid_line_puts calls and send the screen buffer to the UI layer. void grid_line_flush(void) { @@ -828,9 +867,11 @@ void grid_alloc(ScreenGrid *grid, int rows, int columns, bool copy, bool valid) xfree(linebuf_char); xfree(linebuf_attr); xfree(linebuf_vcol); + xfree(linebuf_scratch); linebuf_char = xmalloc((size_t)columns * sizeof(schar_T)); linebuf_attr = xmalloc((size_t)columns * sizeof(sattr_T)); linebuf_vcol = xmalloc((size_t)columns * sizeof(colnr_T)); + linebuf_scratch = xmalloc((size_t)columns * sizeof(sscratch_T)); linebuf_size = (size_t)columns; } } @@ -855,6 +896,7 @@ void grid_free_all_mem(void) xfree(linebuf_char); xfree(linebuf_attr); xfree(linebuf_vcol); + xfree(linebuf_scratch); } /// (Re)allocates a window grid if size changed while in ext_multigrid mode. -- cgit From 83db9115af94992a2fb32e927b7349283434ff5d Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 3 Nov 2023 20:25:52 +0100 Subject: refactor(grid): reimplement 'rightleft' as a post-processing step problem: checks for wp->w_p_rl are all over the place, making simple things like "advance column one cell" incredibly complicated. solution: always fill linebuf_char[] using an incrementing counter, and then mirror the buffer as a post-processing step This was "easier" that I first feared, because the stupid but simple workaround for things like keeping linenumbers still left-right, e.g. "mirror them and them mirror them once more" is more or less what vim did already. So let's just keep doing that. --- src/nvim/grid.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index d59c3b4803..45bffdcab5 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -477,14 +477,21 @@ void grid_line_mirror(void) if (grid_line_first >= grid_line_last) { return; } + linebuf_mirror(&grid_line_first, &grid_line_last, grid_line_maxcol); +} + +void linebuf_mirror(int *firstp, int *lastp, int maxcol) +{ + int first = *firstp; + int last = *lastp; - size_t n = (size_t)(grid_line_last - grid_line_first); - int mirror = grid_line_maxcol - 1; // Mirrors are more fun than television. + size_t n = (size_t)(last - first); + int mirror = maxcol - 1; // Mirrors are more fun than television. schar_T *scratch_char = (schar_T *)linebuf_scratch; - memcpy(scratch_char + grid_line_first, linebuf_char + grid_line_first, n * sizeof(schar_T)); - for (int col = grid_line_first; col < grid_line_last; col++) { + memcpy(scratch_char + first, linebuf_char + first, n * sizeof(schar_T)); + for (int col = first; col < last; col++) { int rev = mirror - col; - if (col + 1 < grid_line_last && scratch_char[col + 1] == 0) { + if (col + 1 < last && scratch_char[col + 1] == 0) { linebuf_char[rev - 1] = scratch_char[col]; linebuf_char[rev] = 0; col++; @@ -495,20 +502,19 @@ void grid_line_mirror(void) // for attr and vcol: assumes doublewidth chars are self-consistent sattr_T *scratch_attr = (sattr_T *)linebuf_scratch; - memcpy(scratch_attr + grid_line_first, linebuf_attr + grid_line_first, n * sizeof(sattr_T)); - for (int col = grid_line_first; col < grid_line_last; col++) { + memcpy(scratch_attr + first, linebuf_attr + first, n * sizeof(sattr_T)); + for (int col = first; col < last; col++) { linebuf_attr[mirror - col] = scratch_attr[col]; } colnr_T *scratch_vcol = (colnr_T *)linebuf_scratch; - memcpy(scratch_vcol + grid_line_first, linebuf_vcol + grid_line_first, n * sizeof(colnr_T)); - for (int col = grid_line_first; col < grid_line_last; col++) { + memcpy(scratch_vcol + first, linebuf_vcol + first, n * sizeof(colnr_T)); + for (int col = first; col < last; col++) { linebuf_vcol[mirror - col] = scratch_vcol[col]; } - int grid_line_last_copy = grid_line_last; - grid_line_last = grid_line_maxcol - grid_line_first; - grid_line_first = grid_line_maxcol - grid_line_last_copy; + *lastp = maxcol - first; + *firstp = maxcol - last; } /// End a group of grid_line_puts calls and send the screen buffer to the UI layer. @@ -698,10 +704,10 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int col, int endcol } } col = endcol + 1; - endcol = (clear_width > 0 ? clear_width : -clear_width); + endcol = clear_width; } - if (p_arshape && !p_tbidi) { + if (p_arshape && !p_tbidi && endcol > col) { line_do_arabic_shape(linebuf_char + col, endcol - col); } -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/grid.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 45bffdcab5..15b648bb03 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - // Most of the routines in this file perform screen (grid) manipulations. The // given operation is performed physically on the screen. The corresponding // change is also made to the internal screen image. In this way, the editor -- cgit From 28f4f3c48498086307ed825d1761edb5789ca0e8 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 15:54:54 +0100 Subject: refactor: follow style guide - reduce variable scope - prefer initialization over declaration and assignment - use bool to represent boolean values --- src/nvim/grid.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 15b648bb03..f21b7e3a90 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -549,8 +549,6 @@ void grid_line_flush_if_valid_row(void) void grid_fill(ScreenGrid *grid, int start_row, int end_row, int start_col, int end_col, int c1, int c2, int attr) { - schar_T sc; - int row_off = 0, col_off = 0; grid_adjust(&grid, &row_off, &col_off); start_row += row_off; @@ -594,7 +592,7 @@ void grid_fill(ScreenGrid *grid, int start_row, int end_row, int start_col, int } int col = start_col; - sc = schar_from_char(c1); + schar_T sc = schar_from_char(c1); for (col = start_col; col < end_col; col++) { size_t off = lineoff + (size_t)col; if (grid->chars[off] != sc || grid->attrs[off] != attr || rdb_flags & RDB_NODELTA) { -- cgit From b522cb1ac3fbdf6e68eed5d0b6e1cbeaf3ac2254 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 6 Nov 2023 14:52:27 +0100 Subject: refactor(grid): make screen rendering more multibyte than ever before Problem: buffer text with composing chars are converted from UTF-8 to an array of up to seven UTF-32 values and then converted back to UTF-8 strings. Solution: Convert buffer text directly to UTF-8 based schar_T values. The limit of the text size is now in schar_T bytes, which is currently 31+1 but easily could be raised as it no longer multiplies the size of the entire screen grid when not used, the full size is only required for temporary scratch buffers. Also does some general cleanup to win_line text handling, which was unnecessarily complicated due to multibyte rendering being an "opt-in" feature long ago. Nowadays, a char is just a char, regardless if it consists of one ASCII byte or multiple bytes. --- src/nvim/grid.c | 65 +++++++++++++++++++-------------------------------------- 1 file changed, 21 insertions(+), 44 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index f21b7e3a90..6320abe4ea 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -68,21 +68,6 @@ void grid_adjust(ScreenGrid **grid, int *row_off, int *col_off) } } -/// Put a unicode char, and up to MAX_MCO composing chars, in a screen cell. -schar_T schar_from_cc(int c, int u8cc[MAX_MCO]) -{ - char buf[MAX_SCHAR_SIZE]; - int len = utf_char2bytes(c, buf); - for (int i = 0; i < MAX_MCO; i++) { - if (u8cc[i] == 0) { - break; - } - len += utf_char2bytes(u8cc[i], buf + len); - } - buf[len] = 0; - return schar_from_buf(buf, (size_t)len); -} - schar_T schar_from_str(char *str) { if (str == NULL) { @@ -243,22 +228,21 @@ void line_do_arabic_shape(schar_T *buf, int cols) schar_get(scbuf, buf[i]); char scbuf_new[MAX_SCHAR_SIZE]; - int len = utf_char2bytes(c0new, scbuf_new); + size_t len = (size_t)utf_char2bytes(c0new, scbuf_new); if (c1new) { - len += utf_char2bytes(c1new, scbuf_new + len); + len += (size_t)utf_char2bytes(c1new, scbuf_new + len); } int off = utf_char2len(c0) + (c1 ? utf_char2len(c1) : 0); size_t rest = strlen(scbuf + off); - if (rest + (size_t)off + 1 > MAX_SCHAR_SIZE) { - // TODO(bfredl): this cannot happen just yet, as we only construct - // schar_T values with up to MAX_MCO+1 composing codepoints. When code - // is improved so that MAX_SCHAR_SIZE becomes the only/sharp limit, - // we need be able to peel off a composing char which doesn't fit anymore. - abort(); + if (rest + len + 1 > MAX_SCHAR_SIZE) { + // Too bigly, discard one code-point. + // This should be enough as c0 cannot grow more than from 2 to 4 bytes + // (base arabic to extended arabic) + rest -= (size_t)utf_cp_head_off(scbuf + off, scbuf + off + rest - 1) + 1; } memcpy(scbuf_new + len, scbuf + off, rest); - buf[i] = schar_from_buf(scbuf_new, (size_t)len + rest); + buf[i] = schar_from_buf(scbuf_new, len + rest); next: c0prev = c0; @@ -289,9 +273,9 @@ static bool grid_invalid_row(ScreenGrid *grid, int row) return grid->attrs[grid->line_offset[row]] < 0; } -/// Get a single character directly from grid.chars into "bytes", which must -/// have a size of "MB_MAXBYTES + 1". -/// If "attrp" is not NULL, return the character's attribute in "*attrp". +/// Get a single character directly from grid.chars +/// +/// @param[out] attrp set to the character's attribute (optional) schar_T grid_getchar(ScreenGrid *grid, int row, int col, int *attrp) { grid_adjust(&grid, &row, &col); @@ -385,42 +369,35 @@ int grid_line_puts(int col, const char *text, int textlen, int attr) { const char *ptr = text; int len = textlen; - int u8cc[MAX_MCO]; assert(grid_line_grid); int start_col = col; int max_col = grid_line_maxcol; - while (col < max_col - && (len < 0 || (int)(ptr - text) < len) - && *ptr != NUL) { + while (col < max_col && (len < 0 || (int)(ptr - text) < len) && *ptr != NUL) { // check if this is the first byte of a multibyte int mbyte_blen = len > 0 ? utfc_ptr2len_len(ptr, (int)((text + len) - ptr)) : utfc_ptr2len(ptr); - int u8c = len >= 0 - ? utfc_ptr2char_len(ptr, u8cc, (int)((text + len) - ptr)) - : utfc_ptr2char(ptr, u8cc); - int mbyte_cells = utf_char2cells(u8c); + int firstc; + schar_T schar = len >= 0 + ? utfc_ptr2schar_len(ptr, (int)((text + len) - ptr), &firstc) + : utfc_ptr2schar(ptr, &firstc); + int mbyte_cells = utf_char2cells(firstc); if (mbyte_cells > 2) { mbyte_cells = 1; - u8c = 0xFFFD; - u8cc[0] = 0; + + schar = schar_from_char(0xFFFD); } if (col + mbyte_cells > max_col) { // Only 1 cell left, but character requires 2 cells: // display a '>' in the last column to avoid wrapping. */ - u8c = '>'; - u8cc[0] = 0; + schar = schar_from_ascii('>'); mbyte_cells = 1; } - schar_T buf; - // TODO(bfredl): why not just keep the original byte sequence. - buf = schar_from_cc(u8c, u8cc); - // When at the start of the text and overwriting the right half of a // two-cell character in the same grid, truncate that into a '>'. if (ptr == text && col > grid_line_first && col < grid_line_last @@ -428,7 +405,7 @@ int grid_line_puts(int col, const char *text, int textlen, int attr) linebuf_char[col - 1] = schar_from_ascii('>'); } - linebuf_char[col] = buf; + linebuf_char[col] = schar; linebuf_attr[col] = attr; linebuf_vcol[col] = -1; if (mbyte_cells == 2) { -- cgit From a6e3d93421ba13c407a96fac9cc01fa41ec7ad98 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 16 Nov 2023 10:59:11 +0100 Subject: refactor: enable formatting for ternaries This requires removing the "Inner expression should be aligned" rule from clint as it prevents essentially any formatting regarding ternary operators. --- src/nvim/grid.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 6320abe4ea..a9d2bf92f7 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -378,12 +378,12 @@ int grid_line_puts(int col, const char *text, int textlen, int attr) while (col < max_col && (len < 0 || (int)(ptr - text) < len) && *ptr != NUL) { // check if this is the first byte of a multibyte int mbyte_blen = len > 0 - ? utfc_ptr2len_len(ptr, (int)((text + len) - ptr)) - : utfc_ptr2len(ptr); + ? utfc_ptr2len_len(ptr, (int)((text + len) - ptr)) + : utfc_ptr2len(ptr); int firstc; schar_T schar = len >= 0 - ? utfc_ptr2schar_len(ptr, (int)((text + len) - ptr), &firstc) - : utfc_ptr2schar(ptr, &firstc); + ? utfc_ptr2schar_len(ptr, (int)((text + len) - ptr), &firstc) + : utfc_ptr2schar(ptr, &firstc); int mbyte_cells = utf_char2cells(firstc); if (mbyte_cells > 2) { mbyte_cells = 1; -- cgit From 4ed1c2a8afc71f1e3e2bc6835dc95f284782fe52 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 24 Nov 2023 05:59:06 +0800 Subject: fix(grid): don't draw beyond max column (#26172) --- src/nvim/grid.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index a9d2bf92f7..e25dcfe4bf 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -348,6 +348,9 @@ schar_T grid_line_getchar(int col, int *attr) void grid_line_put_schar(int col, schar_T schar, int attr) { assert(grid_line_grid); + if (col >= grid_line_maxcol) { + return; + } linebuf_char[col] = schar; linebuf_attr[col] = attr; @@ -374,7 +377,7 @@ int grid_line_puts(int col, const char *text, int textlen, int attr) int start_col = col; - int max_col = grid_line_maxcol; + const int max_col = grid_line_maxcol; while (col < max_col && (len < 0 || (int)(ptr - text) < len) && *ptr != NUL) { // check if this is the first byte of a multibyte int mbyte_blen = len > 0 @@ -428,16 +431,20 @@ int grid_line_puts(int col, const char *text, int textlen, int attr) void grid_line_fill(int start_col, int end_col, int c, int attr) { + end_col = MIN(end_col, grid_line_maxcol); + if (start_col >= end_col) { + return; + } + schar_T sc = schar_from_char(c); for (int col = start_col; col < end_col; col++) { linebuf_char[col] = sc; linebuf_attr[col] = attr; linebuf_vcol[col] = -1; } - if (start_col < end_col) { - grid_line_first = MIN(grid_line_first, start_col); - grid_line_last = MAX(grid_line_last, end_col); - } + + grid_line_first = MIN(grid_line_first, start_col); + grid_line_last = MAX(grid_line_last, end_col); } /// move the cursor to a position in a currently rendered line. @@ -496,7 +503,8 @@ void grid_line_flush(void) { ScreenGrid *grid = grid_line_grid; grid_line_grid = NULL; - if (!(grid_line_first < grid_line_last)) { + assert(grid_line_last <= grid_line_maxcol); + if (grid_line_first >= grid_line_last) { return; } -- cgit From 6c14ae6bfaf51415b555e9a6b85d1d280976358d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:27:32 +0100 Subject: refactor: rename types.h to types_defs.h --- src/nvim/grid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index e25dcfe4bf..edc7e157c0 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -27,7 +27,7 @@ #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option_vars.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/ui.h" #include "nvim/vim.h" -- cgit From ae3685798deaf51f14422c568998998c03f91f2c Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 26 Nov 2023 21:07:29 +0100 Subject: feat(decoration): allow conceal_char to be a composing char decor->text.str pointer must go. This removes it for conceal char, in preparation for a larger PR which will also handle the sign case. By actually allowing composing chars for a conceal chars, this becomes a feature and not just a refactor, as a bonus. --- src/nvim/grid.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index edc7e157c0..029912c8ea 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -18,7 +18,7 @@ #include "nvim/arabic.h" #include "nvim/ascii.h" #include "nvim/buffer_defs.h" -#include "nvim/drawscreen.h" +#include "nvim/decoration.h" #include "nvim/globals.h" #include "nvim/grid.h" #include "nvim/highlight.h" @@ -111,18 +111,16 @@ bool schar_cache_clear_if_full(void) // note: critical max is really (1<<24)-1. This gives us some marginal // until next time update_screen() is called if (glyph_cache.h.n_keys > (1<<21)) { - set_clear(glyph, &glyph_cache); + schar_cache_clear(); return true; } return false; } -/// For testing. The condition in schar_cache_clear_force is hard to -/// reach, so this function can be used to force a cache clear in a test. -void schar_cache_clear_force(void) +void schar_cache_clear(void) { + decor_check_invalid_glyphs(); set_clear(glyph, &glyph_cache); - must_redraw = UPD_CLEAR; } bool schar_high(schar_T sc) @@ -159,6 +157,13 @@ static char schar_get_first_byte(schar_T sc) return schar_high(sc) ? glyph_cache.keys[schar_idx(sc)] : *(char *)≻ } +int schar_get_first_codepoint(schar_T sc) +{ + char sc_buf[MAX_SCHAR_SIZE]; + schar_get(sc_buf, sc); + return utf_ptr2char(sc_buf); +} + /// @return ascii char or NUL if not ascii char schar_get_ascii(schar_T sc) { -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/grid.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 029912c8ea..e5b870e6b0 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -16,20 +16,20 @@ #include "nvim/api/private/defs.h" #include "nvim/arabic.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/buffer_defs.h" #include "nvim/decoration.h" #include "nvim/globals.h" #include "nvim/grid.h" #include "nvim/highlight.h" #include "nvim/log.h" -#include "nvim/map.h" +#include "nvim/map_defs.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option_vars.h" #include "nvim/types_defs.h" #include "nvim/ui.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "grid.c.generated.h" -- cgit From a6cba103cebce535279db197f9efeb34e9d1171f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 20:32:40 +0800 Subject: refactor: move some constants out of vim_defs.h (#26298) --- src/nvim/grid.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index e5b870e6b0..2ef89b778e 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -29,7 +29,6 @@ #include "nvim/option_vars.h" #include "nvim/types_defs.h" #include "nvim/ui.h" -#include "nvim/vim_defs.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "grid.c.generated.h" -- cgit