Skip to content

Commit

Permalink
Add copy_selection bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Dec 5, 2024
1 parent 9ff7cbc commit f9c0aeb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/textual/widgets/_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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)
5 changes: 5 additions & 0 deletions src/textual/widgets/_text_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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]:
Expand Down

0 comments on commit f9c0aeb

Please sign in to comment.