From 9ce3a517280691d356b454071cf4705fa7ac6b2c Mon Sep 17 00:00:00 2001 From: Eduardo Flores Date: Mon, 20 May 2024 22:04:13 -0700 Subject: [PATCH] fix: text input attempting to subtract with overflow --- src/widget/text_input/input.rs | 42 ++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/widget/text_input/input.rs b/src/widget/text_input/input.rs index b8c0c839..5bf4f27a 100644 --- a/src/widget/text_input/input.rs +++ b/src/widget/text_input/input.rs @@ -729,28 +729,30 @@ where } } - let index = tree.children.len() - 1; - if let (Some(trailing_icon), Some(tree)) = - (self.trailing_icon.as_mut(), tree.children.get_mut(index)) - { - let children = text_layout.children(); - trailing_icon_layout = Some(children.last().unwrap()); + if tree.children.len() > 0 { + let index = tree.children.len() - 1; + if let (Some(trailing_icon), Some(tree)) = + (self.trailing_icon.as_mut(), tree.children.get_mut(index)) + { + let children = text_layout.children(); + trailing_icon_layout = Some(children.last().unwrap()); - if let Some(trailing_layout) = trailing_icon_layout { - if cursor_position.is_over(trailing_layout.bounds()) { - let res = trailing_icon.as_widget_mut().on_event( - tree, - event.clone(), - trailing_layout, - cursor_position, - renderer, - clipboard, - shell, - viewport, - ); + if let Some(trailing_layout) = trailing_icon_layout { + if cursor_position.is_over(trailing_layout.bounds()) { + let res = trailing_icon.as_widget_mut().on_event( + tree, + event.clone(), + trailing_layout, + cursor_position, + renderer, + clipboard, + shell, + viewport, + ); - if res == event::Status::Captured { - return res; + if res == event::Status::Captured { + return res; + } } } }