diff options
Diffstat (limited to '')
-rw-r--r-- | widget/src/text/rich.rs | 18 | ||||
-rw-r--r-- | widget/src/text_editor.rs | 13 | ||||
-rw-r--r-- | widget/src/text_input.rs | 66 |
3 files changed, 48 insertions, 49 deletions
diff --git a/widget/src/text/rich.rs b/widget/src/text/rich.rs index 3d241375..f778b029 100644 --- a/widget/src/text/rich.rs +++ b/widget/src/text/rich.rs @@ -1,5 +1,4 @@ use crate::core::alignment; -use crate::core::event; use crate::core::layout; use crate::core::mouse; use crate::core::renderer; @@ -365,7 +364,7 @@ where _clipboard: &mut dyn Clipboard, shell: &mut Shell<'_, Link>, _viewport: &Rectangle, - ) -> event::Status { + ) { match event { Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => { if let Some(position) = cursor.position_in(layout.bounds()) { @@ -374,9 +373,16 @@ where .downcast_mut::<State<Link, Renderer::Paragraph>>(); if let Some(span) = state.paragraph.hit_span(position) { - state.span_pressed = Some(span); - - return event::Status::Captured; + if self + .spans + .as_ref() + .as_ref() + .get(span) + .is_some_and(|span| span.link.is_some()) + { + state.span_pressed = Some(span); + shell.capture_event(); + } } } } @@ -409,8 +415,6 @@ where } _ => {} } - - event::Status::Ignored } fn mouse_interaction( diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index 3bb45494..292e584e 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -33,7 +33,6 @@ //! ``` use crate::core::alignment; use crate::core::clipboard::{self, Clipboard}; -use crate::core::event::{self, Event}; use crate::core::keyboard; use crate::core::keyboard::key; use crate::core::layout::{self, Layout}; @@ -47,7 +46,7 @@ use crate::core::widget::operation; use crate::core::widget::{self, Widget}; use crate::core::window; use crate::core::{ - Background, Border, Color, Element, Length, Padding, Pixels, Point, + Background, Border, Color, Element, Event, Length, Padding, Pixels, Point, Rectangle, Shell, Size, SmolStr, Theme, Vector, }; @@ -606,9 +605,9 @@ where clipboard: &mut dyn Clipboard, shell: &mut Shell<'_, Message>, _viewport: &Rectangle, - ) -> event::Status { + ) { let Some(on_edit) = self.on_edit.as_ref() else { - return event::Status::Ignored; + return; }; let state = tree.state.downcast_mut::<State<Highlighter>>(); @@ -656,7 +655,7 @@ where cursor, self.key_binding.as_deref(), ) else { - return event::Status::Ignored; + return; }; match update { @@ -685,7 +684,7 @@ where let bounds = self.content.0.borrow().editor.bounds(); if bounds.height >= i32::MAX as f32 { - return event::Status::Ignored; + return; } let lines = lines + state.partial_scroll; @@ -798,7 +797,7 @@ where } } - event::Status::Captured + shell.capture_event(); } fn draw( diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs index 8fa7889f..87dffb98 100644 --- a/widget/src/text_input.rs +++ b/widget/src/text_input.rs @@ -42,7 +42,6 @@ use editor::Editor; use crate::core::alignment; use crate::core::clipboard::{self, Clipboard}; -use crate::core::event::{self, Event}; use crate::core::keyboard; use crate::core::keyboard::key; use crate::core::layout; @@ -57,8 +56,8 @@ use crate::core::widget::operation::{self, Operation}; use crate::core::widget::tree::{self, Tree}; use crate::core::window; use crate::core::{ - Background, Border, Color, Element, Layout, Length, Padding, Pixels, Point, - Rectangle, Shell, Size, Theme, Vector, Widget, + Background, Border, Color, Element, Event, Layout, Length, Padding, Pixels, + Point, Rectangle, Shell, Size, Theme, Vector, Widget, }; use crate::runtime::task::{self, Task}; use crate::runtime::Action; @@ -638,7 +637,7 @@ where clipboard: &mut dyn Clipboard, shell: &mut Shell<'_, Message>, _viewport: &Rectangle, - ) -> event::Status { + ) { let update_cache = |state, value| { replace_paragraph( renderer, @@ -754,7 +753,7 @@ where shell.request_redraw(); } - return event::Status::Captured; + shell.capture_event(); } } Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) @@ -809,7 +808,7 @@ where shell.request_redraw(); } - return event::Status::Captured; + shell.capture_event(); } } Event::Keyboard(keyboard::Event::KeyPressed { @@ -834,14 +833,15 @@ where ); } - return event::Status::Captured; + shell.capture_event(); + return; } keyboard::Key::Character("x") if state.keyboard_modifiers.command() && !self.is_secure => { let Some(on_input) = &self.on_input else { - return event::Status::Ignored; + return; }; if let Some((start, end)) = @@ -859,18 +859,18 @@ where let message = (on_input)(editor.contents()); shell.publish(message); + shell.capture_event(); focus.updated_at = Instant::now(); update_cache(state, &self.value); - - return event::Status::Captured; + return; } keyboard::Key::Character("v") if state.keyboard_modifiers.command() && !state.keyboard_modifiers.alt() => { let Some(on_input) = &self.on_input else { - return event::Status::Ignored; + return; }; let content = match state.is_pasting.take() { @@ -897,12 +897,12 @@ where (on_input)(editor.contents()) }; shell.publish(message); + shell.capture_event(); state.is_pasting = Some(content); focus.updated_at = Instant::now(); update_cache(state, &self.value); - - return event::Status::Captured; + return; } keyboard::Key::Character("a") if state.keyboard_modifiers.command() => @@ -917,14 +917,15 @@ where shell.request_redraw(); } - return event::Status::Captured; + shell.capture_event(); + return; } _ => {} } if let Some(text) = text { let Some(on_input) = &self.on_input else { - return event::Status::Ignored; + return; }; state.is_pasting = None; @@ -939,11 +940,11 @@ where let message = (on_input)(editor.contents()); shell.publish(message); + shell.capture_event(); focus.updated_at = Instant::now(); update_cache(state, &self.value); - - return event::Status::Captured; + return; } } @@ -951,13 +952,12 @@ where keyboard::Key::Named(key::Named::Enter) => { if let Some(on_submit) = self.on_submit.clone() { shell.publish(on_submit); - - return event::Status::Captured; + shell.capture_event(); } } keyboard::Key::Named(key::Named::Backspace) => { let Some(on_input) = &self.on_input else { - return event::Status::Ignored; + return; }; if modifiers.jump() @@ -980,15 +980,14 @@ where let message = (on_input)(editor.contents()); shell.publish(message); + shell.capture_event(); focus.updated_at = Instant::now(); update_cache(state, &self.value); - - return event::Status::Captured; } keyboard::Key::Named(key::Named::Delete) => { let Some(on_input) = &self.on_input else { - return event::Status::Ignored; + return; }; if modifiers.jump() @@ -1014,11 +1013,10 @@ where let message = (on_input)(editor.contents()); shell.publish(message); + shell.capture_event(); focus.updated_at = Instant::now(); update_cache(state, &self.value); - - return event::Status::Captured; } keyboard::Key::Named(key::Named::Home) => { let cursor_before = state.cursor; @@ -1038,7 +1036,7 @@ where shell.request_redraw(); } - return event::Status::Captured; + shell.capture_event(); } keyboard::Key::Named(key::Named::End) => { let cursor_before = state.cursor; @@ -1058,7 +1056,7 @@ where shell.request_redraw(); } - return event::Status::Captured; + shell.capture_event(); } keyboard::Key::Named(key::Named::ArrowLeft) if modifiers.macos_command() => @@ -1080,7 +1078,7 @@ where shell.request_redraw(); } - return event::Status::Captured; + shell.capture_event(); } keyboard::Key::Named(key::Named::ArrowRight) if modifiers.macos_command() => @@ -1102,7 +1100,7 @@ where shell.request_redraw(); } - return event::Status::Captured; + shell.capture_event(); } keyboard::Key::Named(key::Named::ArrowLeft) => { let cursor_before = state.cursor; @@ -1129,7 +1127,7 @@ where shell.request_redraw(); } - return event::Status::Captured; + shell.capture_event(); } keyboard::Key::Named(key::Named::ArrowRight) => { let cursor_before = state.cursor; @@ -1156,7 +1154,7 @@ where shell.request_redraw(); } - return event::Status::Captured; + shell.capture_event(); } keyboard::Key::Named(key::Named::Escape) => { state.is_focused = None; @@ -1166,7 +1164,7 @@ where state.keyboard_modifiers = keyboard::Modifiers::default(); - return event::Status::Captured; + shell.capture_event(); } _ => {} } @@ -1179,7 +1177,7 @@ where if let keyboard::Key::Character("v") = key.as_ref() { state.is_pasting = None; - return event::Status::Captured; + shell.capture_event(); } } @@ -1257,8 +1255,6 @@ where { shell.request_redraw(); } - - event::Status::Ignored } fn draw( |