Fix out of bounds caret in TextEditor in some circumstances

This commit is contained in:
Héctor Ramón Jiménez 2024-04-26 15:17:35 +02:00
parent 3762c0590c
commit 73088a6fc1
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -569,23 +569,27 @@ where
if state.is_focused { if state.is_focused {
match internal.editor.cursor() { match internal.editor.cursor() {
Cursor::Caret(position) => { Cursor::Caret(position) => {
let position = position + translation; let cursor =
Rectangle::new(
position + translation,
Size::new(
1.0,
self.line_height
.to_absolute(self.text_size.unwrap_or_else(
|| renderer.default_size(),
))
.into(),
),
);
if bounds.contains(position) { if let Some(clipped_cursor) = bounds.intersection(&cursor) {
renderer.fill_quad( renderer.fill_quad(
renderer::Quad { renderer::Quad {
bounds: Rectangle { bounds: Rectangle {
x: position.x.floor(), x: clipped_cursor.x.floor(),
y: position.y, y: clipped_cursor.y,
width: 1.0, width: clipped_cursor.width,
height: self height: clipped_cursor.height,
.line_height
.to_absolute(
self.text_size.unwrap_or_else(
|| renderer.default_size(),
),
)
.into(),
}, },
..renderer::Quad::default() ..renderer::Quad::default()
}, },