From 16c8c0df30bb37580252d0ce876af562e7ce237c Mon Sep 17 00:00:00 2001 From: ellieplayswow <164806095+ellieplayswow@users.noreply.github.com> Date: Wed, 30 Apr 2025 18:04:54 +0100 Subject: [PATCH] bugfix(zoom): use global modifiers for checking if ctrl is used for zoom instead of mouse area events example(copy): fixing copy example to use correct Method type --- examples/copy.rs | 5 ++-- src/mouse_area.rs | 67 +++-------------------------------------------- src/tab.rs | 2 +- 3 files changed, 7 insertions(+), 67 deletions(-) diff --git a/examples/copy.rs b/examples/copy.rs index f0a12be..956488e 100644 --- a/examples/copy.rs +++ b/examples/copy.rs @@ -1,5 +1,6 @@ use cosmic_files::operation::{recursive::Context, Controller, ReplaceResult}; use std::{error::Error, io, path::PathBuf}; +use cosmic_files::operation::recursive::Method; #[compio::main] async fn main() -> Result<(), Box> { @@ -30,13 +31,13 @@ async fn main() -> Result<(), Box> { context .recursive_copy_or_move( vec![(PathBuf::from("test/a"), PathBuf::from("test/b"))], - false, + Method::Copy, ) .await?; context .recursive_copy_or_move( vec![(PathBuf::from("test/b"), PathBuf::from("test/c"))], - true, + Method::Move { cross_device_copy: false }, ) .await?; diff --git a/src/mouse_area.rs b/src/mouse_area.rs index d263b34..4b176fa 100644 --- a/src/mouse_area.rs +++ b/src/mouse_area.rs @@ -7,12 +7,6 @@ use cosmic::{ iced_core::{ border::Border, event::{self, Event}, - keyboard::{ - self, - key::{self, Key}, - Event::{KeyPressed, KeyReleased}, - Modifiers, - }, layout, mouse::{self, click}, overlay, @@ -201,9 +195,9 @@ impl<'a, Message, F> OnDrag<'a, Message> for F where F: Fn(Option) -> pub trait OnResize<'a, Message>: Fn(Size, Rectangle) -> Message + 'a {} impl<'a, Message, F> OnResize<'a, Message> for F where F: Fn(Size, Rectangle) -> Message + 'a {} -pub trait OnScroll<'a, Message>: Fn(mouse::ScrollDelta, Modifiers) -> Option + 'a {} +pub trait OnScroll<'a, Message>: Fn(mouse::ScrollDelta) -> Option + 'a {} impl<'a, Message, F> OnScroll<'a, Message> for F where - F: Fn(mouse::ScrollDelta, Modifiers) -> Option + 'a + F: Fn(mouse::ScrollDelta) -> Option + 'a { } @@ -216,7 +210,6 @@ struct State { last_position: Option, last_virtual_position: Option, drag_initiated: Option, - modifiers: Modifiers, prev_click: Option<(mouse::Click, Instant)>, size: Option, } @@ -680,17 +673,13 @@ fn update( if let Some(on_scroll) = widget.on_scroll.as_ref() { if let Event::Mouse(mouse::Event::WheelScrolled { delta }) = event { - if let Some(message) = on_scroll(*delta, state.modifiers) { + if let Some(message) = on_scroll(*delta) { shell.publish(message); return event::Status::Captured; } } } - if let Event::Keyboard(key_event) = event { - handle_key_event(key_event, state) - }; - if let Some((message, drag_rect)) = widget.on_drag.as_ref().zip(state.drag_rect(cursor)) { shell.publish(message(drag_rect.intersection(&layout_bounds).map( |mut rect| { @@ -703,53 +692,3 @@ fn update( event::Status::Ignored } - -fn handle_key_event(key_event: &keyboard::Event, state: &mut State) { - if let KeyPressed { - key: Key::Named(key::Named::Control), - .. - } = key_event - { - state.modifiers.insert(Modifiers::CTRL); - } - - if let KeyReleased { - key: Key::Named(key::Named::Control), - .. - } = key_event - { - state.modifiers.remove(Modifiers::CTRL); - } - - if let KeyPressed { - key: Key::Named(key::Named::Shift), - .. - } = key_event - { - state.modifiers.insert(Modifiers::SHIFT); - } - - if let KeyReleased { - key: Key::Named(key::Named::Shift), - .. - } = key_event - { - state.modifiers.remove(Modifiers::SHIFT); - } - - if let KeyPressed { - key: Key::Named(key::Named::Alt), - .. - } = key_event - { - state.modifiers.insert(Modifiers::ALT); - } - - if let KeyReleased { - key: Key::Named(key::Named::Alt), - .. - } = key_event - { - state.modifiers.remove(Modifiers::ALT); - } -} diff --git a/src/tab.rs b/src/tab.rs index ab93e5b..da30659 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -4924,7 +4924,7 @@ impl Tab { .on_resize(|_, _| Message::ScrollToFocus) .on_back_press(move |_point_opt| Message::GoPrevious) .on_forward_press(move |_point_opt| Message::GoNext) - .on_scroll(respond_to_scroll_direction); + .on_scroll(|delta| respond_to_scroll_direction(delta, self.modifiers)); if self.context_menu.is_some() { mouse_area = mouse_area.on_right_press(move |_point_opt| Message::ContextMenu(None));