Skip to content

Commit 251ed76

Browse files
committed
allow text_editor to display the selected range while not focused
1 parent 756308c commit 251ed76

File tree

1 file changed

+41
-39
lines changed

1 file changed

+41
-39
lines changed

widget/src/text_editor.rs

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -801,49 +801,51 @@ where
801801

802802
let translation = text_bounds.position() - Point::ORIGIN;
803803

804-
if let Some(focus) = state.focus.as_ref() {
805-
match internal.editor.cursor() {
806-
Cursor::Caret(position) if focus.is_cursor_visible() => {
807-
let cursor =
808-
Rectangle::new(
809-
position + translation,
810-
Size::new(
811-
1.0,
812-
self.line_height
813-
.to_absolute(self.text_size.unwrap_or_else(
814-
|| renderer.default_size(),
815-
))
816-
.into(),
817-
),
818-
);
804+
match internal.editor.cursor() {
805+
Cursor::Caret(position)
806+
if state
807+
.focus
808+
.as_ref()
809+
.is_some_and(Focus::is_cursor_visible) =>
810+
{
811+
let cursor = Rectangle::new(
812+
position + translation,
813+
Size::new(
814+
1.0,
815+
self.line_height
816+
.to_absolute(
817+
self.text_size
818+
.unwrap_or_else(|| renderer.default_size()),
819+
)
820+
.into(),
821+
),
822+
);
819823

820-
if let Some(clipped_cursor) =
821-
text_bounds.intersection(&cursor)
822-
{
823-
renderer.fill_quad(
824-
renderer::Quad {
825-
bounds: clipped_cursor,
826-
..renderer::Quad::default()
827-
},
828-
style.value,
829-
);
830-
}
824+
if let Some(clipped_cursor) = text_bounds.intersection(&cursor)
825+
{
826+
renderer.fill_quad(
827+
renderer::Quad {
828+
bounds: clipped_cursor,
829+
..renderer::Quad::default()
830+
},
831+
style.value,
832+
);
831833
}
832-
Cursor::Selection(ranges) => {
833-
for range in ranges.into_iter().filter_map(|range| {
834-
text_bounds.intersection(&(range + translation))
835-
}) {
836-
renderer.fill_quad(
837-
renderer::Quad {
838-
bounds: range,
839-
..renderer::Quad::default()
840-
},
841-
style.selection,
842-
);
843-
}
834+
}
835+
Cursor::Selection(ranges) => {
836+
for range in ranges.into_iter().filter_map(|range| {
837+
text_bounds.intersection(&(range + translation))
838+
}) {
839+
renderer.fill_quad(
840+
renderer::Quad {
841+
bounds: range,
842+
..renderer::Quad::default()
843+
},
844+
style.selection,
845+
);
844846
}
845-
Cursor::Caret(_) => {}
846847
}
848+
Cursor::Caret(_) => {}
847849
}
848850
}
849851

0 commit comments

Comments
 (0)