aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-12-03 18:42:43 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-12-03 18:43:11 +0000
commit867cac4207aea464803729339c014024389c5b81 (patch)
tree19c66d8084fe05eee8b2c6c7f4fb5efc3f7c4074
parentsearch: split up search_update() into two (diff)
search: search_match_to_end_of_word: rename start_{row,col} -> end_{row,col}
-rw-r--r--search.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/search.c b/search.c
index 8ade6c88..03eae348 100644
--- a/search.c
+++ b/search.c
@@ -273,14 +273,14 @@ search_match_to_end_of_word(struct terminal *term)
assert(term->search.match.row != -1);
assert(term->search.match.col != -1);
- int start_row = term->search.match.row;
- int start_col = term->search.match.col;
+ int end_row = term->search.match.row;
+ int end_col = term->search.match.col;
size_t len = term->search.match_len;
/* Calculate end coord - note: assumed to be valid */
for (size_t i = 0; i < len; i++) {
- if (++start_col >= term->cols)
- start_row = (start_row + 1) % term->grid->num_rows;
+ if (++end_col >= term->cols)
+ end_row = (end_row + 1) % term->grid->num_rows;
}
tll(wchar_t) new_chars = tll_init();
@@ -290,15 +290,15 @@ search_match_to_end_of_word(struct terminal *term)
for (size_t r = 0;
r < term->grid->num_rows;
- start_row = (start_row + 1) % term->grid->num_rows, r++)
+ end_row = (end_row + 1) % term->grid->num_rows, r++)
{
- const struct row *row = term->grid->rows[start_row];
+ const struct row *row = term->grid->rows[end_row];
if (row == NULL)
break;
bool done = false;
- for (; start_col < term->cols; start_col++) {
- wchar_t wc = row->cells[start_col].wc;
+ for (; end_col < term->cols; end_col++) {
+ wchar_t wc = row->cells[end_col].wc;
if (wc == 0 || (!first && !isword(wc, false))) {
done = true;
break;
@@ -318,8 +318,10 @@ search_match_to_end_of_word(struct terminal *term)
if (!search_ensure_size(term, term->search.len + tll_length(new_chars)))
return;
+ /* Keep cursor at the end, but don't move it if not */
bool move_cursor = term->search.cursor == term->search.len;
+ /* Append newly found characters to the search buffer */
tll_foreach(new_chars, it)
term->search.buf[term->search.len++] = it->item;
term->search.buf[term->search.len] = L'\0';