input: Fix move to to skip \r on Windows. (#1223)

This PR for continue #1214 to fix move cursor to ignore` `\r` for
Windows.
This commit is contained in:
Jason Lee 2025-09-09 09:40:07 +08:00 committed by GitHub
parent 413eac3385
commit d71a32d0e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1918,11 +1918,25 @@ impl InputState {
}
fn previous_boundary(&self, offset: usize) -> usize {
self.text.clip_offset(offset.saturating_sub(1), Bias::Left)
let mut offset = self.text.clip_offset(offset.saturating_sub(1), Bias::Left);
if let Some(ch) = self.text.char_at(offset) {
if ch == '\r' {
offset -= 1;
}
}
offset
}
fn next_boundary(&self, offset: usize) -> usize {
self.text.clip_offset(offset + 1, Bias::Right)
let mut offset = self.text.clip_offset(offset + 1, Bias::Right);
if let Some(ch) = self.text.char_at(offset) {
if ch == '\r' {
offset += 1;
}
}
offset
}
/// Returns the true to let InputElement to render cursor, when Input is focused and current BlinkCursor is visible.