fix: reserve Untitled Project name; rename project will trigger save immidiatly.

This commit is contained in:
Xiaohan-Tian
2026-04-16 20:24:43 -07:00
parent 3010cf4e2d
commit 24ffaa76f6
5 changed files with 79 additions and 11 deletions
+14 -1
View File
@@ -9,6 +9,12 @@ const VALID_PROJECT_NAME_REGEX = /^[a-zA-Z0-9 \-_.()\u00C0-\u024F]+$/;
*/
const DISALLOWED_CHARS_REGEX = /[^a-zA-Z0-9 \-_.()\u00C0-\u024F]/g;
/**
* The reserved project name used for unsaved/new projects.
* Users cannot rename a project to this name, and its OPFS folder is wiped on every startup.
*/
export const RESERVED_PROJECT_NAME = "Untitled Project";
/**
* Validate whether a project name contains only allowed characters.
* Does NOT check for empty string — caller should check that separately.
@@ -19,6 +25,13 @@ export function isValidProjectName(name: string): boolean {
return VALID_PROJECT_NAME_REGEX.test(name);
}
/**
* Returns true if the given name matches the reserved "Untitled Project" name.
*/
export function isReservedProjectName(name: string): boolean {
return name.trim() === RESERVED_PROJECT_NAME;
}
/**
* Sanitize a project name by replacing disallowed characters with underscores,
* collapsing consecutive underscores/spaces, and trimming.
@@ -37,7 +50,7 @@ export function sanitizeProjectName(name: string): string {
// If everything was stripped, provide a fallback
if (sanitized.length === 0) {
sanitized = 'Untitled Project';
sanitized = RESERVED_PROJECT_NAME;
}
return sanitized;