mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-05-02 06:46:32 -04:00
search: match iterator: always return the primary match
Normally, the primary match is automatically included by the iterator, but if the secondary and primary matches overlap, it is possible we don’t return the _actual_ primary match. This lead to highlighting issues, where part of the primary match wasn’t highlighted correctly.
This commit is contained in:
parent
c5519e2aa6
commit
3905212651
1 changed files with 36 additions and 17 deletions
53
search.c
53
search.c
|
|
@ -409,7 +409,7 @@ search_find_next(struct terminal *term)
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DBG(
|
LOG_DBG(
|
||||||
"search: update: %s: starting at row=%d col=%d "
|
"update: %s: starting at row=%d col=%d "
|
||||||
"(offset = %d, view = %d)",
|
"(offset = %d, view = %d)",
|
||||||
backward ? "backward" : "forward", start_row, start_col,
|
backward ? "backward" : "forward", start_row, start_col,
|
||||||
grid->offset, grid->view);
|
grid->offset, grid->view);
|
||||||
|
|
@ -419,11 +419,9 @@ search_find_next(struct terminal *term)
|
||||||
term, direction, start_row, start_col, grid->num_rows, &match);
|
term, direction, start_row, start_col, grid->num_rows, &match);
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
|
LOG_DBG("primary match found at %dx%d",
|
||||||
|
match.start.row, match.start.col);
|
||||||
search_update_selection(term, &match);
|
search_update_selection(term, &match);
|
||||||
#if 0
|
|
||||||
match.start.row, match.start.col,
|
|
||||||
match.end.row, match.end.col + 1);
|
|
||||||
#endif
|
|
||||||
term->search.match = match.start;
|
term->search.match = match.start;
|
||||||
term->search.match_len = term->search.len;
|
term->search.match_len = term->search.len;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -440,16 +438,13 @@ search_matches_new_iter(struct terminal *term)
|
||||||
{
|
{
|
||||||
return (struct search_match_iterator){
|
return (struct search_match_iterator){
|
||||||
.term = term,
|
.term = term,
|
||||||
.start = {0, 0},
|
.start = {-2, -2},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
struct range
|
struct range
|
||||||
search_matches_next(struct search_match_iterator *iter)
|
search_matches_next(struct search_match_iterator *iter)
|
||||||
{
|
{
|
||||||
xassert(iter->start.row >= 0);
|
|
||||||
xassert(iter->start.col >= 0);
|
|
||||||
|
|
||||||
struct terminal *term = iter->term;
|
struct terminal *term = iter->term;
|
||||||
struct grid *grid = term->grid;
|
struct grid *grid = term->grid;
|
||||||
|
|
||||||
|
|
@ -457,11 +452,22 @@ search_matches_next(struct search_match_iterator *iter)
|
||||||
goto no_match;
|
goto no_match;
|
||||||
|
|
||||||
struct range match;
|
struct range match;
|
||||||
bool found = find_next(
|
bool found;
|
||||||
term, SEARCH_FORWARD,
|
|
||||||
grid_row_absolute_in_view(grid, iter->start.row),
|
const bool return_primary_match =
|
||||||
iter->start.col,
|
iter->start.row == -2 && term->selection.coords.end.row >= 0;
|
||||||
term->rows - iter->start.row, &match);
|
|
||||||
|
if (return_primary_match) {
|
||||||
|
/* First, return the primary match */
|
||||||
|
match = term->selection.coords;
|
||||||
|
found = true;
|
||||||
|
} else {
|
||||||
|
found = find_next(
|
||||||
|
term, SEARCH_FORWARD,
|
||||||
|
grid_row_absolute_in_view(grid, iter->start.row),
|
||||||
|
iter->start.col,
|
||||||
|
term->rows - iter->start.row, &match);
|
||||||
|
}
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
LOG_DBG("match at %dx%d-%dx%d",
|
LOG_DBG("match at %dx%d-%dx%d",
|
||||||
|
|
@ -474,9 +480,22 @@ search_matches_next(struct search_match_iterator *iter)
|
||||||
match.end.row = match.end.row - grid->view + grid->num_rows;
|
match.end.row = match.end.row - grid->view + grid->num_rows;
|
||||||
match.end.row &= grid->num_rows - 1;
|
match.end.row &= grid->num_rows - 1;
|
||||||
|
|
||||||
/* Continue at next column, next time */
|
if (return_primary_match) {
|
||||||
iter->start.row = match.end.row;
|
iter->start.row = 0;
|
||||||
iter->start.col = match.end.col + 1;
|
iter->start.col = 0;
|
||||||
|
} else {
|
||||||
|
/* Continue at next column, next time */
|
||||||
|
iter->start.row = match.end.row;
|
||||||
|
iter->start.col = match.end.col + 1;
|
||||||
|
|
||||||
|
if (match.start.row == term->search.match.row &&
|
||||||
|
match.start.col == term->search.match.col)
|
||||||
|
{
|
||||||
|
/* Primary match is handled explicitly */
|
||||||
|
LOG_DBG("primary match: skipping");
|
||||||
|
return search_matches_next(iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue