fix(file-explorer): prevent entering files as directories (#5383)
The file_explorer example had two issues: 1. Used heuristic (contains '.') to detect files vs directories, which is unreliable 2. Tried to enter files as directories when clicked, causing errors Changes: - Use path.is_file() for accurate file detection - Use path.is_dir() check before entering a directory - Rename shadowed 'path' variable to 'path_display' Fixes #5368 Co-authored-by: BillionClaw <267901332+BillionClaw@users.noreply.github.com>
This commit is contained in:
1 parent
049e4416f2
commit
be7296f4f0
1 file changed
+7
-3
@@ -31,12 +31,13 @@ fn app() -> Element {
|
|||||||
for (dir_id, path) in files.read().path_names.iter().enumerate() {
|
for (dir_id, path) in files.read().path_names.iter().enumerate() {
|
||||||
{
|
{
|
||||||
let path_end = path.components().next_back().map(|p|p.as_os_str()).unwrap_or(path.as_os_str()).to_string_lossy();
|
let path_end = path.components().next_back().map(|p|p.as_os_str()).unwrap_or(path.as_os_str()).to_string_lossy();
|
||||||
let path = path.display();
|
let path_display = path.display();
|
||||||
|
let is_file = path.is_file();
|
||||||
rsx! {
|
rsx! {
|
||||||
div { class: "folder", key: "{path}",
|
div { class: "folder", key: "{path_display}",
|
||||||
i { class: "material-icons",
|
i { class: "material-icons",
|
||||||
onclick: move |_| files.write().enter_dir(dir_id),
|
onclick: move |_| files.write().enter_dir(dir_id),
|
||||||
if path_end.contains('.') {
|
if is_file {
|
||||||
"description"
|
"description"
|
||||||
} else {
|
} else {
|
||||||
"folder"
|
"folder"
|
||||||
@@ -115,6 +116,9 @@ impl Files {
|
|||||||
|
|
||||||
fn enter_dir(&mut self, dir_id: usize) {
|
fn enter_dir(&mut self, dir_id: usize) {
|
||||||
let path = &self.path_names[dir_id];
|
let path = &self.path_names[dir_id];
|
||||||
|
if !path.is_dir() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
self.current_path.clone_from(path);
|
self.current_path.clone_from(path);
|
||||||
self.reload_path_list();
|
self.reload_path_list();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user