From 583c961c0158fd44817695225e06d07caa18657e Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Sun, 24 Nov 2024 16:19:46 +1300 Subject: Fix file device cached child issue When opening the previously-visited directory in the file device, the directory data is read from a cache, preventing the need to have it regenerated from scratch. The directory data includes the selected child, which meant that instead of child 0 being selected as per the specification, the previously-selected child was selected instead. To fix this, the child is deselected as the directory data is cached. --- src/devices/file_device.rs | 4 +++- src/devices/file_device/directory_listing.rs | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/devices/file_device.rs b/src/devices/file_device.rs index 00a2f69..61966b1 100644 --- a/src/devices/file_device.rs +++ b/src/devices/file_device.rs @@ -81,7 +81,9 @@ impl FileDevice { self.path_buffer.clear(); self.flush(); - if let Some((Entry::Directory(dir), path)) = std::mem::take(&mut self.entry) { + if let Some((Entry::Directory(mut dir), path)) = std::mem::take(&mut self.entry) { + // Prevent the selected child from persisting when loading from cache. + dir.deselect_child(); self.cached_dir = Some((Entry::Directory(dir), path)); } } diff --git a/src/devices/file_device/directory_listing.rs b/src/devices/file_device/directory_listing.rs index 1d7ddd2..465efc7 100644 --- a/src/devices/file_device/directory_listing.rs +++ b/src/devices/file_device/directory_listing.rs @@ -100,6 +100,11 @@ impl DirectoryListing { } } + pub fn deselect_child(&mut self) { + self.child_path_buffer.clear(); + self.selected = None; + } + pub fn child_path_buffer(&mut self) -> &mut BedrockPathBuffer { &mut self.child_path_buffer } -- cgit v1.2.3-70-g09d2