Skip to content

Commit

Permalink
Merge pull request Textualize#1698 from Textualize/fix-paste
Browse files Browse the repository at this point in the history
Fix paste and test
  • Loading branch information
willmcgugan authored Jan 31, 2023
2 parents 62cede5 + 2ec0191 commit dc1c4da
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fixed double-paste into `Input` https://github.com/Textualize/textual/issues/1657
- Added a workaround for an apparent Windows Terminal paste issue https://github.com/Textualize/textual/issues/1661
- Fixes issue with renderable width calculation https://github.com/Textualize/textual/issues/1685
- Fixed issue with app not processing Paste event https://github.com/Textualize/textual/issues/1666

## [0.10.1] - 2023-01-20

Expand Down
4 changes: 3 additions & 1 deletion src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1901,9 +1901,11 @@ async def on_event(self, event: events.Event) -> None:
else:
await self.screen._forward_event(event)

elif isinstance(event, events.Paste):
elif isinstance(event, events.Paste) and not event.is_forwarded:
if self.focused is not None:
await self.focused._forward_event(event)
else:
await self.screen._forward_event(event)
else:
await super().on_event(event)

Expand Down
2 changes: 1 addition & 1 deletion src/textual/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from ._types import MessageTarget
from .geometry import Offset, Size
from .keys import _get_key_aliases, _get_key_display
from .keys import _get_key_aliases
from .message import Message

MouseEventT = TypeVar("MouseEventT", bound="MouseEvent")
Expand Down
18 changes: 18 additions & 0 deletions tests/test_paste.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from textual.app import App
from textual import events


async def test_paste_app():
paste_events = []

class PasteApp(App):
def on_paste(self, event):
paste_events.append(event)

app = PasteApp()
async with app.run_test() as pilot:
await app.post_message(events.Paste(sender=app, text="Hello"))
await pilot.pause(0)

assert len(paste_events) == 1
assert paste_events[0].text == "Hello"

0 comments on commit dc1c4da

Please sign in to comment.