diff --git a/CHANGELOG.md b/CHANGELOG.md index 142544692..1b20b8650 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Add maximum delay required for two consecutive clicks to be interpreted as a double-click + ### Fixed - All requests are correctly proxied when the relevant environment variables are set diff --git a/src/ui/listview.rs b/src/ui/listview.rs index 8712297a7..a82c36783 100644 --- a/src/ui/listview.rs +++ b/src/ui/listview.rs @@ -2,6 +2,7 @@ use cursive::view::scroll::Scroller; use log::info; use std::cmp::{max, min, Ordering}; use std::sync::{Arc, RwLock}; +use std::time::{Duration, Instant}; use cursive::align::HAlign; use cursive::event::{Callback, Event, EventResult, MouseButton, MouseEvent}; @@ -32,6 +33,8 @@ use crate::ui::artist::ArtistView; use crate::ui::contextmenu::ContextMenu; use crate::ui::pagination::Pagination; +const DOUBLE_CLICK_TIME: Duration = Duration::from_millis(200); + pub struct ListView { content: Arc>>, last_content_len: usize, @@ -45,6 +48,7 @@ pub struct ListView { library: Arc, pagination: Pagination, title: String, + last_click_time: Instant, } impl Scroller for ListView { @@ -72,6 +76,7 @@ impl ListView { library, pagination: Pagination::default(), title: "".to_string(), + last_click_time: Instant::now(), }; result.try_paginate(); result @@ -388,7 +393,10 @@ impl View for ListView { let currently_selected_is_individual = currently_selected_listitem .filter(|item| item.track().is_some()) .is_some(); - if self.selected == clicked_row_index && currently_selected_is_individual { + if self.selected == clicked_row_index + && currently_selected_is_individual + && self.last_click_time.elapsed() < DOUBLE_CLICK_TIME + { // The selected position was already focused. Play the item at the // position as if Enter was pressed. This sort of emulates double // clicking, which isn't supported by Cursive. @@ -405,6 +413,8 @@ impl View for ListView { let clicked_list_item = content.get(self.selected).map(ListItem::as_listitem); + self.last_click_time = Instant::now(); + if let Some(target) = clicked_list_item { if let Some(view) = target.open(self.queue.clone(), self.library.clone())