From 0c6d4eb23f07e0ab424dc22dd198924b8540192a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sun, 2 Feb 2025 17:50:12 +0100 Subject: [PATCH] Run `cargo fmt` and fix lints --- widget/src/text_editor.rs | 9 +++++---- widget/src/text_input.rs | 25 ++++++++++--------------- winit/src/program/state.rs | 6 ++---- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index 2931e7f616..529c8b909a 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -338,7 +338,7 @@ where let text_bounds = bounds.shrink(self.padding); let translation = text_bounds.position() - Point::ORIGIN; - if let Some(_) = state.focus.as_ref() { + if state.focus.is_some() { let position = match internal.editor.cursor() { Cursor::Caret(position) => position, Cursor::Selection(ranges) => ranges @@ -872,10 +872,11 @@ where }; shell.update_caret_info(if state.is_focused() { - let rect = self - .caret_rect(tree, renderer, layout) - .unwrap_or(Rectangle::default()); + let rect = + self.caret_rect(tree, renderer, layout).unwrap_or_default(); + let bottom_left = Point::new(rect.x, rect.y + rect.height); + Some(CaretInfo { position: bottom_left, input_method_allowed: true, diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs index f2756b5be1..ba5d184305 100644 --- a/widget/src/text_input.rs +++ b/widget/src/text_input.rs @@ -407,18 +407,15 @@ where let mut children_layout = layout.children(); let text_bounds = children_layout.next().unwrap().bounds(); - if let Some(_) = state + if state .is_focused - .as_ref() - .filter(|focus| focus.is_window_focused) + .is_some_and(|focus| focus.is_window_focused) { let caret_index = match state.cursor.state(value) { cursor::State::Index(position) => position, - cursor::State::Selection { start, end } => { - let left = start.min(end); - left - } + cursor::State::Selection { start, end } => start.min(end), }; + let text = state.value.raw(); let (caret_x, offset) = measure_cursor_and_scroll_offset( text, @@ -433,6 +430,7 @@ where ); let x = (text_bounds.x + caret_x).floor(); + Some(Rectangle { x: (alignment_offset - offset) + x, y: text_bounds.y, @@ -1250,7 +1248,7 @@ where state.keyboard_modifiers = *modifiers; } - Event::InputMethod(input_method::Event::Commit(string)) => { + Event::InputMethod(input_method::Event::Commit(text)) => { let state = state::(tree); if let Some(focus) = &mut state.is_focused { @@ -1258,21 +1256,18 @@ where return; }; - state.is_pasting = None; - let mut editor = Editor::new(&mut self.value, &mut state.cursor); + editor.paste(Value::new(text)); - editor.paste(Value::new(&string)); + focus.updated_at = Instant::now(); + state.is_pasting = None; let message = (on_input)(editor.contents()); shell.publish(message); - - focus.updated_at = Instant::now(); + shell.capture_event(); update_cache(state, &self.value); - - shell.capture_event(); } } Event::Window(window::Event::Unfocused) => { diff --git a/winit/src/program/state.rs b/winit/src/program/state.rs index 2b5710ac9d..6361d1bab6 100644 --- a/winit/src/program/state.rs +++ b/winit/src/program/state.rs @@ -186,10 +186,8 @@ where WindowEvent::ModifiersChanged(new_modifiers) => { self.modifiers = new_modifiers.state(); } - WindowEvent::Ime(ime) => { - if let Ime::Preedit(text, _) = ime { - self.preedit = text.clone(); - } + WindowEvent::Ime(Ime::Preedit(text, _)) => { + self.preedit = text.clone(); } #[cfg(feature = "debug")] WindowEvent::KeyboardInput {