Small corrections
Some checks failed
Deploy Website / deploy (push) Failing after 4m51s

This commit is contained in:
2026-02-08 01:33:50 +01:00
parent 8ffe2c22c7
commit 1f339f1503
20 changed files with 288 additions and 49 deletions

View File

@@ -43,5 +43,5 @@ pub use patterns_nav::{PatternsColumn, PatternsNav};
pub use mute::MuteState;
pub use playback::{PlaybackState, StagedChange, StagedMuteChange, StagedPropChange};
pub use project::ProjectState;
pub use sample_browser::SampleBrowserState;
pub use sample_browser::{SampleBrowserState, SampleTree};
pub use ui::{DictFocus, FlashKind, HelpFocus, UiState};

View File

@@ -1,7 +1,7 @@
use std::fs;
use std::path::{Path, PathBuf};
use cagire_ratatui::{TreeLine, TreeLineKind};
use cagire_ratatui::{fuzzy_match, TreeLine, TreeLineKind};
const AUDIO_EXTENSIONS: &[&str] = &["wav", "flac", "ogg", "aiff", "aif", "mp3"];
@@ -208,6 +208,29 @@ impl SampleTree {
})
}
pub fn all_folder_names(&self) -> Vec<String> {
let mut names = Vec::new();
for root in &self.roots {
Self::collect_folder_names(root, &mut names);
}
names.sort_by_key(|n| n.to_lowercase());
names
}
fn collect_folder_names(node: &SampleNode, out: &mut Vec<String>) {
match node {
SampleNode::Root { children, .. } => {
for child in children {
Self::collect_folder_names(child, out);
}
}
SampleNode::Folder { name, .. } => {
out.push(name.clone());
}
SampleNode::File { .. } => {}
}
}
pub fn visible_entries(&self) -> Vec<TreeLine> {
let mut out = Vec::new();
for root in &self.roots {
@@ -558,31 +581,6 @@ impl SampleBrowserState {
}
}
fn fuzzy_match(query: &str, target: &str) -> Option<usize> {
let target_lower: Vec<char> = target.to_lowercase().chars().collect();
let query_lower: Vec<char> = query.to_lowercase().chars().collect();
let mut ti = 0;
let mut score = 0;
let mut prev_pos = 0;
for (qi, &qc) in query_lower.iter().enumerate() {
loop {
if ti >= target_lower.len() {
return None;
}
if target_lower[ti] == qc {
if qi > 0 {
score += ti - prev_pos;
}
prev_pos = ti;
ti += 1;
break;
}
ti += 1;
}
}
Some(score)
}
fn is_audio_file(name: &str) -> bool {
let lower = name.to_lowercase();
AUDIO_EXTENSIONS.iter().any(|ext| lower.ends_with(ext))