Add word-and-line-from-point as a mouse selection action #6663
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello, this patch attempts to introduce a new selection mode called "word_and_line_from_point".
The behavior of this is to select the word under the cursor and then also out to the end of the line. It's functionally equivalent to using
word
andline_from_point
in sequence and taking the combined result. (The desire for this was previously described in #6363 .)It can be used in
kitty.conf
with a config line such as:I attempted to keep the diff as minimal as possible, and here's what is included:
MOUSE_SELECTION_WORD_AND_LINE_FROM_POINT
is added to mouse selection types in C and python bindings, so it's communicable from the config options layer.MOUSE_SELECTION_WORD_AND_LINE_FROM_POINT
inkitty/options/utils.py
function, so that string can be recognized in the config file.mouse.c
,mouse_selection
function gains a new case so it can forward theMOUSE_SELECTION_WORD_AND_LINE_FROM_POINT
action to thescreen_selection_*
functions.EXTEND_WORD_AND_LINE_FROM_POINT
is added to theSelectionExtendModes
enum in C, so our mode can be communicated to thescreen_*_selection
functions.screen_update_selection
gains a very small branch forEXTEND_WORD_AND_LINE_FROM_POINT
in the middle of the overallEXTEND_LINE
logic, which performs the search for word. If there's a word, the selection start moves to the start of the word. (If there's no word, the selection is made as it would be otherwise by regularEXTEND_LINE
, meaning it starts at the cursor.)kitty/options/definition.py
.I'm testing this manually and it seems to have the desired behavior. It works on normal lines; it works on long lines that wrapped; it works on the non-first rendered line of wrapped lines; it combines fine with extending selections. I've been driving it around for a few days now and encountered no surprising behavior.
I'm happy to accept any feedback about the feature name, or the code. I think it works, and I tried to keep the change minimal. But this is my first attempt to submit a patch to Kitty, and also the first time I've touched C code in many years, so I cannot guarantee it is perfect on the first pass. :) Thank you very much for your review!