diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-01-06 09:53:27 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-01-06 09:53:27 +0000 |
| commit | 3a9172342fd69c09d3fddfb26eba12dcbe1e5149 (patch) | |
| tree | 8fc6ff4bb902a56f9148cfa9fba1c454a2c3f2be | |
| parent | Merge branch 'extend-selection-by-word' (diff) | |
selection: combine enum selection_kind with selection_semantic
| -rw-r--r-- | extract.c | 8 | ||||
| -rw-r--r-- | input.c | 16 | ||||
| -rw-r--r-- | search.c | 4 | ||||
| -rw-r--r-- | selection.c | 44 | ||||
| -rw-r--r-- | selection.h | 3 | ||||
| -rw-r--r-- | terminal.h | 10 |
6 files changed, 47 insertions, 38 deletions
@@ -119,9 +119,7 @@ extract_one(const struct terminal *term, const struct row *row, if (ctx->last_row != NULL && row != ctx->last_row) { /* New row - determine if we should insert a newline or not */ - if (ctx->selection_kind == SELECTION_NONE || - ctx->selection_kind == SELECTION_NORMAL) - { + if (ctx->selection_kind != SELECTION_BLOCK) { if (ctx->last_row->linebreak || ctx->empty_count > 0 || cell->wc == 0) @@ -134,9 +132,7 @@ extract_one(const struct terminal *term, const struct row *row, ctx->newline_count++; ctx->empty_count = 0; } - } - - else if (ctx->selection_kind == SELECTION_BLOCK) { + } else { /* Always insert a linebreak */ if (!ensure_size(ctx, 1)) goto err; @@ -275,8 +275,7 @@ execute_binding(struct seat *seat, struct terminal *term, case BIND_ACTION_SELECT_BEGIN: if (selection_enabled(term, seat) && cursor_is_on_grid) { selection_start( - term, seat->mouse.col, seat->mouse.row, - SELECTION_NORMAL, SELECTION_SEMANTIC_NONE, false); + term, seat->mouse.col, seat->mouse.row, SELECTION_CHAR_WISE, false); return true; } return false; @@ -284,8 +283,7 @@ execute_binding(struct seat *seat, struct terminal *term, case BIND_ACTION_SELECT_BEGIN_BLOCK: if (selection_enabled(term, seat) && cursor_is_on_grid) { selection_start( - term, seat->mouse.col, seat->mouse.row, - SELECTION_BLOCK, SELECTION_SEMANTIC_NONE, false); + term, seat->mouse.col, seat->mouse.row, SELECTION_BLOCK, false); return true; } return false; @@ -301,8 +299,7 @@ execute_binding(struct seat *seat, struct terminal *term, case BIND_ACTION_SELECT_WORD: if (selection_enabled(term, seat) && cursor_is_on_grid) { selection_start( - term, seat->mouse.col, seat->mouse.row, - SELECTION_NORMAL, SELECTION_SEMANTIC_WORD, false); + term, seat->mouse.col, seat->mouse.row, SELECTION_WORD_WISE, false); return true; } return false; @@ -310,16 +307,15 @@ execute_binding(struct seat *seat, struct terminal *term, case BIND_ACTION_SELECT_WORD_WS: if (selection_enabled(term, seat) && cursor_is_on_grid) { selection_start( - term, seat->mouse.col, seat->mouse.row, - SELECTION_NORMAL, SELECTION_SEMANTIC_WORD, true); + term, seat->mouse.col, seat->mouse.row, SELECTION_WORD_WISE, true); return true; } return false; case BIND_ACTION_SELECT_ROW: if (selection_enabled(term, seat) && cursor_is_on_grid) { - selection_start(term, seat->mouse.col, seat->mouse.row, - SELECTION_NORMAL, SELECTION_SEMANTIC_ROW, false); + selection_start( + term, seat->mouse.col, seat->mouse.row, SELECTION_LINE_WISE, false); return true; } return false; @@ -222,8 +222,8 @@ search_update_selection(struct terminal *term, assert(selection_row >= 0 && selection_row < term->grid->num_rows); - selection_start(term, start_col, selection_row, - SELECTION_NORMAL, SELECTION_SEMANTIC_NONE, false); + selection_start( + term, start_col, selection_row, SELECTION_CHAR_WISE, false); } /* Update selection endpoint */ diff --git a/selection.c b/selection.c index f9642719..b115b219 100644 --- a/selection.c +++ b/selection.c @@ -194,7 +194,9 @@ foreach_selected( void *data) { switch (term->selection.kind) { - case SELECTION_NORMAL: + case SELECTION_CHAR_WISE: + case SELECTION_WORD_WISE: + case SELECTION_LINE_WISE: foreach_selected_normal(term, start, end, cb, data); return; @@ -385,23 +387,24 @@ find_word_boundary_right(struct terminal *term, struct coord *pos, void selection_start(struct terminal *term, int col, int row, enum selection_kind kind, - enum selection_semantic semantic, bool spaces_only) { selection_cancel(term); LOG_DBG("%s selection started at %d,%d", - kind == SELECTION_NORMAL ? "normal" : + kind == SELECTION_CHAR_WISE ? "character-wise" : + kind == SELECTION_WORD_WISE ? "word-wise" : + kind == SELECTION_LINE_WISE ? "line-wise" : kind == SELECTION_BLOCK ? "block" : "<unknown>", row, col); term->selection.kind = kind; - term->selection.semantic = semantic; term->selection.ongoing = true; term->selection.spaces_only = spaces_only; - switch (semantic) { - case SELECTION_SEMANTIC_NONE: + switch (kind) { + case SELECTION_CHAR_WISE: + case SELECTION_BLOCK: term->selection.start = (struct coord){col, term->grid->view + row}; term->selection.end = (struct coord){-1, -1}; @@ -409,7 +412,7 @@ selection_start(struct terminal *term, int col, int row, term->selection.pivot.end = term->selection.end; break; - case SELECTION_SEMANTIC_WORD: { + case SELECTION_WORD_WISE: { struct coord start = {col, row}, end = {col, row}; find_word_boundary_left(term, &start, spaces_only); find_word_boundary_right(term, &end, spaces_only); @@ -424,13 +427,17 @@ selection_start(struct terminal *term, int col, int row, break; } - case SELECTION_SEMANTIC_ROW: + case SELECTION_LINE_WISE: term->selection.start = (struct coord){0, term->grid->view + row}; term->selection.pivot.start = term->selection.start; term->selection.pivot.end = (struct coord){term->cols - 1, term->grid->view + row}; selection_update(term, term->cols - 1, row); break; + + case SELECTION_NONE: + assert(false); + break; } } @@ -470,7 +477,7 @@ premark_selected(struct terminal *term, struct row *row, struct cell *cell, ctx->empty_count = 0; } - if (cell->wc == 0 && term->selection.kind == SELECTION_NORMAL) { + if (cell->wc == 0 && term->selection.kind != SELECTION_BLOCK) { ctx->empty_count++; return true; } @@ -494,7 +501,7 @@ mark_selected(struct terminal *term, struct row *row, struct cell *cell, ctx->empty_count = 0; } - if (cell->wc == 0 && term->selection.kind == SELECTION_NORMAL) { + if (cell->wc == 0 && term->selection.kind != SELECTION_BLOCK) { ctx->empty_count++; return true; } @@ -658,11 +665,12 @@ selection_update(struct terminal *term, int col, int row) } } - switch (term->selection.semantic) { - case SELECTION_SEMANTIC_NONE: + switch (term->selection.kind) { + case SELECTION_CHAR_WISE: + case SELECTION_BLOCK: break; - case SELECTION_SEMANTIC_WORD: + case SELECTION_WORD_WISE: switch (term->selection.direction) { case SELECTION_LEFT: { struct coord end = {col, row}; @@ -683,7 +691,7 @@ selection_update(struct terminal *term, int col, int row) } break; - case SELECTION_SEMANTIC_ROW: + case SELECTION_LINE_WISE: switch (term->selection.direction) { case SELECTION_LEFT: new_end.col = 0; @@ -697,6 +705,10 @@ selection_update(struct terminal *term, int col, int row) break; } break; + + case SELECTION_NONE: + assert(false); + break; } size_t start_row_idx = new_start.row & (term->grid->num_rows - 1); @@ -885,7 +897,9 @@ selection_extend(struct seat *seat, struct terminal *term, assert(false); return; - case SELECTION_NORMAL: + case SELECTION_CHAR_WISE: + case SELECTION_WORD_WISE: + case SELECTION_LINE_WISE: selection_extend_normal(term, col, row, serial); break; diff --git a/selection.h b/selection.h index 21e983e8..c4d393e3 100644 --- a/selection.h +++ b/selection.h @@ -11,8 +11,7 @@ extern const struct zwp_primary_selection_device_v1_listener primary_selection_d bool selection_enabled(const struct terminal *term, struct seat *seat); void selection_start( struct terminal *term, int col, int row, - enum selection_kind kind, enum selection_semantic semantic, - bool spaces_only); + enum selection_kind new_kind, bool spaces_only); void selection_update(struct terminal *term, int col, int row); void selection_finalize( struct seat *seat, struct terminal *term, uint32_t serial); @@ -180,8 +180,13 @@ enum mouse_reporting { enum cursor_style { CURSOR_BLOCK, CURSOR_UNDERLINE, CURSOR_BAR }; -enum selection_kind { SELECTION_NONE, SELECTION_NORMAL, SELECTION_BLOCK }; -enum selection_semantic { SELECTION_SEMANTIC_NONE, SELECTION_SEMANTIC_WORD, SELECTION_SEMANTIC_ROW}; +enum selection_kind { + SELECTION_NONE, + SELECTION_CHAR_WISE, + SELECTION_WORD_WISE, + SELECTION_LINE_WISE, + SELECTION_BLOCK +}; enum selection_direction {SELECTION_UNDIR, SELECTION_LEFT, SELECTION_RIGHT}; enum selection_scroll_direction {SELECTION_SCROLL_NOT, SELECTION_SCROLL_UP, SELECTION_SCROLL_DOWN}; @@ -360,7 +365,6 @@ struct terminal { struct { enum selection_kind kind; - enum selection_semantic semantic; enum selection_direction direction; struct coord start; struct coord end; |
