-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix empty paste #2568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix empty paste #2568
Conversation
Related issues: #2563.
7f7afec to
81289c3
Compare
src/textual/widgets/_input.py
Outdated
|
|
||
| def _on_paste(self, event: events.Paste) -> None: | ||
| line = event.text.splitlines()[0] | ||
| line = event.text.splitlines()[0] if event.text else "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we not skip the insert_text_at_cursor entirely when the pasted text is an empty string.
I'm assuming that inserting an empty string does nothing useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't do anything very useful, but that would short-circuit other things that might be expected, like an Input.Changed event.
Do you think it's worth adding that exception here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you would get a Change event, because nothing should have changed. Have you checked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I thought always_update was True for reactives by default.
Related comments: #2568 (comment)
src/textual/widgets/_input.py
Outdated
| if event.text: | ||
| line = event.text.splitlines()[0] | ||
| self.insert_text_at_cursor(line) | ||
| event.stop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will still need to stop the event. It may be empty string, but we have still consumed the event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course 🤦
Closes #2563.