diff options
author | 2023-09-13 15:16:47 +0200 | |
---|---|---|
committer | 2023-09-13 15:16:47 +0200 | |
commit | d502c9f16fc78bf6b5253152751480c5b5e5999c (patch) | |
tree | 1e7a49b4c1986408caee561c385743c28bd2bb60 /widget/src/text_editor.rs | |
parent | 40eb648f1e1e2ceb2782eddacbbc966f44de6961 (diff) | |
download | iced-d502c9f16fc78bf6b5253152751480c5b5e5999c.tar.gz iced-d502c9f16fc78bf6b5253152751480c5b5e5999c.tar.bz2 iced-d502c9f16fc78bf6b5253152751480c5b5e5999c.zip |
Unify `Focus` and `Click` updates in `widget::text_editor`
Diffstat (limited to 'widget/src/text_editor.rs')
-rw-r--r-- | widget/src/text_editor.rs | 48 |
1 files changed, 16 insertions, 32 deletions
diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index 12e66f68..a8069069 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -189,16 +189,12 @@ where }; match update { - Update::Focus { click, action } => { - state.is_focused = true; - state.last_click = Some(click); - shell.publish(on_edit(action)); - } Update::Unfocus => { state.is_focused = false; state.is_dragging = false; } Update::Click { click, action } => { + state.is_focused = true; state.last_click = Some(click); state.is_dragging = true; shell.publish(on_edit(action)); @@ -340,9 +336,8 @@ where } enum Update { - Focus { click: mouse::Click, action: Action }, - Unfocus, Click { click: mouse::Click, action: Action }, + Unfocus, StopDragging, Edit(Action), Copy, @@ -364,31 +359,20 @@ impl Update { let cursor_position = cursor_position - Vector::new(padding.top, padding.left); - if state.is_focused { - let click = mouse::Click::new( - cursor_position, - state.last_click, - ); - - let action = match click.kind() { - mouse::click::Kind::Single => { - Action::Click(cursor_position) - } - mouse::click::Kind::Double => { - Action::SelectWord - } - mouse::click::Kind::Triple => { - Action::SelectLine - } - }; - - Some(Update::Click { click, action }) - } else { - Some(Update::Focus { - click: mouse::Click::new(cursor_position, None), - action: Action::Click(cursor_position), - }) - } + let click = mouse::Click::new( + cursor_position, + state.last_click, + ); + + let action = match click.kind() { + mouse::click::Kind::Single => { + Action::Click(cursor_position) + } + mouse::click::Kind::Double => Action::SelectWord, + mouse::click::Kind::Triple => Action::SelectLine, + }; + + Some(Update::Click { click, action }) } else if state.is_focused { Some(Update::Unfocus) } else { |