Map same click to different action depending on if text is selected #7920
-
I'd like to map right-click to either copy text (if any is selected) or otherwise to paste. Is that doable? I've tried a few things but the nearest I've got is that copy and paste both fire on the same click at the same time... |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Note; I don't want copy_on_select enabled. I want to have to explicitly right-click a selection to copy it, and then right-click again to paste. Essentially I want to either do...
...or...
...depending on whether anything is selected. |
Beta Was this translation helpful? Give feedback.
-
Write a kitten that does what you want and then map it, look at the
builtin copy_or_interrupt action for an example of how to implement the
kitten.
|
Beta Was this translation helpful? Give feedback.
-
Interesting idea! I really liked that one. Here's a solution that worked for me: Create a script named from kittens.tui.handler import result_handler
def main(args):
pass
@result_handler(no_ui=True)
def handle_result(args, answer, target_window_id, boss):
window = boss.window_id_map.get(target_window_id)
if window is None:
return
if window.text_for_selection():
# Text is selected, perform copy
window.copy_to_clipboard()
else:
# No text selected, perform paste
boss.paste_from_clipboard()
return
handle_result.no_ui = True Then add it to your kitty.conf file:
This solution allows right-click to copy when text is selected, and paste when no text is selected. |
Beta Was this translation helpful? Give feedback.
Interesting idea! I really liked that one. Here's a solution that worked for me:
Create a script named
paste_handler.py
in your kitty configuration directory (in my case~/.config/kitty/
) with the following: