Skip to content

Commit b2bc4c9

Browse files
committed
simplify
1 parent e723ca2 commit b2bc4c9

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/textual/widgets/_input.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -999,9 +999,7 @@ async def action_submit(self) -> None:
999999

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

10071005
def action_copy(self) -> None:
@@ -1012,6 +1010,4 @@ def action_paste(self) -> None:
10121010
"""Paste from the local clipboard."""
10131011
clipboard = self.app._clipboard
10141012
start, end = sorted(self.selection)
1015-
new_value = self.value[:start] + clipboard + self.value[end:]
1016-
self.value = new_value
1017-
self.cursor_position = start + len(clipboard)
1013+
self.replace(clipboard, start, end)

tests/text_area/test_textarea_cut_copy_paste.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async def test_cut():
1616
await pilot.press(*"Hello, World")
1717
await pilot.press("left", "shift+left", "shift+left")
1818
await pilot.press("ctrl+x")
19-
assert text_area.document.text == "Hello, Wod"
19+
assert text_area.text == "Hello, Wod"
2020
assert app.clipboard == "rl"
2121

2222

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

3535

@@ -44,9 +44,9 @@ async def test_paste():
4444
"shift+left", "shift+left", "shift+left", "shift+left", "shift+left"
4545
)
4646
await pilot.press("ctrl+c")
47-
assert text_area.document.text == "Hello, World"
47+
assert text_area.text == "Hello, World"
4848
assert app.clipboard == "World"
4949
await pilot.press("ctrl+v")
50-
assert text_area.document.text == "Hello, World"
50+
assert text_area.text == "Hello, World"
5151
await pilot.press("ctrl+v")
52-
assert text_area.document.text == "Hello, WorldWorld"
52+
assert text_area.text == "Hello, WorldWorld"

0 commit comments

Comments
 (0)