more edit syntax
This commit is contained in:
@@ -580,6 +580,26 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// helper function
|
||||||
|
function getModeForFile(fileName) {
|
||||||
|
const ext = fileName.slice(fileName.lastIndexOf('.') + 1).toLowerCase();
|
||||||
|
switch (ext) {
|
||||||
|
case 'css':
|
||||||
|
return "css";
|
||||||
|
case 'json':
|
||||||
|
return { name: "javascript", json: true };
|
||||||
|
case 'js':
|
||||||
|
return "javascript";
|
||||||
|
case 'html':
|
||||||
|
case 'htm':
|
||||||
|
return "text/html";
|
||||||
|
case 'xml':
|
||||||
|
return "xml";
|
||||||
|
default:
|
||||||
|
return "text/plain";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// File Editing Functions.
|
// File Editing Functions.
|
||||||
export function editFile(fileName, folder) {
|
export function editFile(fileName, folder) {
|
||||||
console.log("Edit button clicked for:", fileName);
|
console.log("Edit button clicked for:", fileName);
|
||||||
@@ -627,9 +647,10 @@ export function editFile(fileName, folder) {
|
|||||||
modal.style.display = "block";
|
modal.style.display = "block";
|
||||||
|
|
||||||
// Initialize CodeMirror on the textarea.
|
// Initialize CodeMirror on the textarea.
|
||||||
|
const mode = getModeForFile(fileName); // fileName should be the current file's name
|
||||||
const editor = CodeMirror.fromTextArea(document.getElementById("fileEditor"), {
|
const editor = CodeMirror.fromTextArea(document.getElementById("fileEditor"), {
|
||||||
lineNumbers: true,
|
lineNumbers: true,
|
||||||
mode: "text/html", // Adjust mode based on file type if needed.
|
mode: mode, // dynamic mode based on file extension
|
||||||
theme: "default",
|
theme: "default",
|
||||||
viewportMargin: Infinity
|
viewportMargin: Infinity
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,10 +16,9 @@
|
|||||||
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/codemirror.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/codemirror.min.css">
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/codemirror.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/codemirror.min.js"></script>
|
||||||
<!-- Load mode(s) you need, e.g., HTML mode: -->
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/mode/xml/xml.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/mode/xml/xml.min.js"></script>
|
||||||
<!-- Optionally, load CSS mode if needed: -->
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/mode/css/css.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/mode/css/css.min.js"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/mode/javascript/javascript.min.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@@ -295,5 +294,4 @@
|
|||||||
<script type="module" src="main.js"></script>
|
<script type="module" src="main.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user