aboutsummaryrefslogtreecommitdiff
path: root/render.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2022-04-09 15:57:29 +0000
committerDaniel Eklöf <daniel@ekloef.se>2022-04-16 17:26:20 +0000
commit90c91d61482920881bb0c1ecf4babc001b3f598d (patch)
tree5063baa37da6ad2e308298479b76d8bbac71236f /render.c
parentrender: implement ‘flash’ and search mode’s ‘dimming’ with a sub-surface (diff)
search/render: initial support for highlighting all visible matches
Before this patch, only the currently “selected” match was highlighted (by having the “selected” attribute, and by *not* dimming it, like the rest of the grid during a scrollback search). With this patch, we now highlight matches within the viewport. While searching, only the “primary” match is searched-for, and tracked. Then, when rendering a frame, we find all “secondary” matches as well. “holes” are added to the search-mode overlay by the means of an search-match iterator. The iterator’s text matching logic is *very* similar to what we do when the search criteria has been updated, and we re-search the scrollback. It should be possible to refactor this, and share code.
Diffstat (limited to 'render.c')
-rw-r--r--render.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/render.c b/render.c
index 8093b747..5a05e354 100644
--- a/render.c
+++ b/render.c
@@ -35,6 +35,7 @@
#include "hsl.h"
#include "ime.h"
#include "quirks.h"
+#include "search.h"
#include "selection.h"
#include "shm.h"
#include "sixel.h"
@@ -1539,17 +1540,30 @@ render_overlay(struct terminal *term)
pixman_region32_clear(see_through);
- struct grid *grid = term->grid;
- for (int r = 0; r < term->rows; r++) {
- struct row *row = grid_row_in_view(grid, r);
- int y = term->margins.top + r * term->cell_height;
- for (int c = 0; c < term->cols; c++) {
- if (row->cells[c].attrs.selected) {
- int x = term->margins.left + c * term->cell_width;
- pixman_region32_union_rect(
- see_through, see_through,
- x, y, term->cell_width, term->cell_height);
- }
+ struct search_match_iterator iter = search_matches_new_iter(term);
+
+ for (struct range match = search_matches_next(&iter);
+ match.start.row >= 0;
+ match = search_matches_next(&iter))
+ {
+ int r = match.start.row;
+ int start_col = match.start.col;
+ const int end_row = match.end.row;
+
+ while (true) {
+ const int end_col =
+ r == end_row ? match.end.col : term->cols - 1;
+
+ int x = term->margins.left + start_col * term->cell_width;
+ int y = term->margins.top + r * term->cell_height;
+ int width = (end_col + 1 - start_col) * term->cell_width;
+ int height = 1 * term->cell_height;
+
+ pixman_region32_union_rect(
+ see_through, see_through, x, y, width, height);
+
+ if (++r > end_row)
+ break;
}
}