mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-05 01:40:41 -05:00
search: make search-direction configurable
This commit is contained in:
parent
42714c51a9
commit
556bf95b28
2 changed files with 24 additions and 7 deletions
30
search.c
30
search.c
|
|
@ -63,6 +63,9 @@ search_cancel(struct terminal *term)
|
||||||
static void
|
static void
|
||||||
search_update(struct terminal *term)
|
search_update(struct terminal *term)
|
||||||
{
|
{
|
||||||
|
bool backward = term->search.direction == SEARCH_BACKWARD;
|
||||||
|
term->search.direction = SEARCH_BACKWARD;
|
||||||
|
|
||||||
if (term->search.len == 0) {
|
if (term->search.len == 0) {
|
||||||
term->search.match = (struct coord){-1, -1};
|
term->search.match = (struct coord){-1, -1};
|
||||||
term->search.match_len = 0;
|
term->search.match_len = 0;
|
||||||
|
|
@ -78,23 +81,36 @@ search_update(struct terminal *term)
|
||||||
(len > 0 && start_row >= 0 && start_col >= 0));
|
(len > 0 && start_row >= 0 && start_col >= 0));
|
||||||
|
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
start_row = grid_row_absolute_in_view(term->grid, term->rows - 1);
|
if (backward) {
|
||||||
start_col = term->cols - 1;
|
start_row = grid_row_absolute_in_view(term->grid, term->rows - 1);
|
||||||
|
start_col = term->cols - 1;
|
||||||
|
} else {
|
||||||
|
start_row = grid_row_absolute_in_view(term->grid, 0);
|
||||||
|
start_col = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DBG("search: update: starting at row=%d col=%d (offset = %d, view = %d)",
|
LOG_DBG("search: update: %s: starting at row=%d col=%d (offset = %d, view = %d)",
|
||||||
start_row, start_col, term->grid->offset, term->grid->view);
|
backward ? "backward" : "forward", start_row, start_col,
|
||||||
|
term->grid->offset, term->grid->view);
|
||||||
|
|
||||||
#define ROW_DEC(_r) ((_r) = ((_r) - 1 + term->grid->num_rows) % term->grid->num_rows)
|
#define ROW_DEC(_r) ((_r) = ((_r) - 1 + term->grid->num_rows) % term->grid->num_rows)
|
||||||
|
#define ROW_INC(_r) ((_r) = ((_r) + 1) % term->grid->num_rows)
|
||||||
|
|
||||||
/* Scan backward from current end-of-output */
|
/* Scan backward from current end-of-output */
|
||||||
/* TODO: don't search "scrollback" in alt screen? */
|
/* TODO: don't search "scrollback" in alt screen? */
|
||||||
for (size_t r = 0; r < term->grid->num_rows; ROW_DEC(start_row), r++) {
|
for (size_t r = 0;
|
||||||
|
r < term->grid->num_rows;
|
||||||
|
backward ? ROW_DEC(start_row) : ROW_INC(start_row), r++)
|
||||||
|
{
|
||||||
const struct row *row = term->grid->rows[start_row];
|
const struct row *row = term->grid->rows[start_row];
|
||||||
if (row == NULL)
|
if (row == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (; start_col >= 0; start_col--) {
|
for (;
|
||||||
|
backward ? start_col >= 0 : start_col < term->cols;
|
||||||
|
backward ? start_col-- : start_col++)
|
||||||
|
{
|
||||||
if (wcsncasecmp(&row->cells[start_col].wc, term->search.buf, 1) != 0)
|
if (wcsncasecmp(&row->cells[start_col].wc, term->search.buf, 1) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
@ -207,7 +223,7 @@ search_update(struct terminal *term)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
start_col = term->cols - 1;
|
start_col = backward ? term->cols - 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No match */
|
/* No match */
|
||||||
|
|
|
||||||
|
|
@ -353,6 +353,7 @@ struct terminal {
|
||||||
size_t len;
|
size_t len;
|
||||||
size_t sz;
|
size_t sz;
|
||||||
size_t cursor;
|
size_t cursor;
|
||||||
|
enum { SEARCH_BACKWARD, SEARCH_FORWARD} direction;
|
||||||
|
|
||||||
int original_view;
|
int original_view;
|
||||||
bool view_followed_offset;
|
bool view_followed_offset;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue