aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/edit.c
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2023-10-05 14:44:13 +0200
committerbfredl <bjorn.linse@gmail.com>2023-10-06 10:16:30 +0200
commita58bb215449cee65b965b9094e9e996ddfe78315 (patch)
treed5ed5946e782d4a50b1b94c9de40948a81e07e3b /src/nvim/edit.c
parentf67517bba30b6233bea85e1f6a8505171142d4ca (diff)
downloadrneovim-a58bb215449cee65b965b9094e9e996ddfe78315.tar.gz
rneovim-a58bb215449cee65b965b9094e9e996ddfe78315.tar.bz2
rneovim-a58bb215449cee65b965b9094e9e996ddfe78315.zip
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)
Diffstat (limited to 'src/nvim/edit.c')
-rw-r--r--src/nvim/edit.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 58cface37f..4593748c25 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -1412,11 +1412,11 @@ static void ins_ctrl_v(void)
// Put a character directly onto the screen. It's not stored in a buffer.
// Used while handling CTRL-K, CTRL-V, etc. in Insert mode.
static int pc_status;
-#define PC_STATUS_UNSET 0 // pc_bytes was not set
-#define PC_STATUS_RIGHT 1 // right half of double-wide char
-#define PC_STATUS_LEFT 2 // left half of double-wide char
-#define PC_STATUS_SET 3 // pc_bytes was filled
-static char pc_bytes[MB_MAXBYTES + 1]; // saved bytes
+#define PC_STATUS_UNSET 0 // nothing was put on screen
+#define PC_STATUS_RIGHT 1 // right half of double-wide char
+#define PC_STATUS_LEFT 2 // left half of double-wide char
+#define PC_STATUS_SET 3 // pc_schar was filled
+static schar_T pc_schar; // saved char
static int pc_attr;
static int pc_row;
static int pc_col;
@@ -1433,31 +1433,34 @@ void edit_putchar(int c, bool highlight)
attr = 0;
}
pc_row = curwin->w_wrow;
- pc_col = 0;
pc_status = PC_STATUS_UNSET;
+ grid_line_start(&curwin->w_grid, pc_row);
if (curwin->w_p_rl) {
- pc_col += curwin->w_grid.cols - 1 - curwin->w_wcol;
- const int fix_col = grid_fix_col(&curwin->w_grid, pc_col, pc_row);
+ pc_col = curwin->w_grid.cols - 1 - curwin->w_wcol;
- if (fix_col != pc_col) {
- grid_putchar(&curwin->w_grid, ' ', pc_row, fix_col, attr);
+ if (grid_line_getchar(pc_col, NULL) == NUL) {
+ grid_line_put_schar(pc_col - 1, schar_from_ascii(' '), attr);
curwin->w_wcol--;
pc_status = PC_STATUS_RIGHT;
}
} else {
- pc_col += curwin->w_wcol;
- if (grid_lefthalve(&curwin->w_grid, pc_row, pc_col)) {
+ pc_col = curwin->w_wcol;
+
+ if (grid_line_getchar(pc_col + 1, NULL) == NUL) {
+ // pc_col is the left half of a double-width char
pc_status = PC_STATUS_LEFT;
}
}
// save the character to be able to put it back
if (pc_status == PC_STATUS_UNSET) {
- // TODO(bfredl): save the schar_T instead
- grid_getbytes(&curwin->w_grid, pc_row, pc_col, pc_bytes, &pc_attr);
+ pc_schar = grid_line_getchar(pc_col, &pc_attr);
pc_status = PC_STATUS_SET;
}
- grid_putchar(&curwin->w_grid, c, pc_row, pc_col, attr);
+
+ char buf[MB_MAXBYTES + 1];
+ grid_line_puts(pc_col, buf, utf_char2bytes(c, buf), attr);
+ grid_line_flush();
}
}
@@ -1537,7 +1540,10 @@ void edit_unputchar(void)
if (pc_status == PC_STATUS_RIGHT || pc_status == PC_STATUS_LEFT) {
redrawWinline(curwin, curwin->w_cursor.lnum);
} else {
- grid_puts(&curwin->w_grid, pc_bytes, -1, pc_row, pc_col, pc_attr);
+ // TODO(bfredl): this could be smarter and also handle the dubyawidth case
+ grid_line_start(&curwin->w_grid, pc_row);
+ grid_line_put_schar(pc_col, pc_schar, pc_attr);
+ grid_line_flush();
}
}
}