All files / src/web help.js

100% Statements 26/26
100% Branches 4/4
100% Functions 6/6
100% Lines 24/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57                    2x             2x 2x       20x 2x   10x 10x 10x 10x 10x 10x 10x 10x 10x                   1x 1x 1x 1x 4x   1x 3x 3x 3x 3x      
import * as bootstrap from "bootstrap";
 
import { BasicKeys } from "./basic-panel.js";
import { MemoryKeys, ToolbarKeys } from "./debug.js";
import { DisassemblyKeys } from "./disassembly-view.js";
import { PauseKeys } from "./keyboard-setup.js";
import { helpRow, helpRows } from "./panel-keys.js";
import { Shortcuts } from "./shortcuts.js";
 
/** Help's blocks on its debugging tab, one for each window's keys; a window with keys of its own adds itself here. */
const KeyTables = [
    ["Paused", PauseKeys],
    ["Debugger", ToolbarKeys],
    ["Disassembly", DisassemblyKeys],
    ["Memory", MemoryKeys],
    ["BASIC", BasicKeys],
];
const StartTab = "#help-start";
const DebuggingTab = "#help-debugging";
 
/** Fills Help's tables of keys from the tables that bind them. */
export function fillHelp() {
    document.getElementById("shortcuts-help").append(...Shortcuts.map((row) => helpRow([row.combo], row.description)));
    document.getElementById("debug-keys-help").append(
        ...KeyTables.map(([title, table]) => {
            const block = document.createElement("section");
            block.className = "col-lg-6";
            const heading = document.createElement("h6");
            heading.textContent = title;
            const rows = document.createElement("table");
            rows.className = "table table-sm";
            rows.createTBody().append(...helpRows(table));
            block.append(heading, rows);
            return block;
        }),
    );
}
 
/**
 * Opens Help on its debugging tab while the machine is stopped, and otherwise on the tab last chosen.
 * @param {function(): boolean} isStopped
 */
export function openHelpOnTheTabForNow(isStopped) {
    let chosen = StartTab;
    let choosing = true;
    const help = document.getElementById("help");
    help.addEventListener("show.bs.tab", (event) => {
        if (choosing) chosen = event.target.dataset.bsTarget;
    });
    help.addEventListener("show.bs.modal", () => {
        choosing = false;
        const tab = isStopped() ? DebuggingTab : chosen;
        bootstrap.Tab.getOrCreateInstance(help.querySelector(`[data-bs-target="${tab}"]`)).show();
        choosing = true;
    });
}