Skip to content

Commit d4c42eb

Browse files
committed
skip copy in input/textarea if there is nothing to copy
1 parent c0e7fe3 commit d4c42eb

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/textual/widgets/_input.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from typing_extensions import Literal
1212

1313
from textual import events
14+
from textual.actions import SkipAction
1415
from textual.expand_tabs import expand_tabs_inline
1516
from textual.screen import Screen
1617
from textual.scroll_view import ScrollView
@@ -1106,7 +1107,11 @@ def action_cut(self) -> None:
11061107

11071108
def action_copy(self) -> None:
11081109
"""Copy the current selection to the clipboard."""
1109-
self.app.copy_to_clipboard(self.selected_text)
1110+
selected_text = self.selected_text
1111+
if selected_text:
1112+
self.app.copy_to_clipboard(selected_text)
1113+
else:
1114+
raise SkipAction()
11101115

11111116
def action_paste(self) -> None:
11121117
"""Paste from the local clipboard."""

src/textual/widgets/_text_area.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from textual._text_area_theme import TextAreaTheme
1818
from textual._tree_sitter import TREE_SITTER, get_language
19+
from textual.actions import SkipAction
1920
from textual.cache import LRUCache
2021
from textual.color import Color
2122
from textual.content import Content
@@ -2513,6 +2514,8 @@ def action_copy(self) -> None:
25132514
selected_text = self.selected_text
25142515
if selected_text:
25152516
self.app.copy_to_clipboard(selected_text)
2517+
else:
2518+
raise SkipAction()
25162519

25172520
def action_paste(self) -> None:
25182521
"""Paste from local clipboard."""

0 commit comments

Comments
 (0)