Commit f5a2ce7f authored by Jakob Moser's avatar Jakob Moser
Browse files

Disable auto-focus in hand-in

parent 7a222a94
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -214,17 +214,17 @@ export async function runUnexecutedCommand() {
}

/**
 * Enables auto-focus to the terminal whenever a key is pressed.
 * Enables (or disables) auto-focus to the terminal whenever a key is pressed.
 * This allows the user to click on an exercise completion button and then seamlessly continue
 * typing into the terminal, without having to click it first.
 * 
 * Note: This also prevents any shortcuts from working, so use with care
 */
export function enableAutoFocus() {
    window.onkeydown = function () {
export function setAutoFocusEnabled(enabled) {
    window.onkeydown = enabled ? function () {
        const textareaElement = document.querySelector("textarea.term_textarea")
        if (document.activeElement !== textareaElement) {
            textareaElement.focus()
        }
    }
    } : null
}
+4 −2
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ import { State } from "./state.mjs"
import * as tests from "./exercises.mjs"
import { createExerciseCard, displayAsSolved, displayAsNonCurrent, displayAsCurrent, displayAsVerifying, displayAsNonVerifying, displayAsUnusuallyLongVerifying } from "./exercises.cards.mjs"
import { Exercise } from "./exercises.api.mjs"
import { enableAutoFocus, isVmLoading } from "./jslinux.api.mjs"
import { isVmLoading, setAutoFocusEnabled } from "./jslinux.api.mjs"
import { waitFor } from "./util.mjs"

const testId = new URLSearchParams(location.search).get("id")
@@ -95,6 +95,7 @@ function initActionLinks() {
    document.querySelectorAll("[data-action]").forEach(el => {
        const handler = {
            "hand-in": function () {
                setAutoFocusEnabled(false)
                const handInToken = currentTest.getHandInToken(currentState)
                navigator.clipboard.writeText(handInToken)
                document.querySelector("#hand-in-token").textContent = handInToken
@@ -109,6 +110,7 @@ function initActionLinks() {
            },
            "complete": function () {
                document.body.classList.remove("hand-in-shown")
                setAutoFocusEnabled(true)
            },
            "welcome-again": function () {
                document.querySelector("#welcome-dialog [data-action='begin']").style.display = "none"
@@ -171,7 +173,7 @@ export async function main() {
        document.querySelector("[data-action='hand-in']").style.display = "none"
    }

    enableAutoFocus()
    setAutoFocusEnabled(true)
    initExerciseList()
    setExerciseActionButtonsEnabled(false)
    initActionLinks()