diff --git a/crates/engine/src/cmds_file.rs b/crates/engine/src/cmds_file.rs index aa8938dc..6e6c8792 100644 --- a/crates/engine/src/cmds_file.rs +++ b/crates/engine/src/cmds_file.rs @@ -204,11 +204,15 @@ impl Import { /// The import of `source`, as the disk has it now. pub fn of(source: &std::path::Path) -> Import { let package = import_package(source); - // "." or "walk/sub/.." has no name of its own: resolve it, or the suggestion would land - // inside the package as "animation.anicraft". + // "." or "walk/sub/.." has no name of its own, and nor does the empty folder a bare + // "walk.xfl" is in: resolve it, or the suggestion would land inside the package as + // "animation.anicraft". let package = match package.file_name() { Some(_) => package, - None => std::fs::canonicalize(&package).unwrap_or(package), + None => { + let here = if package.as_os_str().is_empty() { std::path::Path::new(".") } else { package.as_path() }; + std::fs::canonicalize(here).unwrap_or(package) + } }; // A folder's whole name ("walk.v2" stays "walk.v2"); a file's without its extension. let name = if crate::vfs::is_dir(&package) { package.file_name() } else { package.file_stem() }; diff --git a/src/tabs.rs b/src/tabs.rs index fd7b4f12..94fb60ed 100644 --- a/src/tabs.rs +++ b/src/tabs.rs @@ -206,7 +206,10 @@ impl Tabs { /// A document's name on its tab: the file's, the Animate file's it was imported from (ADR 0009), /// or "Untitled" (numbered from the second on). fn name_of(untitled: u32, s: &Session) -> String { - match s.path.as_deref().or(s.imported.as_ref().map(|i| i.source.as_path())).and_then(Path::file_name) { + // An import is named after what was opened, or after its folder when that path has no + // name of its own ("walk/sub/.."). + let imported = s.imported.as_ref().and_then(|i| i.source.file_name().or_else(|| i.package.file_name())); + match s.path.as_deref().and_then(Path::file_name).or(imported) { Some(n) => n.to_string_lossy().into_owned(), None if untitled <= 1 => tr!("Untitled").to_string(), None => tr!("Untitled {n}", n = untitled), diff --git a/src/tabs_tests.rs b/src/tabs_tests.rs index 9c25594e..25ad8692 100644 --- a/src/tabs_tests.rs +++ b/src/tabs_tests.rs @@ -101,6 +101,10 @@ fn an_import_is_named_after_its_animate_file_until_it_is_saved() { assert_eq!(spoken(t), "primitives, imported"); assert_eq!(window_title(&app), "AniCraft — primitives (imported)"); assert_eq!(app.save_suggestion(), corpus.join("primitives.anicraft").display().to_string(), "beside the XFL folder"); + // Reached through "..", it is still named after its folder. + let (_, mut other) = self::app(); + other.request("file.open", json!({"path": folder.join("golden").join("..").display().to_string()})); + assert_eq!(names(&other), ["primitives"]); // A new document is "Untitled": the import has a name of its own. app.request("file.new", json!({})); assert_eq!(names(&app), ["primitives", "Untitled"]);