gpui: Unify the index_for_x methods (#42162)
Supersedes https://github.com/zed-industries/zed/pull/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 commit is contained in:
@@ -371,12 +371,10 @@ impl Vim {
|
||||
|
||||
loop {
|
||||
let laid_out_line = map.layout_row(row, &text_layout_details);
|
||||
let start = DisplayPoint::new(
|
||||
row,
|
||||
laid_out_line.closest_index_for_x(positions.start) as u32,
|
||||
);
|
||||
let start =
|
||||
DisplayPoint::new(row, laid_out_line.index_for_x(positions.start) as u32);
|
||||
let mut end =
|
||||
DisplayPoint::new(row, laid_out_line.closest_index_for_x(positions.end) as u32);
|
||||
DisplayPoint::new(row, laid_out_line.index_for_x(positions.end) as u32);
|
||||
if end <= start {
|
||||
if start.column() == map.line_len(start.row()) {
|
||||
end = start;
|
||||
|
||||
Reference in New Issue
Block a user