Use Option to encode empty text case in hit test methods

This commit is contained in:
Héctor Ramón Jiménez 2021-09-15 14:49:13 +07:00
parent 93fec8d273
commit 643500bbdf
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
10 changed files with 59 additions and 52 deletions

View file

@ -14,14 +14,14 @@ pub enum Hit {
impl Hit {
/// Computes the cursor position corresponding to this [`HitTestResult`] .
pub fn cursor(&self) -> usize {
pub fn cursor(self) -> usize {
match self {
Self::CharOffset(i) => *i,
Self::CharOffset(i) => i,
Self::NearestCharOffset(i, delta) => {
if delta.x > f32::EPSILON {
i + 1
} else {
*i
i
}
}
}