Skip to content
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

gpui: Prevent crash on macOS by adding characterIndexForPoint on GPUIView #23469

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

LouisBrunner
Copy link

Partially resolves #22939

This PR adds the missing selector and makes it return NSNotFound, meaning the cursor is not within a character bounding box. This is not completely correct but it does prevent zed from crashing and doesn't cause any further bug apart from the input method selector disappearing very quickly.

A more thorough check would be to calculate if and where the user has clicked inside the editor and return the offset of the selected character. It seems like a deeper change which also requires ViewInputHandler to calculate Screen mouse position (x, y) to Editor (row, column) which was unclear to me.

For reference, this is the input method selector:
Screenshot 2025-01-22 at 16 14 52

Release Notes:

  • Fix a "unrecognized selector sent to instance" crash on macOS when using different input methods

Copy link

cla-bot bot commented Jan 22, 2025

We require contributors to sign our Contributor License Agreement, and we don't have @LouisBrunner on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@LouisBrunner
Copy link
Author

@cla-bot check

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jan 22, 2025
Copy link

cla-bot bot commented Jan 22, 2025

The cla-bot has been summoned, and re-checked this pull request!

@maxdeviant maxdeviant changed the title fix(macos): prevent crash by adding characterIndexForPoint on GPUIView gpui: Prevent crash on macOS by adding characterIndexForPoint on GPUIView Jan 22, 2025
@@ -1827,6 +1832,10 @@ extern "C" fn accepts_first_mouse(this: &Object, _: Sel, _: id) -> BOOL {
YES
}

extern "C" fn character_index_for_point(_this: &Object, _: Sel, _position: NSPoint) -> u64 {
NSNotFound as u64
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if we want this solution, but not crashing is > crashing. So lets at least mark this with a TODO :)

Copy link
Author

Choose a reason for hiding this comment

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

100% agree, I am just unsure how to do that correctly.

Not sure on the guidelines on TODOs, but I added an explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

macOS crash: -[GPUIView characterIndexForPoint:]: unrecognized selector sent to instance
2 participants