Skip to content

Commit

Permalink
Allow editor to create newfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve0Greatness committed Sep 27, 2024
1 parent bf065fd commit 2e16afc
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions views/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ <h1>${output.metadata["title"]}</h1>

var editorenv = {
"oldcontent": "",
"filename": ""
"filename": "",
"newpage": false
}
var editorcodemirror;
var PyodideCached;
Expand Down Expand Up @@ -273,10 +274,12 @@ <h1>${output.metadata["title"]}</h1>
break;
default:
content = defaultcontent;
editorenv.newpage = true;
break;
}

editorenv.oldcontent = content;
if (!editorenv.newpage)
editorenv.oldcontent = content;
editorenv.filename = LikelyPath;

editorcodemirror = CodeMirror(document.querySelector("#editspace"), {
Expand All @@ -302,7 +305,10 @@ <h1>${output.metadata["title"]}</h1>

function exportpatch() {
const newcontent = editorcodemirror.getValue();
const diff = Diff.createPatch(editorenv.filename, editorenv.oldcontent, newcontent);
var diff = Diff.createPatch(editorenv.filename, editorenv.oldcontent, newcontent);

if (editorenv.newpage)
diff = diff.replace(/(?<=={67}\n--- ).*(?=\n)/, "/dev/null");

const tempanchor = document.createElement("a")
tempanchor.href = "data:text/plain;charset=utf-8," + encodeURIComponent(diff);
Expand Down

0 comments on commit 2e16afc

Please sign in to comment.