Use Option to encode empty text case in hit test methods
This commit is contained in:
parent
93fec8d273
commit
643500bbdf
10 changed files with 59 additions and 52 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue