Skip to content

Commit 297c8fa

Browse files
committed
Code and Serial Panels printable
1 parent bc7338f commit 297c8fa

3 files changed

Lines changed: 67 additions & 3 deletions

File tree

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
</ul>
9191
</nav>
9292
</div>
93-
<div id="editor"></div>
93+
<div id="editor" tabindex="0"></div>
9494
</div>
9595
<div id="page-separator" class=""></div>
9696
<div id="serial-page" class="">
@@ -113,7 +113,7 @@
113113
</select>
114114
<canvas id="plotter-canvas"></canvas>
115115
</div>
116-
<div id="terminal"></div>
116+
<div id="terminal" tabindex="1"></div>
117117
</div>
118118
</div>
119119
<div id="footer-bar">

js/layout.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,52 @@ function isSerialVisible() {
2626
return serialPage.classList.contains('active');
2727
}
2828

29+
function setupPanelFocusHandlers() {
30+
console.log("Setting up panel focus handlers");
31+
serialPage.removeEventListener('click', handleActivePanel);
32+
serialPage.addEventListener('click', handleActivePanel);
33+
editorPage.removeEventListener('click', handleActivePanel);
34+
editorPage.addEventListener('click', handleActivePanel);
35+
}
36+
37+
function handleActivePanel(event) {
38+
const panel = event.currentTarget;
39+
setActivePanel(panel);
40+
}
41+
42+
function setActivePanel(panel) {
43+
if (panel === serialPage && isSerialVisible()) {
44+
// Serial panel requested and visible
45+
serialPage.classList.add('focused-panel');
46+
editorPage.classList.remove('focused-panel');
47+
console.log("Serial panel focused");
48+
} else if (panel === editorPage && isEditorVisible()) {
49+
// Editor panel requested and visible
50+
editorPage.classList.add('focused-panel');
51+
serialPage.classList.remove('focused-panel');
52+
console.log("Editor panel focused");
53+
} else {
54+
// Requested panel is not visible, set other panel as focused
55+
if (isEditorVisible()) {
56+
editorPage.classList.add('focused-panel');
57+
serialPage.classList.remove('focused-panel');
58+
console.log("Editor panel focused (default)");
59+
} else {
60+
serialPage.classList.add('focused-panel');
61+
editorPage.classList.remove('focused-panel');
62+
console.log("Serial panel focused (default)");
63+
}
64+
}
65+
}
66+
2967
async function toggleEditor() {
3068
if (isSerialVisible()) {
3169
editorPage.classList.toggle('active');
3270
saveSetting(SETTING_EDITOR_VISIBLE, isEditorVisible());
3371
updatePageLayout(UPDATE_TYPE_EDITOR);
3472
}
73+
setupPanelFocusHandlers();
74+
setActivePanel(editorPage);
3575
}
3676

3777
async function toggleSerial() {
@@ -40,6 +80,8 @@ async function toggleSerial() {
4080
saveSetting(SETTING_TERMINAL_VISIBLE, isSerialVisible());
4181
updatePageLayout(UPDATE_TYPE_SERIAL);
4282
}
83+
setupPanelFocusHandlers();
84+
setActivePanel(serialPage);
4385
}
4486

4587
btnModeEditor.removeEventListener('click', toggleEditor);
@@ -229,4 +271,6 @@ pageSeparator.addEventListener('mousedown', async function (e) {
229271

230272
fixViewportHeight();
231273
window.addEventListener("resize", fixViewportHeight);
232-
loadPanelSettings();
274+
loadPanelSettings();
275+
setupPanelFocusHandlers();
276+
setActivePanel(editorPage);

sass/base/_base.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,23 @@ h5 {
8888
background-color: #d8d8d8;
8989
color: #888;
9090
}
91+
92+
@media print {
93+
body {
94+
visibility: hidden;
95+
}
96+
#editor-page.focused-panel #editor, #serial-page.focused-panel #terminal {
97+
visibility: visible;
98+
position: absolute;
99+
left: 0;
100+
top: 0;
101+
font-size: 2em;
102+
.xterm-rows {
103+
font-size: 1.2em;
104+
&> div {
105+
height: 1.2em !important;
106+
line-height: 1.2em !important;
107+
}
108+
}
109+
}
110+
}

0 commit comments

Comments
 (0)