Skip to content

Commit 3ef8939

Browse files
committed
[fix] constraints check for editing file names
1 parent 72b6fb8 commit 3ef8939

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/routes/tutorial/[slug]/+page.svelte

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,9 @@
105105
},
106106
107107
edit: async (to_rename, new_name) => {
108-
const illegal_rename =
109-
!editing_constraints.remove.some((r) => to_rename.name === r) ||
110-
!editing_constraints.create.some((c) => new_name === c);
111-
if (illegal_rename) {
112-
modal_text =
113-
'Only the following files and folders are allowed to be renamed in this tutorial chapter:\n' +
114-
editing_constraints.remove.join('\n') +
115-
'\n\nThey can only be renamed to the following:\n' +
116-
editing_constraints.create.join('\n');
117-
return;
118-
}
119-
120108
/** @type {Array<[import('$lib/types').Stub, import('$lib/types').Stub]>}*/
121109
const changed = [];
122-
current_stubs = current_stubs.map((s) => {
110+
const updated_stubs = current_stubs.map((s) => {
123111
if (!s.name.startsWith(to_rename.name)) {
124112
return s;
125113
}
@@ -135,6 +123,19 @@
135123
return new_stub;
136124
});
137125
126+
const illegal_rename =
127+
!editing_constraints.remove.some((r) => to_rename.name === r) ||
128+
changed.some(([, s]) => !editing_constraints.create.some((c) => s.name === c));
129+
if (illegal_rename) {
130+
modal_text =
131+
'Only the following files and folders are allowed to be renamed in this tutorial chapter:\n' +
132+
editing_constraints.remove.join('\n') +
133+
'\n\nThey can only be renamed to the following:\n' +
134+
editing_constraints.create.join('\n');
135+
return;
136+
}
137+
138+
current_stubs = updated_stubs;
138139
await load_files(current_stubs);
139140
140141
if (to_rename.type === 'file') {

0 commit comments

Comments
 (0)