Skip to content
This repository was archived by the owner on Oct 22, 2021. It is now read-only.

Commit 6da52a8

Browse files
authored
Implement a text editor feature (#875)
1 parent e88017d commit 6da52a8

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

src/_renderer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,12 @@ window.openSettings = async () => {
807807
});
808808
};
809809

810+
window.writeFile = (path) => {
811+
fs.writeFile(path, document.getElementById("fileEdit").value, "utf-8", () => {
812+
document.getElementById("fedit-status").innerHTML = "<i>File saved.</i>";
813+
});
814+
}
815+
810816
window.writeSettingsFile = () => {
811817
window.settings = {
812818
shell: document.getElementById("settingsEditor-shell").value,

src/assets/css/modal.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,19 @@ div.modal_popup table:not(#settingsEditor) td:first-child {
144144
text-align: center;
145145
}
146146

147+
div.modal_popup textarea {
148+
background: var(--color_light_black);
149+
color: rgb(var(--color_r), var(--color_g), var(--color_b));
150+
border: 0.15vh solid rgb(var(--color_r), var(--color_g), var(--color_b));
151+
padding: 0.4vh 0.2vh;
152+
font-size: 1.4vh;
153+
resize: none;
154+
}
155+
156+
div.modal_popup textarea:active, div.modal_popup textarea:focus {
157+
outline: none !important;
158+
}
159+
147160
div.modal_popup td input {
148161
width: 100%;
149162
background: var(--color_light_black);

src/classes/filesystem.class.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,10 @@ class FilesystemDisplay {
346346
}
347347
}
348348

349+
if (e.type === "file") {
350+
cmd = `window.fsDisp.openFile(${blockIndex})`
351+
}
352+
349353
if (e.type === "system") {
350354
cmd = "";
351355
}
@@ -542,6 +546,65 @@ class FilesystemDisplay {
542546
this.readFS(window.term[window.currentTerm].cwd || window.settings.cwd);
543547
}
544548

549+
this.openFile = (name, path, type) => { //Might add text formatting at some point, not now though - Surge
550+
let block;
551+
552+
if (typeof name === "number") {
553+
block = this.cwd[name];
554+
name = block.name
555+
}
556+
557+
block.path = block.path.replace(/\\/g, "/");
558+
559+
let filetype = name.split(".")[name.split(".").length - 1];
560+
switch (filetype) {
561+
case "xml":
562+
case "yaml":
563+
case "java":
564+
case "cs":
565+
case "cpp":
566+
case "h":
567+
case "html":
568+
case "css":
569+
case "js":
570+
case "md":
571+
case "log":
572+
case "bat":
573+
case "sh":
574+
case "gd":
575+
//To anyone else working with this: Feel free to add on to this list. - Surge
576+
case "txt":
577+
case "json":
578+
fs.readFile(block.path, 'utf-8', (err, data) => {
579+
if (err) {
580+
new Modal({
581+
type: "info",
582+
title: "Failed to load file: " + block.path,
583+
html: err
584+
});
585+
console.log(err);
586+
};
587+
window.keyboard.detach();
588+
new Modal(
589+
{
590+
type: "custom",
591+
title: _escapeHtml(name),
592+
html: `<textarea id="fileEdit" rows="40" cols="150" spellcheck="false">${data}</textarea><p id="fedit-status"></p>`,
593+
buttons: [
594+
{label:"Save to Disk",action:`window.writeFile('${block.path}')`}
595+
]
596+
}, () => {
597+
window.keyboard.attach();
598+
window.term[window.currentTerm].term.focus();
599+
}
600+
);
601+
});
602+
break;
603+
default:
604+
return;
605+
}
606+
}
607+
545608
this.openMedia = (name, path, type) => {
546609
let block, html;
547610

0 commit comments

Comments
 (0)