Skip to main content

vtcode_tui/core_tui/session/file_palette/
mod.rs

1use std::path::PathBuf;
2
3use crate::ui::FileColorizer;
4
5mod filtering;
6mod navigation;
7mod references;
8
9pub use references::extract_file_reference;
10
11const PAGE_SIZE: usize = 20;
12
13#[derive(Debug, Clone)]
14pub struct FileEntry {
15    pub path: String,
16    #[allow(dead_code)]
17    pub display_name: String,
18    pub relative_path: String,
19    pub is_dir: bool,
20}
21
22pub struct FilePalette {
23    all_files: Vec<FileEntry>,
24    filtered_files: Vec<FileEntry>,
25    selected_index: usize,
26    current_page: usize,
27    filter_query: String,
28    workspace_root: PathBuf,
29    filter_cache: hashbrown::HashMap<String, Vec<FileEntry>>,
30    #[allow(dead_code)]
31    file_colorizer: FileColorizer,
32}
33
34impl FilePalette {
35    pub fn new(workspace_root: PathBuf) -> Self {
36        Self {
37            all_files: Vec::new(),
38            filtered_files: Vec::new(),
39            selected_index: 0,
40            current_page: 0,
41            filter_query: String::new(),
42            workspace_root,
43            filter_cache: hashbrown::HashMap::new(),
44            file_colorizer: FileColorizer::new(),
45        }
46    }
47
48    /// Reset selection and filter (call when opening file browser)
49    #[allow(dead_code)]
50    pub fn reset(&mut self) {
51        self.selected_index = 0;
52        self.current_page = 0;
53        self.filter_query.clear();
54        self.apply_filter(); // Refresh filtered_files to show all
55    }
56
57    /// Clean up resources to free memory (call when closing file browser)
58    pub fn cleanup(&mut self) {
59        self.filter_cache.clear();
60        self.filtered_files.clear();
61        self.filtered_files.shrink_to_fit();
62    }
63}
64
65#[cfg(test)]
66mod tests;