Skip to content
Discussion options

You must be logged in to vote

I think I understand the confusion now. The query_one method just gets a widget, it doesn't know what widget is currently focused.

You could check if the TextArea is focused like @Zaloog suggested.

But actually if this binding shouldn't do anything if a different type of widget is focused, wouldn't it make more sense to add the binding to the TextArea, rather than the App?

class TextAreaWithCopyPaste(TextArea):
    BINDINGS = [
        Binding("ctrl+p", "copy_to_clipboard"),
        Binding("ctrl+v", "paste_from_clipboard"),
    ]

    def action_copy_to_clipboard(self) -> None:
        text_to_copy = self.selected_text
        # etc...

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@Tim-Cao
Comment options

@Zaloog
Comment options

@Tim-Cao
Comment options

@TomJGooding
Comment options

Answer selected by Tim-Cao
@davep
Comment options

@Tim-Cao
Comment options

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