Prefer overlapping row in galley cursor_from_pos (#127)

This commit is contained in:
Paul Shen 2021-01-24 06:05:59 -08:00 committed by GitHub
parent 9f4c31c0e0
commit 18b9214575
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -197,8 +197,9 @@ impl Galley {
let mut pcursor_it = PCursor::default();
for (row_nr, row) in self.rows.iter().enumerate() {
let is_pos_within_row = pos.y >= row.y_min && pos.y <= row.y_max;
let y_dist = (row.y_min - pos.y).abs().min((row.y_max - pos.y).abs());
if y_dist < best_y_dist {
if is_pos_within_row || y_dist < best_y_dist {
best_y_dist = y_dist;
let column = row.char_at(pos.x);
let prefer_next_row = column < row.char_count_excluding_newline();
@ -216,6 +217,10 @@ impl Galley {
offset: pcursor_it.offset + column,
prefer_next_row,
},
};
if is_pos_within_row {
return cursor;
}
}
ccursor_index += row.char_count_including_newline();