-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
gpui: Unify the index_for_x methods #42162
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
Conversation
fb03290 to
e5b0484
Compare
| let fragment_end_x = fragment_start_x + shaped_line.width; | ||
| if x < fragment_end_x { | ||
| return Some( | ||
| fragment_start_index + shaped_line.index_for_x(x - fragment_start_x)?, |
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.
From what I can tell, this is the only line of code that could be effected by removing the "overshoot returns None" part of the API. However, I believe this case is impossible to reach due to the x < fragment_end_x check above it, and so we can safely move forward with this API change.
Supersedes zed-industries#39910 At some point, these two (`index_for_x` and `closest_index_for_x`) methods where separated out and some code paths used one, while other code paths took the other. That said, their behavior is almost identical: - `index_for_x` computes the index behind the pixel offset, and returns `None` if there's an overshoot - `closest_index_for_x` computes the nearest index to the pixel offset, taking into account whether the offset is over halfway through or not. If there's an overshoot, it returns the length of the line. Given these two behaviors, `closest_index_for_x` seems to be a more useful API than `index_for_x`, and indeed the display map and other core editor features use it extensively. So this PR is an experiment in simply replacing one behavior with the other. Release Notes: - Improved the accuracy of mouse selections in Markdown
This reverts commit 082b80e.
Supersedes zed-industries#39910 At some point, these two (`index_for_x` and `closest_index_for_x`) methods where separated out and some code paths used one, while other code paths took the other. That said, their behavior is almost identical: - `index_for_x` computes the index behind the pixel offset, and returns `None` if there's an overshoot - `closest_index_for_x` computes the nearest index to the pixel offset, taking into account whether the offset is over halfway through or not. If there's an overshoot, it returns the length of the line. Given these two behaviors, `closest_index_for_x` seems to be a more useful API than `index_for_x`, and indeed the display map and other core editor features use it extensively. So this PR is an experiment in simply replacing one behavior with the other. Release Notes: - Improved the accuracy of mouse selections in Markdown
…ed-industries#42505) This reverts commit 082b80e. This broke clicking, e.g. in snippets like ```rs let x = vec![ 1, 2, // 3, ]; ``` clicking between `2` and `,` is quite off now. Release Notes: - N/A
Supersedes #39910
At some point, these two (
index_for_xandclosest_index_for_x) methods where separated out and some code paths used one, while other code paths took the other. That said, their behavior is almost identical:index_for_xcomputes the index behind the pixel offset, and returnsNoneif there's an overshootclosest_index_for_xcomputes the nearest index to the pixel offset, taking into account whether the offset is over halfway through or not. If there's an overshoot, it returns the length of the line.Given these two behaviors,
closest_index_for_xseems to be a more useful API thanindex_for_x, and indeed the display map and other core editor features use it extensively. So this PR is an experiment in simply replacing one behavior with the other.Release Notes: