From b474a01a2784c0df45dfdb8a75a2362986476ca4 Mon Sep 17 00:00:00 2001 From: Rob Coenen <753704+rcoenen@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:18:55 +0100 Subject: [PATCH] fix(shell): an import reached through a nameless path keeps its name Review follow-ups (ADR 0009 note): * A bare relative "walk.xfl" has an empty package folder: it resolves as ".", so Save suggests an .anicraft beside the folder, not inside it. * When the opened path has no name of its own ("walk/sub/.."), the tab and window title use the package folder's name instead of "Untitled". Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmds_file.rs | 10 +++++++--- src/tabs.rs | 5 ++++- src/tabs_tests.rs | 4 ++++ 3 files changed, 15 insertions(+), 4 deletions(-) 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"]);