skip copy in input/textarea if there is nothing to copy

This commit is contained in:
Will McGugan
2025-10-01 15:51:48 +01:00
parent c0e7fe3315
commit d4c42eb79d
2 changed files with 9 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ from rich.text import Text
from typing_extensions import Literal
from textual import events
from textual.actions import SkipAction
from textual.expand_tabs import expand_tabs_inline
from textual.screen import Screen
from textual.scroll_view import ScrollView
@@ -1106,7 +1107,11 @@ class Input(ScrollView):
def action_copy(self) -> None:
"""Copy the current selection to the clipboard."""
self.app.copy_to_clipboard(self.selected_text)
selected_text = self.selected_text
if selected_text:
self.app.copy_to_clipboard(selected_text)
else:
raise SkipAction()
def action_paste(self) -> None:
"""Paste from the local clipboard."""

View File

@@ -16,6 +16,7 @@ from typing_extensions import Literal
from textual._text_area_theme import TextAreaTheme
from textual._tree_sitter import TREE_SITTER, get_language
from textual.actions import SkipAction
from textual.cache import LRUCache
from textual.color import Color
from textual.content import Content
@@ -2513,6 +2514,8 @@ TextArea {
selected_text = self.selected_text
if selected_text:
self.app.copy_to_clipboard(selected_text)
else:
raise SkipAction()
def action_paste(self) -> None:
"""Paste from local clipboard."""