diff --git a/src/app.rs b/src/app.rs index 65b640a..5cb2953 100644 --- a/src/app.rs +++ b/src/app.rs @@ -3014,13 +3014,12 @@ impl Application for App { } }, Message::ModifiersChanged(window_id, modifiers) => { - self.modifiers = modifiers; - if self.core.main_window_id() == Some(window_id) { - let entity = self.tab_model.active(); - return self.update(Message::TabMessage( - Some(entity), - tab::Message::ModifiersChanged(modifiers), - )); + #[cfg(all(feature = "wayland", feature = "desktop-applet"))] + let in_surface_ids = self.surface_ids.values().any(|id| *id == window_id); + #[cfg(not(all(feature = "wayland", feature = "desktop-applet")))] + let in_surface_ids = false; + if self.core.main_window_id() == Some(window_id) || in_surface_ids { + self.modifiers = modifiers; } } Message::MounterItems(mounter_key, mounter_items) => { @@ -5678,7 +5677,7 @@ impl Application for App { let entity = self.tab_model.active(); if let Some(tab) = self.tab_model.data::(entity) { let tab_view = tab - .view(&self.key_binds) + .view(&self.key_binds, &self.modifiers) .map(move |message| Message::TabMessage(Some(entity), message)); tab_column = tab_column.push(tab_view); } else { @@ -5715,7 +5714,7 @@ impl Application for App { let tab_view = match self.tab_model.data::(*entity) { Some(tab) => tab - .view(&self.key_binds) + .view(&self.key_binds, &self.modifiers) .map(move |message| Message::TabMessage(Some(*entity), message)), None => widget::vertical_space().into(), }; diff --git a/src/dialog.rs b/src/dialog.rs index 6778c0c..843ce94 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -1444,9 +1444,6 @@ impl Application for App { } Message::ModifiersChanged(modifiers) => { self.modifiers = modifiers; - return self.update(Message::TabMessage(tab::Message::ModifiersChanged( - modifiers, - ))); } Message::MounterItems(mounter_key, mounter_items) => { // Check for unmounted folders @@ -1926,7 +1923,11 @@ impl Application for App { } } - col = col.push(self.tab.view(&self.key_binds).map(Message::TabMessage)); + col = col.push( + self.tab + .view(&self.key_binds, &self.modifiers) + .map(Message::TabMessage), + ); col.into() } diff --git a/src/tab.rs b/src/tab.rs index dfb94df..9f6d2da 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -1611,7 +1611,6 @@ pub enum Message { ItemUp, Location(Location), LocationUp, - ModifiersChanged(Modifiers), Open(Option), Reload, RightClick(Option, Option), @@ -2496,7 +2495,6 @@ pub struct Tab { select_range: Option<(usize, usize)>, clicked: Option, selected_clicked: bool, - modifiers: Modifiers, last_right_click: Option, search_context: Option, date_time_formatter: DateTimeFormatter, @@ -2617,7 +2615,6 @@ impl Tab { clicked: None, dnd_hovered: None, selected_clicked: false, - modifiers: Modifiers::default(), last_right_click: None, search_context: None, date_time_formatter: date_time_formatter(config.military_time), @@ -3573,9 +3570,6 @@ impl Tab { } } } - Message::ModifiersChanged(modifiers) => { - self.modifiers = modifiers; - } Message::Open(path_opt) => { match path_opt { Some(path) => { @@ -5417,11 +5411,12 @@ impl Tab { (drag_col, mouse_area.into(), true) } - pub fn view_responsive( - &self, - key_binds: &HashMap, + pub fn view_responsive<'a>( + &'a self, + key_binds: &'a HashMap, + modifiers: &'a Modifiers, size: Size, - ) -> Element<'_, Message> { + ) -> Element<'a, Message> { // Update cached size self.size_opt.set(Some(size)); @@ -5495,7 +5490,7 @@ impl Tab { .on_resize(Message::Resize) .on_back_press(move |_point_opt| Message::GoPrevious) .on_forward_press(move |_point_opt| Message::GoNext) - .on_scroll(|delta| respond_to_scroll_direction(delta, self.modifiers)) + .on_scroll(|delta| respond_to_scroll_direction(delta, modifiers)) .on_right_press(move |p| { Message::ContextMenu( if self.context_menu.is_some() { None } else { p }, @@ -5507,7 +5502,7 @@ impl Tab { let mut popover = widget::popover(mouse_area); if let Some(point) = self.context_menu { if !cfg!(feature = "wayland") || !crate::is_wayland() { - let context_menu = menu::context_menu(self, key_binds, &self.modifiers); + let context_menu = menu::context_menu(self, key_binds, &modifiers); popover = popover .popup(context_menu) .position(widget::popover::Position::Point(point)); @@ -5607,8 +5602,12 @@ impl Tab { dnd_dest.into() } - pub fn view<'a>(&'a self, key_binds: &'a HashMap) -> Element<'a, Message> { - widget::responsive(|size| self.view_responsive(key_binds, size)).into() + pub fn view<'a>( + &'a self, + key_binds: &'a HashMap, + modifiers: &'a Modifiers, + ) -> Element<'a, Message> { + widget::responsive(|size| self.view_responsive(key_binds, modifiers, size)).into() } pub fn subscription(&self, preview: bool) -> Subscription { @@ -5926,7 +5925,7 @@ impl Tab { } } -pub fn respond_to_scroll_direction(delta: ScrollDelta, modifiers: Modifiers) -> Option { +pub fn respond_to_scroll_direction(delta: ScrollDelta, modifiers: &Modifiers) -> Option { if !modifiers.control() { return None; } @@ -6401,7 +6400,7 @@ mod tests { #[test] fn tab_scroll_up_with_ctrl_modifier_zooms() -> io::Result<()> { let message_maybe = - respond_to_scroll_direction(ScrollDelta::Pixels { x: 0.0, y: 1.0 }, Modifiers::CTRL); + respond_to_scroll_direction(ScrollDelta::Pixels { x: 0.0, y: 1.0 }, &Modifiers::CTRL); assert!(message_maybe.is_some()); assert!(matches!(message_maybe.unwrap(), Message::ZoomIn)); Ok(()) @@ -6409,8 +6408,10 @@ mod tests { #[test] fn tab_scroll_up_without_ctrl_modifier_does_not_zoom() -> io::Result<()> { - let message_maybe = - respond_to_scroll_direction(ScrollDelta::Pixels { x: 0.0, y: 1.0 }, Modifiers::empty()); + let message_maybe = respond_to_scroll_direction( + ScrollDelta::Pixels { x: 0.0, y: 1.0 }, + &Modifiers::empty(), + ); assert!(message_maybe.is_none()); Ok(()) } @@ -6418,7 +6419,7 @@ mod tests { #[test] fn tab_scroll_down_with_ctrl_modifier_zooms() -> io::Result<()> { let message_maybe = - respond_to_scroll_direction(ScrollDelta::Pixels { x: 0.0, y: -1.0 }, Modifiers::CTRL); + respond_to_scroll_direction(ScrollDelta::Pixels { x: 0.0, y: -1.0 }, &Modifiers::CTRL); assert!(message_maybe.is_some()); assert!(matches!(message_maybe.unwrap(), Message::ZoomOut)); Ok(()) @@ -6428,7 +6429,7 @@ mod tests { fn tab_scroll_down_without_ctrl_modifier_does_not_zoom() -> io::Result<()> { let message_maybe = respond_to_scroll_direction( ScrollDelta::Pixels { x: 0.0, y: -1.0 }, - Modifiers::empty(), + &Modifiers::empty(), ); assert!(message_maybe.is_none()); Ok(())