Skip to content

Add word-and-line-from-point as a mouse selection action #6663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

warpfork
Copy link
Contributor

@warpfork warpfork commented Oct 2, 2023

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 and line_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:

mouse_map left triplepress ungrabbed mouse_selection word_and_line_from_point

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.
  • the string "line_from_word" is mapped to MOUSE_SELECTION_WORD_AND_LINE_FROM_POINT in kitty/options/utils.py function, so that string can be recognized in the config file.
  • in mouse.c, mouse_selection function gains a new case so it can forward the MOUSE_SELECTION_WORD_AND_LINE_FROM_POINT action to the screen_selection_* functions.
  • EXTEND_WORD_AND_LINE_FROM_POINT is added to the SelectionExtendModes enum in C, so our mode can be communicated to the screen_*_selection functions.
  • screen_update_selection gains a very small branch for EXTEND_WORD_AND_LINE_FROM_POINT in the middle of the overall EXTEND_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 regular EXTEND_LINE, meaning it starts at the cursor.)
  • documentation added in 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!

@kovidgoyal
Copy link
Owner

At a quick glance it looks fine. Some comments:

  1. Add some docs to options/definition.py -- wherever line_from_point is used to its docs add a sentence saying that one can instead use word_and_line_from_point to have it select the word under the cursor and extend to end of line

  2. rename line_from_word to something like word_and_line_from_point

I'll review in detail after you make these changes.

@warpfork
Copy link
Contributor Author

warpfork commented Oct 5, 2023

That's a much better name, thanks. Rebased to that.

Brief docs also added to definition.py.

@warpfork warpfork force-pushed the mouse-selection-line-from-word-feature branch from f0eff96 to d310acc Compare October 5, 2023 15:48
@warpfork warpfork changed the title Add line-from-word as a mouse selection action Add word-and-line-from-point as a mouse selection action Oct 5, 2023
@warpfork warpfork force-pushed the mouse-selection-line-from-word-feature branch from 4092b34 to f0eff96 Compare October 5, 2023 15:55
@kovidgoyal kovidgoyal merged commit baa0270 into kovidgoyal:master Oct 6, 2023
@warpfork warpfork deleted the mouse-selection-line-from-word-feature branch October 6, 2023 09:47
@warpfork
Copy link
Contributor Author

warpfork commented Oct 7, 2023

🎉 🤩 💃 Thank you!! This made my day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants