Krolyxon
Commit ba154a3

rmptuiba154a3

fix appending songs

Author
krolxon
Date
2024-04-26 20:15 +0530
Parent
e500c52
Commit
ba154a307e5b28e8131d1c3d98847c5710b4ecc8

+20 −10

1 file changed

  1. M src/handler.rs +20 −10
M src/handler.rs View
@@ -4,7 +4,7 @@ use crate::{
44 app::{App, AppResult, SelectedTab},
55 ui::InputMode,
66 };
7−use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
7+use crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyEventState, KeyModifiers};
88 use rust_fuzzy_search::{self, fuzzy_search_sorted};
99 use simple_dmenu::dmenu;
1010
@@ -79,6 +79,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
7979 } else {
8080 app.conn.conn.clear()?;
8181 app.conn.update_status();
82+ app.queue_list.list.clear();
8283 }
8384 }
8485
@@ -154,21 +155,28 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
154155
155156 // add to queue
156157 KeyCode::Char('a') => {
157− // let song = app.conn.get_song_with_only_filename(
158− // app.conn.songs_filenames.get(app.song_list.index).unwrap(),
159− // );
160−
161158 let list = app
162159 .conn
163160 .songs_filenames
164161 .iter()
165162 .map(|f| f.as_str())
166163 .collect::<Vec<&str>>();
167− let (filename, _) =
168− rust_fuzzy_search::fuzzy_search_sorted(&app.browser.path, &list)
169− .get(0)
170− .unwrap()
171− .clone();
164+
165+ let files: Vec<String> = app
166+ .browser
167+ .filetree
168+ .clone()
169+ .into_iter()
170+ .map(|(_, f)| f)
171+ .collect();
172+
173+ let (filename, _) = rust_fuzzy_search::fuzzy_search_sorted(
174+ &files.get(app.browser.selected).unwrap(),
175+ &list,
176+ )
177+ .get(0)
178+ .unwrap()
179+ .clone();
172180
173181 let song = app.conn.get_song_with_only_filename(filename);
174182
@@ -180,6 +188,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
180188 .push_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
181189 }
182190
191+ // Fast forward
183192 KeyCode::Char('f') => {
184193 let place = app.conn.conn.status().unwrap().song.unwrap().pos;
185194 let (pos, _) = app.conn.conn.status().unwrap().time.unwrap();
@@ -187,6 +196,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
187196 app.conn.conn.seek(place, pos)?;
188197 }
189198
199+ // backward
190200 KeyCode::Char('b') => {
191201 let place = app.conn.conn.status().unwrap().song.unwrap().pos;
192202 let (pos, _) = app.conn.conn.status().unwrap().time.unwrap();