diff --git a/src/inspector/profiler.rs b/src/inspector/profiler.rs index 1899e38f..cd5ad9a6 100644 --- a/src/inspector/profiler.rs +++ b/src/inspector/profiler.rs @@ -94,7 +94,7 @@ fn profile_view(profile: &Rc) -> impl IntoView { }) }) .collect(); - frames.sort_by(|a, b| b.sum.cmp(&a.sum)); + frames.sort_by_key(|frame| std::cmp::Reverse(frame.sum)); let frames: Rc<[_]> = frames.into(); let selected_frame = RwSignal::new(None); diff --git a/src/inspector/view.rs b/src/inspector/view.rs index ff67bc6e..04083152 100644 --- a/src/inspector/view.rs +++ b/src/inspector/view.rs @@ -729,30 +729,26 @@ impl View for InspectorImageView { return EventPropagation::Continue; } match key { - Key::Named(NamedKey::ArrowUp) => { - if !self.contain_ids.is_empty() { - self.contain_index = if self.contain_index == 0 { - self.contain_ids.len() - 1 - } else { - self.contain_index - 1 - }; - if let Some(id) = self.contain_ids.get(self.contain_index).copied() { - cx.window_state.request_paint = true; - self.id.owning_id().request_paint(); - update_select_view_id(id, &self.capture_view, false, self.datas); - return EventPropagation::Stop; - } + Key::Named(NamedKey::ArrowUp) if !self.contain_ids.is_empty() => { + self.contain_index = if self.contain_index == 0 { + self.contain_ids.len() - 1 + } else { + self.contain_index - 1 + }; + if let Some(id) = self.contain_ids.get(self.contain_index).copied() { + cx.window_state.request_paint = true; + self.id.owning_id().request_paint(); + update_select_view_id(id, &self.capture_view, false, self.datas); + return EventPropagation::Stop; } } - Key::Named(NamedKey::ArrowDown) => { - if !self.contain_ids.is_empty() { - self.contain_index = (self.contain_index + 1) % self.contain_ids.len(); - if let Some(id) = self.contain_ids.get(self.contain_index).copied() { - cx.window_state.request_paint = true; - self.id.owning_id().request_paint(); - update_select_view_id(id, &self.capture_view, false, self.datas); - return EventPropagation::Stop; - } + Key::Named(NamedKey::ArrowDown) if !self.contain_ids.is_empty() => { + self.contain_index = (self.contain_index + 1) % self.contain_ids.len(); + if let Some(id) = self.contain_ids.get(self.contain_index).copied() { + cx.window_state.request_paint = true; + self.id.owning_id().request_paint(); + update_select_view_id(id, &self.capture_view, false, self.datas); + return EventPropagation::Stop; } } _ => {} diff --git a/src/views/label.rs b/src/views/label.rs index daea0e67..0861efb6 100644 --- a/src/views/label.rs +++ b/src/views/label.rs @@ -405,29 +405,28 @@ impl View for Label { cx.window_state.request_paint(self.id); return EventPropagation::Continue; } - Event::Pointer(PointerEvent::Down(PointerButtonEvent { state, pointer, .. })) => { + Event::Pointer(PointerEvent::Down(PointerButtonEvent { state, pointer, .. })) if self.label_props.text_selectable() && state .buttons - .contains(ui_events::pointer::PointerButton::Primary) - { - self.selection_state = self - .get_hit_point(state.logical_point()) - .map(|cursor| SelectionState::Ready { - origin: state.logical_point(), - selection: self - .layout_data - .borrow() - .get_effective_text_layout() - .map(|layout| layout.collapsed_selection(cursor)) - .expect("label text layout should be available on pointer down"), - }) - .unwrap_or(SelectionState::None); - if let Some(pointer_id) = pointer.pointer_id { - cx.window_state.set_pointer_capture(pointer_id, self.id); - } - cx.window_state.request_paint(self.id); + .contains(ui_events::pointer::PointerButton::Primary) => + { + self.selection_state = self + .get_hit_point(state.logical_point()) + .map(|cursor| SelectionState::Ready { + origin: state.logical_point(), + selection: self + .layout_data + .borrow() + .get_effective_text_layout() + .map(|layout| layout.collapsed_selection(cursor)) + .expect("label text layout should be available on pointer down"), + }) + .unwrap_or(SelectionState::None); + if let Some(pointer_id) = pointer.pointer_id { + cx.window_state.set_pointer_capture(pointer_id, self.id); } + cx.window_state.request_paint(self.id); } Event::Pointer(PointerEvent::Move(pu)) => { if !self.label_props.text_selectable() { diff --git a/src/views/text_input.rs b/src/views/text_input.rs index d704622b..d4b90f82 100644 --- a/src/views/text_input.rs +++ b/src/views/text_input.rs @@ -1355,54 +1355,46 @@ impl View for TextInput { Event::Ime(ImeEvent::DeleteSurrounding { before_bytes, after_bytes, - }) => { - if self.is_focused { - let selection = self.selection_byte_range(); - if let Some(selection) = selection.as_ref() { - self.selection = None; - self.cursor_glyph_idx = selection.start; - } - self.buffer.update(|buf| { - if let Some(selection) = selection.clone() { - buf.replace_range(selection, ""); - } - // If the index falls inside a character, delete that character too. - // This only happens on desynchronized input: - // 1. IME sends a request with index on code point boundary - // 2. Another source shifts text around - // 3. Request arrives. - // This situation is expected to be rare, so not trying to be too clever at handling it. - let before_start = buf[..self.cursor_glyph_idx] - .char_indices() - .rev() - .find(|(index, _)| self.cursor_glyph_idx - index >= *before_bytes) - .map(|(i, _)| i) - .unwrap_or(0); - let after_end = buf[self.cursor_glyph_idx..] - .char_indices() - .map(|(index, _)| index) - .find(|index| index >= after_bytes) - .map(|i| i + self.cursor_glyph_idx) - .unwrap_or(buf.len()); - buf.replace_range(before_start..after_end, ""); - self.cursor_glyph_idx = before_start; - }); - true - } else { - false + }) if self.is_focused => { + let selection = self.selection_byte_range(); + if let Some(selection) = selection.as_ref() { + self.selection = None; + self.cursor_glyph_idx = selection.start; } + self.buffer.update(|buf| { + if let Some(selection) = selection.clone() { + buf.replace_range(selection, ""); + } + // If the index falls inside a character, delete that character too. + // This only happens on desynchronized input: + // 1. IME sends a request with index on code point boundary + // 2. Another source shifts text around + // 3. Request arrives. + // This situation is expected to be rare, so not trying to be too clever at handling it. + let before_start = buf[..self.cursor_glyph_idx] + .char_indices() + .rev() + .find(|(index, _)| self.cursor_glyph_idx - index >= *before_bytes) + .map(|(i, _)| i) + .unwrap_or(0); + let after_end = buf[self.cursor_glyph_idx..] + .char_indices() + .map(|(index, _)| index) + .find(|index| index >= after_bytes) + .map(|i| i + self.cursor_glyph_idx) + .unwrap_or(buf.len()); + buf.replace_range(before_start..after_end, ""); + self.cursor_glyph_idx = before_start; + }); + true } - Event::Ime(ImeEvent::Commit(text)) => { - if self.is_focused { - self.buffer - .update(|buf| buf.insert_str(self.cursor_glyph_idx, text)); - self.cursor_glyph_idx += text.len(); - self.preedit = None; + Event::Ime(ImeEvent::Commit(text)) if self.is_focused => { + self.buffer + .update(|buf| buf.insert_str(self.cursor_glyph_idx, text)); + self.cursor_glyph_idx += text.len(); + self.preedit = None; - true - } else { - false - } + true } Event::Focus(focus) => { diff --git a/src/views/toggle_button.rs b/src/views/toggle_button.rs index 4aca86b1..1beee676 100644 --- a/src/views/toggle_button.rs +++ b/src/views/toggle_button.rs @@ -140,11 +140,9 @@ impl Handle { self.update_bounds(toggle_size, radius); cx.window_state.request_paint(self.parent_id); } - Event::Interaction(InteractionEvent::Click) => { - if !self.dragged { - *state = !*state; - self.snap(*state, toggle_size, radius, inset); - } + Event::Interaction(InteractionEvent::Click) if !self.dragged => { + *state = !*state; + self.snap(*state, toggle_size, radius, inset); } _ => {} diff --git a/src/views/tooltip.rs b/src/views/tooltip.rs index 9c1fa380..66c9844b 100644 --- a/src/views/tooltip.rs +++ b/src/views/tooltip.rs @@ -114,14 +114,12 @@ impl View for Tooltip { impl Tooltip { fn handle_event(&mut self, cx: &mut EventCx) -> EventPropagation { match &cx.event { - Event::Pointer(PointerEvent::Move(pu)) => { - if self.overlay.borrow().is_none() { - let id = self.id(); - let token = exec_after(self.style.delay(), move |token| { - id.update_state(token); - }); - self.hover_point = Some((pu.current.logical_point(), token)); - } + Event::Pointer(PointerEvent::Move(pu)) if self.overlay.borrow().is_none() => { + let id = self.id(); + let token = exec_after(self.style.delay(), move |token| { + id.update_state(token); + }); + self.hover_point = Some((pu.current.logical_point(), token)); } Event::Pointer(_) | Event::Key(_) => { self.hover_point = None;