Skip to content

Commit 8e36aea

Browse files
matej21claude
andcommitted
fix: refresh file tree when reopening cached file viewer
The cached FileViewer entity scanned files once at creation and never rescanned, so added/removed files wouldn't appear in the sidebar. Now refresh_file_tree() runs on every reopen and can be triggered manually with the 'r' key. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 488833d commit 8e36aea

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

crates/okena-files/src/file_viewer/mod.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,15 @@ impl FileViewer {
316316
}
317317

318318
/// Update configuration (font size and dark mode) from the host app.
319-
/// Also refreshes all tabs that were modified externally.
319+
/// Also refreshes the file tree and all tabs that were modified externally.
320320
pub fn update_config(&mut self, font_size: f32, is_dark: bool) {
321321
let rehighlight = is_dark != self.is_dark;
322322
self.file_font_size = font_size;
323323
self.is_dark = is_dark;
324324

325+
// Rescan project files so the sidebar reflects added/removed files
326+
self.refresh_file_tree();
327+
325328
for tab in &mut self.tabs {
326329
if tab.is_empty() {
327330
continue;
@@ -341,6 +344,28 @@ impl FileViewer {
341344
}
342345
}
343346

347+
/// Rescan the project directory and rebuild the file tree.
348+
/// Preserves expanded folders and updates file indices on open tabs.
349+
fn refresh_file_tree(&mut self) {
350+
let files = FileSearchDialog::scan_files(&self.project_path);
351+
let file_tree = build_file_tree(
352+
files
353+
.iter()
354+
.enumerate()
355+
.map(|(i, f)| (i, f.relative_path.as_str())),
356+
);
357+
358+
// Update file indices on open tabs to match the new file list
359+
for tab in &mut self.tabs {
360+
if !tab.is_empty() {
361+
tab.selected_file_index = files.iter().position(|f| f.path == tab.file_path);
362+
}
363+
}
364+
365+
self.files = files;
366+
self.file_tree = file_tree;
367+
}
368+
344369
/// Check if the active tab's file was modified externally and reload if so.
345370
/// Throttled to at most once per second.
346371
pub(super) fn check_active_tab_freshness(&mut self) {

crates/okena-files/src/file_viewer/render.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,10 @@ impl Render for FileViewer {
638638
"w" if modifiers.platform || modifiers.control => {
639639
this.close_active_tab(cx);
640640
}
641+
"r" if !modifiers.platform && !modifiers.control => {
642+
this.refresh_file_tree();
643+
cx.notify();
644+
}
641645
"left" if modifiers.alt => {
642646
this.go_back(cx);
643647
}

0 commit comments

Comments
 (0)