Skip to content

Conversation

@rodrigogiraoserrao
Copy link
Contributor

Closes #2563.


def _on_paste(self, event: events.Paste) -> None:
line = event.text.splitlines()[0]
line = event.text.splitlines()[0] if event.text else ""
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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?

Copy link
Contributor Author

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.

if event.text:
line = event.text.splitlines()[0]
self.insert_text_at_cursor(line)
event.stop()
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course 🤦

@rodrigogiraoserrao rodrigogiraoserrao merged commit 1bba397 into main May 15, 2023
@rodrigogiraoserrao rodrigogiraoserrao deleted the empty-paste branch May 15, 2023 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pasting in Input with an empty string crashes the program

3 participants