diff options
author | 2024-04-26 15:38:46 +0200 | |
---|---|---|
committer | 2024-04-26 15:38:46 +0200 | |
commit | ce12231e22372eea0369f99b8fdfe26aa1240c57 (patch) | |
tree | 2ea1465ff65d10cd7dccaac6785d5544b071ce38 /widget | |
parent | 40c4aa8ff25f27e9bbc43f8fc2aa161e63396172 (diff) | |
parent | 73088a6fc1567f8bd557fdf479e16b395032b019 (diff) | |
download | iced-ce12231e22372eea0369f99b8fdfe26aa1240c57.tar.gz iced-ce12231e22372eea0369f99b8fdfe26aa1240c57.tar.bz2 iced-ce12231e22372eea0369f99b8fdfe26aa1240c57.zip |
Merge pull request #2407 from iced-rs/fix/text-editor-quirks
Fix some `text_editor` quirks
Diffstat (limited to 'widget')
-rw-r--r-- | widget/src/text_editor.rs | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index 5b0b1b79..7c0b98ea 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -569,23 +569,27 @@ where if state.is_focused { match internal.editor.cursor() { 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::Quad { bounds: Rectangle { - x: position.x.floor(), - y: position.y, - width: 1.0, - height: self - .line_height - .to_absolute( - self.text_size.unwrap_or_else( - || renderer.default_size(), - ), - ) - .into(), + x: clipped_cursor.x.floor(), + y: clipped_cursor.y, + width: clipped_cursor.width, + height: clipped_cursor.height, }, ..renderer::Quad::default() }, |