aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--CHANGELOG.md4
-rw-r--r--config.c2
-rw-r--r--doc/foot.ini.5.scd36
-rw-r--r--foot.ini1
-rw-r--r--input.c12
-rw-r--r--selection.c22
-rw-r--r--selection.h5
-rw-r--r--wayland.h1
8 files changed, 65 insertions, 18 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4245280e..21baf89b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -34,6 +34,8 @@
`vertical-letter-offset` to `foot.ini`. These options let you tweak
cell size and glyph positioning
(https://codeberg.org/dnkl/foot/issues/244).
+* Key/mouse binding `select-extend-character-wise`, which forces the
+ selection mode to 'character-wise' when extending a selection.
### Changed
@@ -49,6 +51,8 @@
word- or line-wise (https://codeberg.org/dnkl/foot/issues/267).
* The line thickness of box drawing characters now depend on the font
size (https://codeberg.org/dnkl/foot/issues/281).
+* Extending a word/line-wise selection now uses the original selection
+ mode instead of switching to character-wise.
### Deprecated
diff --git a/config.c b/config.c
index fb424218..06691545 100644
--- a/config.c
+++ b/config.c
@@ -80,6 +80,7 @@ static const char *const binding_action_map[] = {
[BIND_ACTION_SELECT_BEGIN] = "select-begin",
[BIND_ACTION_SELECT_BEGIN_BLOCK] = "select-begin-block",
[BIND_ACTION_SELECT_EXTEND] = "select-extend",
+ [BIND_ACTION_SELECT_EXTEND_CHAR_WISE] = "select-extend-character-wise",
[BIND_ACTION_SELECT_WORD] = "select-word",
[BIND_ACTION_SELECT_WORD_WS] = "select-word-whitespace",
[BIND_ACTION_SELECT_ROW] = "select-row",
@@ -2026,6 +2027,7 @@ add_default_mouse_bindings(struct config *conf)
add_binding(BIND_ACTION_SELECT_BEGIN, none, BTN_LEFT, 1);
add_binding(BIND_ACTION_SELECT_BEGIN_BLOCK, ctrl, BTN_LEFT, 1);
add_binding(BIND_ACTION_SELECT_EXTEND, none, BTN_RIGHT, 1);
+ add_binding(BIND_ACTION_SELECT_EXTEND_CHAR_WISE, ctrl, BTN_RIGHT, 1);
add_binding(BIND_ACTION_SELECT_WORD, none, BTN_LEFT, 2);
add_binding(BIND_ACTION_SELECT_WORD_WS, ctrl, BTN_LEFT, 2);
add_binding(BIND_ACTION_SELECT_ROW, none, BTN_LEFT, 3);
diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd
index a857df10..16fd270b 100644
--- a/doc/foot.ini.5.scd
+++ b/doc/foot.ini.5.scd
@@ -581,21 +581,37 @@ All actions listed under *key-bindings* can be user here as well.
and copied to the _primary selection_, when the button is
released. Default: _Control+BTN\_LEFT_.
-*select-extend*
- Interactively extend an existing selection. The selection is
- finalized, and copied to the _primary selection_, when the button
- is released. Default: _BTN\_RIGHT_.
-
*select-word*
- Select the _word_ (separated by spaces, period, comma, parenthesis
- etc) under the pointer. Default: _BTN\_LEFT-2_.
+ Begin an interactive word-wise selection, where words are
+ separated by whitespace and all characters defined by the
+ *word-delimiters* option. The selection is finalized, and copied
+ to the _primary selection_, when the button is released. Default:
+ _BTN\_LEFT-2_.
*select-word-whitespace*
- Select the _word_ (separated by spaces _only_) under the
- pointer. Default: Control+_BTN\_LEFT-2_.
+ Same as *select-word*, but the characters in the *word-delimiters*
+ option are ignored. I.e only whitespace characters act as
+ delimiters. The selection is finalized, and copied to the _primary
+ selection_, when the button is released. Default:
+ _Control+_BTN\_LEFT-2_.
*select-row*
- Select the whole row under the pointer. Default: _BTN\_LEFT-3_.
+ Begin an interactive row-wise selection. The selection is
+ finalized, and copied to the _primary selection_, when the button
+ is released. Default: _BTN\_LEFT-3_.
+
+*select-extend*
+ Interactively extend an existing selection, using the original
+ selection mode (normal, block, word-wise or row-wise). The
+ selection is finalized, and copied to the _primary selection_,
+ when the button is released. Default: _BTN\_RIGHT_.
+
+*select-extend-character-wise*
+ Same as *select-extend*, but forces the selection mode to _normal_
+ (i.e. character wise). Note that this causes subsequent
+ *select-extend* operations to be character wise. This action is
+ ignored for block selections. Default: _Control+BTN\_RIGHT_.
+
*primary-paste*
Pastes from the _primary selection_. Default: _BTN\_MIDDLE_.
diff --git a/foot.ini b/foot.ini
index f13d8e63..3cff1842 100644
--- a/foot.ini
+++ b/foot.ini
@@ -119,6 +119,7 @@
# select-begin=BTN_LEFT
# select-begin-block=Control+BTN_LEFT
# select-extend=BTN_RIGHT
+# select-extend-character-wise=Control+BTN_RIGHT
# select-word=BTN_LEFT-2
# select-word-whitespace=Control+BTN_LEFT-2
# select-row=BTN_LEFT-3
diff --git a/input.c b/input.c
index 3e8019e8..33127afd 100644
--- a/input.c
+++ b/input.c
@@ -291,7 +291,17 @@ execute_binding(struct seat *seat, struct terminal *term,
case BIND_ACTION_SELECT_EXTEND:
if (selection_enabled(term, seat) && cursor_is_on_grid) {
selection_extend(
- seat, term, seat->mouse.col, seat->mouse.row, serial);
+ seat, term, seat->mouse.col, seat->mouse.row, term->selection.kind);
+ return true;
+ }
+ return false;
+
+ case BIND_ACTION_SELECT_EXTEND_CHAR_WISE:
+ if (selection_enabled(term, seat) && cursor_is_on_grid &&
+ term->selection.kind != SELECTION_BLOCK)
+ {
+ selection_extend(
+ seat, term, seat->mouse.col, seat->mouse.row, SELECTION_CHAR_WISE);
return true;
}
return false;
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;
}
}
diff --git a/selection.h b/selection.h
index c4d393e3..aa027d3e 100644
--- a/selection.h
+++ b/selection.h
@@ -17,8 +17,9 @@ void selection_finalize(
struct seat *seat, struct terminal *term, uint32_t serial);
void selection_dirty_cells(struct terminal *term);
void selection_cancel(struct terminal *term);
-void selection_extend( struct seat *seat, struct terminal *term,
- int col, int row, uint32_t serial);
+void selection_extend(
+ struct seat *seat, struct terminal *term,
+ int col, int row, enum selection_kind kind);
bool selection_on_rows(const struct terminal *term, int start, int end);
diff --git a/wayland.h b/wayland.h
index 93244353..5ebc8a7e 100644
--- a/wayland.h
+++ b/wayland.h
@@ -54,6 +54,7 @@ enum bind_action_normal {
BIND_ACTION_SELECT_BEGIN,
BIND_ACTION_SELECT_BEGIN_BLOCK,
BIND_ACTION_SELECT_EXTEND,
+ BIND_ACTION_SELECT_EXTEND_CHAR_WISE,
BIND_ACTION_SELECT_WORD,
BIND_ACTION_SELECT_WORD_WS,
BIND_ACTION_SELECT_ROW,