Skip to content

Commit 1a02fdd

Browse files
committed
2 fixes
scrolling in the editor tabs being multi-selected 1 improvment: no longer downloads all files regardless of content
1 parent 88e29ad commit 1a02fdd

File tree

4 files changed

+76
-7
lines changed

4 files changed

+76
-7
lines changed

Build/src/editor.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ function createEditorConfig(
5555
language,
5656
themeCompartment.of(isDarkMode ? monokai : bbedit),
5757
EditorView.lineWrapping,
58+
EditorState.tabSize.of(2),
59+
EditorView.theme({
60+
"&": { height: "100%" },
61+
".cm-scroller": { overflow: "auto" },
62+
".cm-content": { minHeight: "100%" }
63+
}),
5864
search(),
5965
linter(
6066
(view) => {

Build/src/main.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,36 @@ function toggleDarkMode(): void {
306306

307307
// Export editors' content as ZIP
308308
async function exportAsZip() {
309+
const html = editors.html.view.state.doc.toString().trim();
310+
const css = editors.css.view.state.doc.toString().trim();
311+
const js = editors.js.view.state.doc.toString().trim();
312+
313+
const files: { name: string; content: string }[] = [];
314+
if (html) files.push({ name: "index.html", content: html });
315+
if (css) files.push({ name: "styles.css", content: css });
316+
if (js) files.push({ name: "script.js", content: js });
317+
318+
if (files.length === 0) {
319+
alert("Nothing to export!");
320+
return;
321+
}
322+
323+
if (files.length === 1) {
324+
const blob = new Blob([files[0].content], { type: "text/plain" });
325+
saveAs(blob, files[0].name);
326+
return;
327+
}
328+
309329
const zip = new JSZip();
310-
zip.file("index.html", editors.html.view.state.doc.toString());
311-
zip.file("styles.css", editors.css.view.state.doc.toString());
312-
zip.file("script.js", editors.js.view.state.doc.toString());
330+
for (const file of files) {
331+
zip.file(file.name, file.content);
332+
}
333+
313334
const content = await zip.generateAsync({ type: "blob" });
314335
saveAs(content, "htmlrunner-export.zip");
315336
}
316337

338+
317339
// Copy console content
318340
function copyAllConsole(): void {
319341
const entries = Array.from(consoleOutput.children);

Build/src/ui.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export function showError(message: string): void {
3434

3535
export function switchTab(tab: string): void {
3636
currentTab = tab;
37+
38+
// Hide all editor containers
3739
document.querySelectorAll(".editor-container").forEach((c) => {
3840
const container = c as HTMLElement;
3941
container.style.display = "none";
@@ -49,12 +51,20 @@ export function switchTab(tab: string): void {
4951
return;
5052
}
5153

54+
// Remove 'active' class from all tabs
55+
document
56+
.querySelectorAll(".editor-tabs .tab")
57+
.forEach((t) => t.classList.remove("active"));
58+
59+
// Show the selected container and mark tab as active
5260
editorContainer.style.display = "block";
5361
tabElement.classList.add("active");
62+
5463
editors[tab].view.focus();
5564
saveState();
5665
}
5766

67+
5868
export function switchOutput(output: string): void {
5969
currentOutput = output;
6070
const previewEl = document.getElementById("preview");

main.js

Lines changed: 35 additions & 4 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)