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:
@ -13,6 +13,7 @@ import crossPlatformFetch from './crossPlatformFetch'
|
||||
import { isTauri } from './isTauri'
|
||||
import { Themes } from './theme'
|
||||
import { commandBarMachine } from 'machines/commandBarMachine'
|
||||
import { getNextFileName } from './tauriFS'
|
||||
|
||||
export async function submitTextToCadPrompt(
|
||||
prompt: string,
|
||||
@ -166,7 +167,7 @@ export async function submitAndAwaitTextToKcl({
|
||||
showFailureToast('Failed to generate parametric model')
|
||||
return e
|
||||
})
|
||||
.then((value) => {
|
||||
.then(async (value) => {
|
||||
if (value.code === undefined || !value.code || value.code.length === 0) {
|
||||
// We want to show the real error message to the user.
|
||||
if (value.error && value.error.length > 0) {
|
||||
@ -180,13 +181,23 @@ export async function submitAndAwaitTextToKcl({
|
||||
}
|
||||
|
||||
const TRUNCATED_PROMPT_LENGTH = 24
|
||||
const newFileName = `${value.prompt
|
||||
let newFileName = `${value.prompt
|
||||
.slice(0, TRUNCATED_PROMPT_LENGTH)
|
||||
.replace(/\s/gi, '-')
|
||||
.replace(/\W/gi, '-')
|
||||
.toLowerCase()}`
|
||||
.toLowerCase()}${FILE_EXT}`
|
||||
|
||||
if (isTauri()) {
|
||||
// We have to pre-emptively run our unique file name logic,
|
||||
// so that we can pass the unique file name to the toast,
|
||||
// and by extension the file-deletion-on-reject logic.
|
||||
newFileName = (
|
||||
await getNextFileName({
|
||||
entryName: newFileName,
|
||||
baseDir: context.selectedDirectory.path,
|
||||
})
|
||||
).name
|
||||
|
||||
fileMachineSend({
|
||||
type: 'Create file',
|
||||
data: {
|
||||
@ -194,14 +205,13 @@ export async function submitAndAwaitTextToKcl({
|
||||
makeDir: false,
|
||||
content: value.code,
|
||||
silent: true,
|
||||
makeUnique: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
...value,
|
||||
fileName: newFileName + FILE_EXT,
|
||||
fileName: newFileName,
|
||||
}
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user