Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add double click time limit #1416

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion src/ui/listview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<I: ListItem> {
content: Arc<RwLock<Vec<I>>>,
last_content_len: usize,
Expand All @@ -45,6 +48,7 @@ pub struct ListView<I: ListItem> {
library: Arc<Library>,
pagination: Pagination<I>,
title: String,
last_click_time: Instant,
}

impl<I: ListItem> Scroller for ListView<I> {
Expand Down Expand Up @@ -72,6 +76,7 @@ impl<I: ListItem + Clone> ListView<I> {
library,
pagination: Pagination::default(),
title: "".to_string(),
last_click_time: Instant::now(),
};
result.try_paginate();
result
Expand Down Expand Up @@ -388,7 +393,10 @@ impl<I: ListItem + Clone> View for ListView<I> {
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.
Expand All @@ -405,6 +413,8 @@ impl<I: ListItem + Clone> View for ListView<I> {
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())
Expand Down