Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Dec 6, 2024
1 parent e723ca2 commit b2bc4c9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
8 changes: 2 additions & 6 deletions src/textual/widgets/_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,9 +999,7 @@ async def action_submit(self) -> None:

def action_cut(self) -> None:
"""Cut the current selection (copy to clipboard and remove from input)."""
start, end = sorted(self.selection)
text = self.value[start:end]
self.app.copy_to_clipboard(text)
self.app.copy_to_clipboard(self.selected_text)
self.delete_selection()

def action_copy(self) -> None:
Expand All @@ -1012,6 +1010,4 @@ def action_paste(self) -> None:
"""Paste from the local clipboard."""
clipboard = self.app._clipboard
start, end = sorted(self.selection)
new_value = self.value[:start] + clipboard + self.value[end:]
self.value = new_value
self.cursor_position = start + len(clipboard)
self.replace(clipboard, start, end)
10 changes: 5 additions & 5 deletions tests/text_area/test_textarea_cut_copy_paste.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async def test_cut():
await pilot.press(*"Hello, World")
await pilot.press("left", "shift+left", "shift+left")
await pilot.press("ctrl+x")
assert text_area.document.text == "Hello, Wod"
assert text_area.text == "Hello, Wod"
assert app.clipboard == "rl"


Expand All @@ -29,7 +29,7 @@ async def test_copy():
await pilot.press(*"Hello, World")
await pilot.press("left", "shift+left", "shift+left")
await pilot.press("ctrl+c")
assert text_area.document.text == "Hello, World"
assert text_area.text == "Hello, World"
assert app.clipboard == "rl"


Expand All @@ -44,9 +44,9 @@ async def test_paste():
"shift+left", "shift+left", "shift+left", "shift+left", "shift+left"
)
await pilot.press("ctrl+c")
assert text_area.document.text == "Hello, World"
assert text_area.text == "Hello, World"
assert app.clipboard == "World"
await pilot.press("ctrl+v")
assert text_area.document.text == "Hello, World"
assert text_area.text == "Hello, World"
await pilot.press("ctrl+v")
assert text_area.document.text == "Hello, WorldWorld"
assert text_area.text == "Hello, WorldWorld"

0 comments on commit b2bc4c9

Please sign in to comment.