Skip to content

Commit f9c0aeb

Browse files
committed
Add copy_selection bindings
1 parent 9ff7cbc commit f9c0aeb

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/textual/widgets/_input.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class Input(ScrollView):
114114
"ctrl+f", "delete_right_word", "Delete right to start of word", show=False
115115
),
116116
Binding("ctrl+k", "delete_right_all", "Delete all to the right", show=False),
117+
Binding("ctrl+c", "copy_selection", "Copy selected text", show=False),
117118
]
118119
"""
119120
| Key(s) | Description |
@@ -990,3 +991,7 @@ async def action_submit(self) -> None:
990991
self.validate(self.value) if "submitted" in self.validate_on else None
991992
)
992993
self.post_message(self.Submitted(self, self.value, validation_result))
994+
995+
def action_copy_selection(self) -> None:
996+
"""Copy the current selection to the clipboard."""
997+
self.app.copy_to_clipboard(self.selected_text)

src/textual/widgets/_text_area.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ class TextArea(ScrollView):
238238
),
239239
Binding("ctrl+z", "undo", "Undo", show=False),
240240
Binding("ctrl+y", "redo", "Redo", show=False),
241+
Binding("ctrl+c", "copy_selection", "Copy selected text", show=False),
241242
]
242243
"""
243244
| Key(s) | Description |
@@ -2279,6 +2280,10 @@ def action_delete_word_right(self) -> None:
22792280

22802281
self._delete_via_keyboard(end, to_location)
22812282

2283+
def action_copy_selection(self) -> None:
2284+
"""Copy the current selection to the clipboard."""
2285+
self.app.copy_to_clipboard(self.selected_text)
2286+
22822287

22832288
@lru_cache(maxsize=128)
22842289
def build_byte_to_codepoint_dict(data: bytes) -> dict[int, int]:

0 commit comments

Comments
 (0)