From 4f55810f729fc61e22eafa7ea69afe79bcfe1cb6 Mon Sep 17 00:00:00 2001 From: morning-star <1453017105@qq.com> Date: Sat, 8 Jul 2023 15:33:15 +0800 Subject: [PATCH] fix: filename index auto-increment (#133) --- src/editor/FileSelector.vue | 4 ++-- src/store.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/editor/FileSelector.vue b/src/editor/FileSelector.vue index 0978acea..d3cc1a9c 100644 --- a/src/editor/FileSelector.vue +++ b/src/editor/FileSelector.vue @@ -32,8 +32,8 @@ function startAddFile() { while (true) { let hasConflict = false - for (const file in store.state.files) { - if (file === name) { + for (const filename in store.state.files) { + if (stripSrcPrefix(filename) === name) { hasConflict = true name = `Comp${++i}.vue` break diff --git a/src/store.ts b/src/store.ts index 38a72253..e221f0f4 100644 --- a/src/store.ts +++ b/src/store.ts @@ -310,7 +310,7 @@ export class ReplStore implements Store { const exported: Record = {} for (const filename in this.state.files) { const normalized = - filename === importMapFile ? filename : filename.replace(/^src\//, '') + filename === importMapFile ? filename : stripSrcPrefix(filename) exported[normalized] = this.state.files[filename].code } return exported