Skip to content

Commit

Permalink
Fix FileManager's file creation bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Fr0stbyteR authored and sletz committed Jan 4, 2024
1 parent 4dfb7cc commit 72fef1f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/FileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ export class FileManager {
this.fs = options.fs;
this.path = options.path;
this.$mainFile = options.$mainFile;
this.getChildren();
this.getFiles();
this.bind();
this.selectHandler = options.selectHandler;
this.saveHandler = options.saveHandler;
this.deleteHandler = options.deleteHandler;
this.mainFileChangeHandler = options.mainFileChangeHandler;
this.getChildren();
this.getFiles();
this.bind();
this.select(this._fileList[options.$mainFile]);
}
getChildren() {
Expand Down Expand Up @@ -158,6 +158,9 @@ export class FileManager {
this._fileList.push(fileName);
const divFile = this.createFileDiv(fileName, true);
this.divFiles.appendChild(divFile);
if (this.saveHandler) this.saveHandler(fileName, "", this.mainCode);
this.select(fileName);
if (fileName.endsWith(".dsp")) this.setMain(this._fileList.length - 1);
const spanName = divFile.getElementsByClassName("filemanager-filename")[0] as HTMLSpanElement;
spanName.focus();
const range = document.createRange();
Expand Down Expand Up @@ -272,6 +275,7 @@ export class FileManager {
this.fs.unlink(this.path + fileName);
this._fileList.splice(i, 1);
divFile.remove();
if (this.deleteHandler) this.deleteHandler(fileName, this.mainCode);
if (this._fileList.length === 0) {
const fileName = this.newFile("untitled.dsp", `import("stdfaust.lib");
process = ba.pulsen(1, 10000) : pm.djembe(60, 0.3, 0.4, 1) <: dm.freeverb_demo;`);
Expand All @@ -281,7 +285,6 @@ process = ba.pulsen(1, 10000) : pm.djembe(60, 0.3, 0.4, 1) <: dm.freeverb_demo;`
}
if (this.$mainFile >= this._fileList.length) this.setMain(this._fileList.length - 1);
else this.setMain(this.$mainFile);
if (this.deleteHandler) this.deleteHandler(fileName, this.mainCode);
});
const handlePointerDown = () => this.select(fileName);
divFile.addEventListener("mousedown", handlePointerDown);
Expand Down Expand Up @@ -363,8 +366,9 @@ process = ba.pulsen(1, 10000) : pm.djembe(60, 0.3, 0.4, 1) <: dm.freeverb_demo;`
this.rename(this.selected, newName);
}
newFile(fileNameIn?: string, content?: string) {
let fileName = fileNameIn.replace(/[^a-zA-Z0-9_.]/g, "");
const extension = fileNameIn.split(".").slice(-1) || "lib";
let fileName;
if (fileNameIn) fileName = fileNameIn.replace(/[^a-zA-Z0-9_.]/g, "");
const extension = fileNameIn ? fileNameIn.split(".").slice(-1) || "lib" : "dsp";
if (!fileName || this._fileList.indexOf(fileName) !== -1) {
let i = 1;
fileName = `untitled${i}.${extension}`;
Expand Down

0 comments on commit 72fef1f

Please sign in to comment.