diff --git a/src/textual/widgets/_input.py b/src/textual/widgets/_input.py index 5665591975..126bf9da1c 100644 --- a/src/textual/widgets/_input.py +++ b/src/textual/widgets/_input.py @@ -114,6 +114,7 @@ class Input(ScrollView): "ctrl+f", "delete_right_word", "Delete right to start of word", show=False ), Binding("ctrl+k", "delete_right_all", "Delete all to the right", show=False), + Binding("ctrl+c", "copy_selection", "Copy selected text", show=False), ] """ | Key(s) | Description | @@ -990,3 +991,7 @@ async def action_submit(self) -> None: self.validate(self.value) if "submitted" in self.validate_on else None ) self.post_message(self.Submitted(self, self.value, validation_result)) + + def action_copy_selection(self) -> None: + """Copy the current selection to the clipboard.""" + self.app.copy_to_clipboard(self.selected_text) diff --git a/src/textual/widgets/_text_area.py b/src/textual/widgets/_text_area.py index e498210336..2b68efbc60 100644 --- a/src/textual/widgets/_text_area.py +++ b/src/textual/widgets/_text_area.py @@ -238,6 +238,7 @@ class TextArea(ScrollView): ), Binding("ctrl+z", "undo", "Undo", show=False), Binding("ctrl+y", "redo", "Redo", show=False), + Binding("ctrl+c", "copy_selection", "Copy selected text", show=False), ] """ | Key(s) | Description | @@ -2279,6 +2280,10 @@ def action_delete_word_right(self) -> None: self._delete_via_keyboard(end, to_location) + def action_copy_selection(self) -> None: + """Copy the current selection to the clipboard.""" + self.app.copy_to_clipboard(self.selected_text) + @lru_cache(maxsize=128) def build_byte_to_codepoint_dict(data: bytes) -> dict[int, int]: