Skip to content

Map same click to different action depending on if text is selected #7920

Answered by gabrielfrimodig
ozmodeuz asked this question in Q&A
Discussion options

You must be logged in to vote

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:

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

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@ozmodeuz
Comment options

Answer selected by ozmodeuz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants