diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2019-07-17 19:30:57 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2019-07-17 19:30:57 +0000 |
| commit | 8bd969262b091b910560d183c57df5ee09805fbb (patch) | |
| tree | e7532d346ebddbf086467b1989763d88f65e628b /selection.c | |
| parent | selection: bug: apply grid's view offset when starting a selection (diff) | |
selection: implement double-click-to-select-word
Diffstat (limited to 'selection.c')
| -rw-r--r-- | selection.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/selection.c b/selection.c index 76b4d3dc..73a20b40 100644 --- a/selection.c +++ b/selection.c @@ -1,5 +1,6 @@ #include "selection.h" +#include <ctype.h> #include <string.h> #include <unistd.h> #include <fcntl.h> @@ -214,6 +215,74 @@ selection_cancel(struct terminal *term) } } +void +selection_mark_word(struct terminal *term, int col, int row, uint32_t serial) +{ + if (!selection_enabled(term)) + return; + + selection_cancel(term); + + struct coord start = {col, row}; + struct coord end = {col, row}; + + const struct row *r = grid_row_in_view(term->grid, start.row); + unsigned char c = r->cells[start.col].c[0]; + + if (!(c == '\0' || isspace(c))) { + while (true) { + int next_col = start.col - 1; + int next_row = start.row; + + /* Linewrap */ + if (next_col < 0) { + next_col = term->cols - 1; + if (--next_row < 0) + break; + } + + const struct row *row = grid_row_in_view(term->grid, next_row); + + unsigned char c = row->cells[next_col].c[0]; + if (c == '\0' || isspace(c)) + break; + + start.col = next_col; + start.row = next_row; + } + } + + r = grid_row_in_view(term->grid, end.row); + c = r->cells[end.col].c[0]; + + if (!(c == '\0' || isspace(c))) { + while (true) { + int next_col = end.col + 1; + int next_row = end.row; + + /* Linewrap */ + if (next_col >= term->cols) { + next_col = 0; + if (++next_row >= term->rows) + break; + } + + const struct row *row = grid_row_in_view(term->grid, next_row); + + unsigned char c = row->cells[next_col].c[0]; + if (c == '\0' || isspace(c)) + break; + + end.col = next_col; + end.row = next_row; + } + } + + selection_start(term, start.col, start.row); + selection_update(term, end.col, end.row); + selection_finalize(term, serial); +} + static void target(void *data, struct wl_data_source *wl_data_source, const char *mime_type) { |
