mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
Enable renames
This commit is contained in:
@@ -52,4 +52,15 @@ export default class FileSystem {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rename(file: string, newFile: string): void {
|
||||
const content = this.read(file);
|
||||
|
||||
if (content === nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.write(newFile, content, file);
|
||||
this.write(file, nil);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,6 +296,27 @@ editorEl.innerHTML = '';
|
||||
editor.setValue(defaultContent);
|
||||
}
|
||||
};
|
||||
|
||||
renameBtn.onclick = async () => {
|
||||
const currentParts = currentFile.split('/');
|
||||
|
||||
const prefill = currentParts.length === 1
|
||||
? ''
|
||||
: `${currentParts.slice(0, -1).join('/')}/`;
|
||||
|
||||
const popup = await Swal.fire({
|
||||
title: 'Rename File',
|
||||
input: 'text',
|
||||
inputValue: prefill,
|
||||
inputPlaceholder: currentFile,
|
||||
});
|
||||
|
||||
if (typeof popup.value === 'string' && popup.value !== '') {
|
||||
const newFile = popup.value.endsWith('.ts') ? popup.value : `${popup.value}.ts`;
|
||||
fs.rename(currentFile, newFile);
|
||||
changeFile(newFile);
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
|
||||
Reference in New Issue
Block a user