selection: add support for selecting the contents of a quote

This patch changes the default of triple clicking, from selecting the
current logical row, to first trying to select the contents of the
quote under the cursor, and if failing to find a quote, selecting the
current row (like before).

This is implemented by adding a new key binding, 'select-quote'.

It will search for surrounding quote characters, and if one is found
on each side of the cursor, the quote is selected. If not, the entire
row is selected instead.

Subsequent selection operations will behave as if the selection is
either a word selection (a quote was found), or a row selection (no
quote found).

Escaped quote characters are not supported: "foo \" bar" will match
'foo \', and not 'foo " bar'.

Mismatched quotes are not custom handled. They will simply not match.

Nested quotes ("123 'abc def' 456") are supported.

Closes #1364
This commit is contained in:
Daniel Eklöf 2023-09-19 16:23:34 +02:00
parent fe7aa25ad8
commit 1719ff93a7
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
8 changed files with 199 additions and 17 deletions

View file

@ -1101,10 +1101,37 @@ actions listed under *key-bindings* can be used here as well.
selection_, when the button is released. Default:
_Control+BTN\_LEFT-2_.
*select-quote*
Begin an interactive "quote" selection. This is similar to
*select-word*, except an entire quote is selected (that is,
everything inside the quote, excluding the quote
characters). Recognized quote characters are: *"* and *'*.
If a complete quote cannot be found on the current logical row
(only one quote character, or none are found), the entire row is
selected.
The selection is finalized, and copied to the _primary selection_,
when the button is released.
After the initial selection has been made, it behaves like a
normal word, or row selection, depending on whether a quote was
found or not. This affects what happens when, for example,
extending the selection.
Notes:
- Escaped quote characters are not supported (*"foo \\"bar"* will
match *'foo \\'*, not *'foo "bar'*).
- Foot does not try to handle mismatched quote characters; they
will simply not match.
- Nested quotes (using different quote characters) are supported.
Default: _BTN\_LEFT-3_.
*select-row*
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_.
is released. Default: _BTN\_LEFT-4_.
*select-extend*
Interactively extend an existing selection, using the original