Skip to content

Commit 0bd6ded

Browse files
nextlevelshitMichael Czechowski
authored andcommitted
feat(lesson-ux): progress chip + Run-shortcut hint + auto-focus next (#111)
Co-authored-by: Michael Czechowski <mail@dailysh.it> Co-committed-by: Michael Czechowski <mail@dailysh.it>
1 parent 3932134 commit 0bd6ded

3 files changed

Lines changed: 56 additions & 1 deletion

File tree

src/app.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,14 @@ function loadCurrentLesson() {
767767
// Render difficulty badge
768768
renderDifficultyBadge(elements.lessonTitleRow, lesson);
769769

770+
// Update lesson-progress chip "<index+1> / <total>"
771+
const lessonProgressEl = document.getElementById("lesson-progress");
772+
if (lessonProgressEl && engineState.module?.lessons) {
773+
const total = engineState.module.lessons.length;
774+
const current = (engineState.lessonIndex || 0) + 1;
775+
lessonProgressEl.textContent = total > 1 ? `${current} / ${total}` : "";
776+
}
777+
770778
// Set user code in CodeMirror (clear history to prevent undo/redo across lessons)
771779
// Pass codePrefix/codeSuffix as read-only zones for CSS mode
772780
if (codeEditor) {
@@ -1041,6 +1049,15 @@ function runCode() {
10411049
}, isModuleComplete ? 8000 : 5000);
10421050
}
10431051

1052+
// Move keyboard focus to Next so Tab/Enter continues the flow.
1053+
// Skip if user disabled the auto-focus by hovering away — i.e.
1054+
// only when no other interactive element has focus.
1055+
if (elements.nextBtn && !elements.nextBtn.disabled) {
1056+
const active = document.activeElement;
1057+
const safe = !active || active === document.body || active.tagName === "TEXTAREA" || active === elements.runBtn;
1058+
if (safe) setTimeout(() => elements.nextBtn.focus({ preventScroll: true }), 100);
1059+
}
1060+
10441061
// Show success hint
10451062
showSuccessHint(validationResult.message || t("successMessage"));
10461063

src/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ <h4 data-i18n="footerSupport">Support</h4>
425425
<section class="instructions">
426426
<div class="lesson-title-row">
427427
<h2 id="lesson-title"></h2>
428+
<span id="lesson-progress" class="lesson-progress" aria-label="Lesson progress"></span>
428429
<button id="share-btn" class="share-btn" data-i18n-title="shareTitle" title="Share lesson" aria-label="Share lesson">
429430
<svg
430431
xmlns="http://www.w3.org/2000/svg"
@@ -464,7 +465,7 @@ <h2 id="lesson-title"></h2>
464465
465466
</button>
466467
</div>
467-
<button id="run-btn" class="btn btn-run"><img src="./gear.svg" alt="" /><span data-i18n="run">Run</span></button>
468+
<button id="run-btn" class="btn btn-run" title="Ctrl+Enter"><img src="./gear.svg" alt="" /><span data-i18n="run">Run</span><span class="run-shortcut" aria-hidden="true"><kbd>Ctrl</kbd>+<kbd></kbd></span></button>
468469
</div>
469470
</div>
470471
<div class="editor-content">

src/main.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4127,3 +4127,40 @@ body[data-section="javascript"] #lesson-title {
41274127
.cta-button:focus-visible {
41284128
outline-offset: 3px;
41294129
}
4130+
4131+
/* ================= LESSON UX ================= */
4132+
4133+
/* Module progress chip in lesson header — quiet, dependent on lesson */
4134+
.lesson-progress {
4135+
font-size: 0.78rem;
4136+
font-weight: 500;
4137+
color: var(--text-secondary, #6b7280);
4138+
background: var(--bg-secondary, #f3f4f6);
4139+
padding: 2px 8px;
4140+
border-radius: 999px;
4141+
letter-spacing: 0.02em;
4142+
white-space: nowrap;
4143+
}
4144+
.lesson-progress:empty { display: none; }
4145+
4146+
/* Run button keyboard shortcut hint */
4147+
.run-shortcut {
4148+
margin-left: 0.6rem;
4149+
display: inline-flex;
4150+
gap: 0.15rem;
4151+
opacity: 0.7;
4152+
font-size: 0.8em;
4153+
}
4154+
.run-shortcut kbd {
4155+
background: rgba(255, 255, 255, 0.18);
4156+
border: 1px solid rgba(255, 255, 255, 0.28);
4157+
border-bottom-width: 2px;
4158+
padding: 0 5px;
4159+
border-radius: 3px;
4160+
font-family: inherit;
4161+
font-size: 0.95em;
4162+
line-height: 1.4;
4163+
}
4164+
@media (max-width: 720px) {
4165+
.run-shortcut { display: none; }
4166+
}

0 commit comments

Comments
 (0)