aboutsummaryrefslogtreecommitdiff
path: root/selection.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-01-06 10:11:46 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-01-14 15:29:29 +0000
commit767bd4f1dbbb14d9d28acb22cf42a91e6305a69a (patch)
tree6c79ade4d1100b0d6d14eaff0c89145320f3996a /selection.c
parentMerge branch 'sixel-current-geometry-response' (diff)
config: add ‘select-extend-character-wise’ bind action
This forces the (new) selection mode to be character-wise when extending a word- or line-wise selection. Default key binding is ctrl+RMB.
Diffstat (limited to 'selection.c')
-rw-r--r--selection.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/selection.c b/selection.c
index de8b06e7..7422b095 100644
--- a/selection.c
+++ b/selection.c
@@ -783,7 +783,8 @@ selection_dirty_cells(struct terminal *term)
}
static void
-selection_extend_normal(struct terminal *term, int col, int row, uint32_t serial)
+selection_extend_normal(struct terminal *term, int col, int row,
+ enum selection_kind new_kind)
{
const struct coord *start = &term->selection.start;
const struct coord *end = &term->selection.end;
@@ -839,10 +840,14 @@ selection_extend_normal(struct terminal *term, int col, int row, uint32_t serial
switch (term->selection.kind) {
case SELECTION_CHAR_WISE:
+ assert(new_kind == SELECTION_CHAR_WISE);
set_pivot_point_for_block_and_char_wise(term, new_start, direction);
break;
case SELECTION_WORD_WISE: {
+ assert(new_kind == SELECTION_CHAR_WISE ||
+ new_kind == SELECTION_WORD_WISE);
+
struct coord pivot_start = {new_start.col, new_start.row - term->grid->view};
struct coord pivot_end = pivot_start;
@@ -857,6 +862,9 @@ selection_extend_normal(struct terminal *term, int col, int row, uint32_t serial
}
case SELECTION_LINE_WISE:
+ assert(new_kind == SELECTION_CHAR_WISE ||
+ new_kind == SELECTION_LINE_WISE);
+
term->selection.pivot.start = (struct coord){0, new_start.row};
term->selection.pivot.end = (struct coord){term->cols - 1, new_start.row};
break;
@@ -867,12 +875,13 @@ selection_extend_normal(struct terminal *term, int col, int row, uint32_t serial
break;
}
+ term->selection.kind = new_kind;
term->selection.direction = direction;
selection_modify(term, new_start, new_end);
}
static void
-selection_extend_block(struct terminal *term, int col, int row, uint32_t serial)
+selection_extend_block(struct terminal *term, int col, int row)
{
const struct coord *start = &term->selection.start;
const struct coord *end = &term->selection.end;
@@ -941,13 +950,16 @@ selection_extend_block(struct terminal *term, int col, int row, uint32_t serial)
void
selection_extend(struct seat *seat, struct terminal *term,
- int col, int row, uint32_t serial)
+ int col, int row, enum selection_kind new_kind)
{
if (term->selection.start.row < 0 || term->selection.end.row < 0) {
/* No existing selection */
return;
}
+ if (term->selection.kind == SELECTION_BLOCK && new_kind != SELECTION_BLOCK)
+ return;
+
term->selection.ongoing = true;
row += term->grid->view;
@@ -967,11 +979,11 @@ selection_extend(struct seat *seat, struct terminal *term,
case SELECTION_CHAR_WISE:
case SELECTION_WORD_WISE:
case SELECTION_LINE_WISE:
- selection_extend_normal(term, col, row, serial);
+ selection_extend_normal(term, col, row, new_kind);
break;
case SELECTION_BLOCK:
- selection_extend_block(term, col, row, serial);
+ selection_extend_block(term, col, row);
break;
}
}