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 <noreply@anthropic.com>
This commit is contained in:
Rob CoenenandClaude Opus 5.5 committed 2026-11-24 17:18:55 +01:00
1 parent af3abf3396
commit b474a01a27
3 files changed
+15 -4

No files matched your search

+7 -3
View File
@@ -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() };
+4 -1
View File
@@ -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),
+4
View File
@@ -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"]);