Always give new files and dirs a new index if their names are taken (#3460)
* Add actual support for makeUnique parameter * Add uniqueness logic to dirs, make text-to-cad receive unique filename * No longer need makeUnique flag, it's always on * fmt * Don't show toast when name hasn't changed during a rename * fmt * Get "interact with many" text-to-cad test passing again * Get "engine fails export" back to reliably green * Maybe more stable click target for text-to-cad test * Make "export is already going" test moderately more reliable * Mark "export is already going" as fixme * Undo that fixme thing I take it back
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
import { appConfigDir } from '@tauri-apps/api/path'
|
||||
import { appConfigDir, join } from '@tauri-apps/api/path'
|
||||
import { isTauri } from './isTauri'
|
||||
import type { FileEntry } from 'lib/types'
|
||||
import {
|
||||
FILE_EXT,
|
||||
INDEX_IDENTIFIER,
|
||||
MAX_PADDING,
|
||||
ONBOARDING_PROJECT_NAME,
|
||||
@ -15,6 +16,7 @@ import {
|
||||
readAppSettingsFile,
|
||||
} from './tauri'
|
||||
import { engineCommandManager } from './singletons'
|
||||
import { exists } from '@tauri-apps/plugin-fs'
|
||||
|
||||
export const isHidden = (fileOrDir: FileEntry) =>
|
||||
!!fileOrDir.name?.startsWith('.')
|
||||
@ -162,3 +164,56 @@ export async function createAndOpenNewProject({
|
||||
)
|
||||
return newProject
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next available file name by appending a hyphen and number to the end of the name
|
||||
* @todo move this to the equivalent of tauriFS.ts for Electron migration
|
||||
*/
|
||||
export async function getNextFileName({
|
||||
entryName,
|
||||
baseDir,
|
||||
}: {
|
||||
entryName: string
|
||||
baseDir: string
|
||||
}) {
|
||||
// Remove any existing index from the name before adding a new one
|
||||
let createdName = entryName.replace(FILE_EXT, '') + FILE_EXT
|
||||
let createdPath = await join(baseDir, createdName)
|
||||
let i = 1
|
||||
while (await exists(createdPath)) {
|
||||
const matchOnIndexAndExtension = new RegExp(`(-\\d+)?(${FILE_EXT})?$`)
|
||||
createdName =
|
||||
entryName.replace(matchOnIndexAndExtension, '') + `-${i}` + FILE_EXT
|
||||
createdPath = await join(baseDir, createdName)
|
||||
i++
|
||||
}
|
||||
return {
|
||||
name: createdName,
|
||||
path: createdPath,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next available directory name by appending a hyphen and number to the end of the name
|
||||
* @todo move this to the equivalent of tauriFS.ts for Electron migration
|
||||
*/
|
||||
export async function getNextDirName({
|
||||
entryName,
|
||||
baseDir,
|
||||
}: {
|
||||
entryName: string
|
||||
baseDir: string
|
||||
}) {
|
||||
let createdName = entryName
|
||||
let createdPath = await join(baseDir, createdName)
|
||||
let i = 1
|
||||
while (await exists(createdPath)) {
|
||||
createdName = entryName.replace(/-\d+$/, '') + `-${i}`
|
||||
createdPath = await join(baseDir, createdName)
|
||||
i++
|
||||
}
|
||||
return {
|
||||
name: createdName,
|
||||
path: createdPath,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user