aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/popupmenu.c
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2023-09-20 13:42:37 +0200
committerbfredl <bjorn.linse@gmail.com>2023-09-22 13:48:46 +0200
commit3a7cb72dcbe4aaaed47999ab5afaf3d1cb8d4df8 (patch)
tree534581de3060c6c2ed9d000636a27295295e653e /src/nvim/popupmenu.c
parentb7763d7f6b7fdcabe06658c664457df8bc147563 (diff)
downloadrneovim-3a7cb72dcbe4aaaed47999ab5afaf3d1cb8d4df8.tar.gz
rneovim-3a7cb72dcbe4aaaed47999ab5afaf3d1cb8d4df8.tar.bz2
rneovim-3a7cb72dcbe4aaaed47999ab5afaf3d1cb8d4df8.zip
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.
Diffstat (limited to 'src/nvim/popupmenu.c')
-rw-r--r--src/nvim/popupmenu.c41
1 files changed, 17 insertions, 24 deletions
diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c
index fe31c70d5d..488c893bd8 100644
--- a/src/nvim/popupmenu.c
+++ b/src/nvim/popupmenu.c
@@ -507,14 +507,14 @@ void pum_redraw(void)
const int *const attrs = (idx == pum_selected) ? attrsSel : attrsNorm;
int attr = attrs[0]; // start with "word" highlight
- grid_puts_line_start(&pum_grid, row);
+ grid_line_start(&pum_grid, row);
// prepend a space if there is room
if (extra_space) {
if (pum_rl) {
- grid_putchar(&pum_grid, ' ', row, col_off + 1, attr);
+ grid_line_puts(col_off + 1, " ", 1, attr);
} else {
- grid_putchar(&pum_grid, ' ', row, col_off - 1, attr);
+ grid_line_puts(col_off - 1, " ", 1, attr);
}
}
@@ -580,13 +580,13 @@ void pum_redraw(void)
size++;
}
}
- grid_puts_len(&pum_grid, rt, (int)strlen(rt), row, grid_col - size + 1, attr);
+ grid_line_puts(grid_col - size + 1, rt, -1, attr);
xfree(rt_start);
xfree(st);
grid_col -= width;
} else {
- // use grid_puts_len() to truncate the text
- grid_puts(&pum_grid, st, row, grid_col, attr);
+ // use grid_line_puts() to truncate the text
+ grid_line_puts(grid_col, st, -1, attr);
xfree(st);
grid_col += width;
}
@@ -597,11 +597,10 @@ void pum_redraw(void)
// Display two spaces for a Tab.
if (pum_rl) {
- grid_puts_len(&pum_grid, " ", 2, row, grid_col - 1,
- attr);
+ grid_line_puts(grid_col - 1, " ", 2, attr);
grid_col -= 2;
} else {
- grid_puts_len(&pum_grid, " ", 2, row, grid_col, attr);
+ grid_line_puts(grid_col, " ", 2, attr);
grid_col += 2;
}
totwidth += 2;
@@ -632,37 +631,31 @@ void pum_redraw(void)
}
if (pum_rl) {
- grid_fill(&pum_grid, row, row + 1, col_off - pum_base_width - n + 1,
- grid_col + 1, ' ', ' ', attr);
+ grid_line_fill(col_off - pum_base_width - n + 1, grid_col + 1, ' ', attr);
grid_col = col_off - pum_base_width - n + 1;
} else {
- grid_fill(&pum_grid, row, row + 1, grid_col,
- col_off + pum_base_width + n, ' ', ' ', attr);
+ grid_line_fill(grid_col, col_off + pum_base_width + n, ' ', attr);
grid_col = col_off + pum_base_width + n;
}
totwidth = pum_base_width + n;
}
if (pum_rl) {
- grid_fill(&pum_grid, row, row + 1, col_off - pum_width + 1, grid_col + 1,
- ' ', ' ', attr);
+ grid_line_fill(col_off - pum_width + 1, grid_col + 1, ' ', attr);
} else {
- grid_fill(&pum_grid, row, row + 1, grid_col, col_off + pum_width, ' ', ' ',
- attr);
+ grid_line_fill(grid_col, col_off + pum_width, ' ', attr);
}
if (pum_scrollbar > 0) {
if (pum_rl) {
- grid_putchar(&pum_grid, ' ', row, col_off - pum_width,
- i >= thumb_pos && i < thumb_pos + thumb_height
- ? attr_thumb : attr_scroll);
+ grid_line_puts(col_off - pum_width, " ", 1,
+ i >= thumb_pos && i < thumb_pos + thumb_height ? attr_thumb : attr_scroll);
} else {
- grid_putchar(&pum_grid, ' ', row, col_off + pum_width,
- i >= thumb_pos && i < thumb_pos + thumb_height
- ? attr_thumb : attr_scroll);
+ grid_line_puts(col_off + pum_width, " ", 1,
+ i >= thumb_pos && i < thumb_pos + thumb_height ? attr_thumb : attr_scroll);
}
}
- grid_puts_line_flush(false);
+ grid_line_flush(false);
row++;
}
}