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.
This commit is contained in:
Daniel Eklöf 2021-01-06 11:11:46 +01:00
parent 2e46811953
commit 767bd4f1db
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
8 changed files with 65 additions and 18 deletions

View file

@ -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

View file

@ -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);

View file

@ -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_.

View file

@ -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

12
input.c
View file

@ -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;

View file

@ -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;
}
}

View file

@ -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);

View file

@ -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,