Enable renames

This commit is contained in:
Andrew Morris
2023-03-27 19:16:00 +11:00
parent 491042d8b7
commit 80fbe4bee8
2 changed files with 32 additions and 0 deletions

View File

@@ -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);
}
}

View File

@@ -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