A UX pass over the workspace, and two defects it turned up
Walking the site as a student (desktop, a phone-width screen, dark) found these. Each is small; together they are what got in the way. Defects: - Opening a problem in the Bridge saved the generated Mojo over the exercise's own program. The workspace fills every pane's editor as it opens, the editor reported that as typing, and the Bridge's read-only Mojo pane holds the generated text. Developer then showed generated Mojo labeled "your edits", and the problem counted as edited. The value setter now marks its change as a load, the change listener leaves loads out, and a Bridge session refuses a Mojo edit. - A page opened at #/#problems or #/#reference stopped about 45px past the heading: the fonts arrived after the place was computed. A page built this moment goes straight to its section and finds it again when the fonts are in; a page already on screen still scrolls there. The workspace: - With no run to step, the Run view said "Nothing to run yet." It and the stepper now give one reason (src/core/norun.ts): how many problems the stepped pane has and the first with its line, with a button to the line and the Problems list; or that the pane is empty. - In the Bridge the dock starts at about a quarter of the height (it holds a call, a line of output, a short list), so the code and the run get the room. Developer keeps a third for the compiler's answer. A double-click on a divider returns to the area's default, not to the student's last position. - The reason a pane is not in step wraps instead of ending in an ellipsis, and a button in the pane's head keeps its words on one line. - A problem that does not exist keeps the site's navigation and links the problem list. - Help, the theme switch and the stepper's first, back, step and last buttons have names a screen reader can say. A phone-width screen: - The toolbar is three rows in every area and on every tab (it was four or five): the mark, the area, help and the theme; the problem, Versions and Reset; the actions. About 30px more of the code shows. An embedded workspace keeps its own toolbar. - The Share dialog puts each row's name above what it holds (a note had been squeezed to a word per line), and the Versions menu opens across the screen instead of running off its right edge. - The stepper's speed label stays with its slider. Checked by hand, in headless Chromium at 1440x900, 1366x768, 390x844 and 320x640, light and dark: each state above before and after; the editor has line numbers and highlighting; the stepper steps; embeds (playground, trace, Developer) are unchanged; 31 smoke scenarios clean but the ones that err on purpose.
This commit is contained in:
14 files changed
+302
-39
No files matched your search
@@ -14,6 +14,11 @@ No version has been tagged yet. What programs mean is pplus-core's, and its chan
|
||||
- The copy says what the site holds and no more: what runs in the browser and what does not, that the Hardware area is a model machine, and what "verified" means.
|
||||
- A shared link never saves over the reader's own work on the same problem.
|
||||
- Below 700px a workspace shows one part at a time; every page has a main landmark and a heading, and the contrast findings are fixed.
|
||||
- With no run to step, the Run view and the stepper say why: how many problems the pane has and the first one with its line (and a button to the Problems list), or that the pane is empty. It said "Nothing to run yet."
|
||||
- In the Bridge the dock starts at about a quarter of the height, not a third, so the code and the run get the room; Developer keeps a third for the compiler's answer. A double-click on a divider returns it to the area's default.
|
||||
- A phone-width toolbar is three rows in every area (it was four or five): about 30px more of the code on screen. The stepper's speed label stays with its slider.
|
||||
- A problem that does not exist keeps the site's navigation and links the problem list.
|
||||
- The icon-only buttons (help, the theme, the stepper's first, back, step and last) have names a screen reader can say.
|
||||
- The Quarto extension's syntax definitions state their license as Apache-2.0 (they said MIT), and `THIRD_PARTY.md` says that the stylesheets and syntax definitions that came from the course are under this repository's copyright and license.
|
||||
|
||||
- The deploy job is light: it runs the site's tests and core's `mojo-status-strict` at the pinned commit, then publishes. It no longer runs core's own tests (15 to 22 minutes on the deploy server, where they also failed for want of a C compiler and for the server's speed, so the site was not published). Core's tests and everything that builds Mojo are core's gate, on a runner of its own; run `pixi run core-test` before moving the pointer. `docs/deploy.md` and the workflow describe the runner as it is, a new container for every job, not a host shell.
|
||||
@@ -39,6 +44,10 @@ No version has been tagged yet. What programs mean is pplus-core's, and its chan
|
||||
- With `pplus-strict: true`, a program with `EXPECT` lines that does not run at all stops the render; it was only a warning.
|
||||
- `quarto/README.md` is corrected against the extension: `follow` belongs to the stepper only, the defaults and limits of `height` and `max`, what a non-HTML format gets, what `check-pages` runs, and what `quarto-export` writes.
|
||||
- From core: brackets that each hold a long chain are one `too-deep` error in the pseudo pane; they ended in the engine's own stack error.
|
||||
- Opening a problem in the Bridge saved the generated Mojo over the exercise's own program, so the Developer area then showed the generated text labeled "your edits" and the problem counted as edited. Text the app loads into an editor is no longer reported as typing, and a Bridge session refuses a Mojo edit.
|
||||
- A page opened at `#/#problems` or `#/#reference` stopped about 45px past the section's heading (the fonts arrived after the place was computed); it now goes straight to the section and finds it again when the fonts are in.
|
||||
- On a phone-width screen the Share dialog squeezed a note into a column one word wide, and the Versions menu ran off the right edge.
|
||||
- The reason a pane is not in step was cut off with an ellipsis; it wraps.
|
||||
|
||||
## [0.1.0] - 2026-10-06
|
||||
|
||||
|
||||
+6
-5
@@ -24,8 +24,8 @@ Four languages are kept in step (see [Translation between languages](#translatio
|
||||
|
||||
- **Link state on every tab.** ✎ the pane you are editing (the others follow it), ⇄ in step, ⚠ not in step (the reason is in the tooltip and in the banner above the editor), nothing for a pane still **as authored** (nothing has been translated yet; the first edit makes that pane the authority).
|
||||
- **Typing never fights the cursor.** The pane being edited is never rewritten. The other panes are brought up to date when their tab is shown, replacing only the part of the text that changed, so the cursor and scroll position of a pane stay put. Each such update is its own undo step (the editor's `setSynced`, a `sync` user event that history does not join to typing), so Ctrl+Z in a pane steps back to what it showed before the sync, and, as with any change to a pane, that pane then becomes the authority. Loading a problem is not an undoable edit.
|
||||
- **A pane that is not in step** (matho for a `WHILE`; anything while the pane you edited does not read) keeps its last text, is read-only, and says why, with an **Edit anyway** button that makes it the authority. The stepper does not step a stale lingo or matho pane; it steps the pseudo.
|
||||
- **Mojo (from pseudo)** is read-only, labeled *Generated from pseudo*, and computed from the pseudo on the fly (`Session.derivedMojo()`; the state's own `sources.mojo` is untouched). It steps in the Mojo interpreter, is checked, and **Compile & run** sends it to the real compiler. **Edit in Developer** copies it into the Developer area's Mojo pane (asking first if that pane holds something else) and records `mojoOrigin: 'generated'`; the first edit there makes it `'generated-edited'`, and the Mojo pane says so.
|
||||
- **A pane that is not in step** (matho for a `WHILE`; anything while the pane you edited does not read) keeps its last text, is read-only, and says why in full (the reason wraps; it is never cut short), with an **Edit anyway** button that makes it the authority. The stepper does not step a stale lingo or matho pane; it steps the pseudo.
|
||||
- **Mojo (from pseudo)** is read-only, labeled *Generated from pseudo*, and computed from the pseudo on the fly (`Session.derivedMojo()`; the state's own `sources.mojo` is untouched: text loaded into an editor is not reported as typing, and a Bridge session refuses a Mojo edit). It steps in the Mojo interpreter, is checked, and **Compile & run** sends it to the real compiler. **Edit in Developer** copies it into the Developer area's Mojo pane (asking first if that pane holds something else) and records `mojoOrigin: 'generated'`; the first edit there makes it `'generated-edited'`, and the Mojo pane says so.
|
||||
- **Prove and Tests** work on the hub's pseudo with the speco woven in, whichever pane you edited.
|
||||
|
||||
Every area is an IDE-style workspace: the language panes as tabs over one editor; under it the stepper and what runs next; beside it an inspect panel (the Run view, flowchart, data flow, proof, tests) whose tabs appear only when they apply to the pane; under everything a dock for the output, the problems, the real compiler's answer, and the machine model's numbers. A catalog of worked problems comes with it.
|
||||
@@ -105,7 +105,7 @@ A student can save the state of their work under a name and come back to any sav
|
||||
|
||||
**Work that takes the page down.** The engines stop a program that runs too long or makes values too large (core's [limits.md](../core/docs/limits.md)), but should a program still use up the tab's memory first, the browser kills the page. Saved work runs again as the page opens, so before it runs its save is marked busy in this tab (`src/core/guard.ts`, in `sessionStorage`), and the mark is cleared once the page has been idle for a moment and when it closes normally. A reload that finds the mark puts that save aside as a named version, "When the page stopped (time)", opens the problem as written, and says so; an embed drops the reader's edits instead. If a saved state makes the page fail in any other way, the page that says so offers the same: keep the work as a version and open the problem as written.
|
||||
|
||||
Nothing else is a route: `#/p/<problem>`, `#/s/<state>` and the other earlier forms open the home page, with a note at the foot of the page that there is no page at that address (`isUnknownRoute` in `src/core/state.ts`). A problem or library routine that does not exist, in the app or in an embed, is a page that says so; so is a link that does not open (below). `<view>` is `playground` (the whole workspace; `?area=dev` picks the area, Bridge by default or the problem's own), `trace`, `table`, `flow`, `data`, `life`, `proof`, `tests`, `problems`, `compiler`, `asm` (the machine numbers), or a pane name (`lingo`, `pseudo`, `speco`, `mojo`, `asm`) to show just that editor with its problems under it. Query parameters on an embed: `?t=12` parks the stepper, `?ro=1` makes the editor read-only; `area`, `panel`, `lang`, `build`, `machine`, `dock`, `docktab`, `editor`, `side`, `dockheight` and `theme` arrange the example as the playground's controls do (`applyEmbedParams` in `src/core/state.ts`).
|
||||
Nothing else is a route: `#/p/<problem>`, `#/s/<state>` and the other earlier forms open the home page, with a note at the foot of the page that there is no page at that address (`isUnknownRoute` in `src/core/state.ts`). A problem or library routine that does not exist, in the app or in an embed, is a page that says so (in the app it keeps the site's navigation and links the problem list); so is a link that does not open (below). `<view>` is `playground` (the whole workspace; `?area=dev` picks the area, Bridge by default or the problem's own), `trace`, `table`, `flow`, `data`, `life`, `proof`, `tests`, `problems`, `compiler`, `asm` (the machine numbers), or a pane name (`lingo`, `pseudo`, `speco`, `mojo`, `asm`) to show just that editor with its problems under it. Query parameters on an embed: `?t=12` parks the stepper, `?ro=1` makes the editor read-only; `area`, `panel`, `lang`, `build`, `machine`, `dock`, `docktab`, `editor`, `side`, `dockheight` and `theme` arrange the example as the playground's controls do (`applyEmbedParams` in `src/core/state.ts`).
|
||||
|
||||
A reader's edits in an embed are saved in their browser, in that embed's own save (one per embedded example, shared by pages that embed the same one), never in the app's save for the problem. Once they have changed something, **Reset** appears beside "open in Programming+" and puts the author's version back. An embed keeps a save only while it holds edits, so a reader who has not changed an example always sees the author's current version. A read-only embed (`?ro=1`) saves nothing.
|
||||
|
||||
@@ -121,7 +121,7 @@ The **Share** button in the app produces the app link, a ready-to-paste `<iframe
|
||||
|
||||
- **Step through**, with the tools a tutor would use at a whiteboard: the next line is called out before it runs with what it reads and writes; strings and lists draw as rulers with the position being read highlighted; every variable shows its previous value and a link to the step that changed it; click a line number for a breakpoint and run to it; jump by loop pass; **predict mode** asks what the next step will write before you take it and keeps score; play at any speed; export the trace as CSV (a cell that a spreadsheet would read as a formula, one starting with `=`, `+`, `-` or `@` that is not a number, is written with a leading apostrophe: `src/core/csv.ts`). Keyboard: → ← Shift+→ Home End Space B P, and ? in the toolbar lists them.
|
||||
- **Light and dark**: the ☾/☀ button; follows the system until you choose. Embeds take `?theme=dark`.
|
||||
- **A phone-width screen** (under 700px): the workspace fills the screen and shows one part at a time, chosen in a bar at the foot of the toolbar: **Code** (the panes with the stepper under them), **Run and views** (the side column, with the stepper's first row and what runs next above it) and **Setup and output** (the dock); in Hardware, **Code** and **Board**. Each part scrolls inside itself. **Run** shows the Run view, Compile & run and a click on a problem's tab show the dock (or the board), and a click on a line in a view shows the code. A wider screen never sees the bar, and every part stays where it is (`tests/narrow.test.mjs` holds the rules to the media query).
|
||||
- **A phone-width screen** (under 700px): the workspace fills the screen and shows one part at a time, chosen in a bar at the foot of the toolbar: **Code** (the panes with the stepper under them), **Run and views** (the side column, with the stepper's first row and what runs next above it) and **Setup and output** (the dock); in Hardware, **Code** and **Board**. Each part scrolls inside itself. **Run** shows the Run view, Compile & run and a click on a problem's tab show the dock (or the board), and a click on a line in a view shows the code. A wider screen never sees the bar, and every part stays where it is (`tests/narrow.test.mjs` holds the rules to the media query). The toolbar there is three rows above the bar, the same in every area and on every tab: the mark (the name is left out; it still opens the home page), the area, help and the theme; the problem, Versions and Reset; then the actions. The Versions menu opens across the screen, the Share dialog puts each row's name above what it holds, and under 380px the Best practices switch reads "Practices".
|
||||
- **Table of values**: the table a student draws by hand, drawn by the machine: a column per step that changed something, a row per name, the new value in the cell, blank for unchanged; click a step to jump the stepper there; copy as text (tab-separated, with the same guard against formulas as the CSV).
|
||||
- **Flowchart**: laid out from the structure of the pseudo (so loops loop and branches branch), each box shaded by how often its line ran in the last run, each loop labeled with its passes, each arrow out of a decision with how often it was taken; a box that never ran is dashed. Click a box to reveal its line; download as SVG.
|
||||
- **Data flow**: inputs on the left, `RETURN` and `OUTPUT` on the right, one arrow per assignment that reads the one and writes the other, labeled with its line, dashed when a condition only decides whether it happens.
|
||||
@@ -136,7 +136,8 @@ The **Share** button in the app produces the app link, a ready-to-paste `<iframe
|
||||
- **Views that follow the run**: the **Flowchart** shades by the run so far and marks the box that runs next; the **Data flow** lights up the names the next line reads and the name the last line wrote.
|
||||
- **Step colors**: every step in the Run view and the "next" box is colored by what it does (writes a value, decides, loop control, enters a routine, returns, input or output, a value destroyed, raises or fails); the legend is in the inspect panel's tab row.
|
||||
- **The stepper** is docked under the editor, at the editor column's width, as part of it: first, back, step, last, play and the slider; the loop-pass jumps, run to breakpoint, predict mode, only writes, speed and CSV; the loops in flight (or the machine's counts); and what runs next. It stays visible when the dock is folded.
|
||||
- **The dock** under everything holds **Setup** (the call and the input lines for pseudo, lingo and matho; the build level and stdin for Mojo; the machine and the setup block for x86-64, in fixed-size boxes), Output, Problems (with the count on its tab), Compiler (Mojo) and Machine (the Hardware area's board); ▾ folds it away.
|
||||
- **No run to step.** When the pane has nothing to step, the stepper and the Run view give the same reason (`whyNoRun` in `src/core/norun.ts`): how many problems the stepped pane has and the first one with its line, what an engine said when it stopped, or that the pane is empty. The Run view adds a button that shows the first problem's line and the Problems list.
|
||||
- **The dock** under everything holds **Setup** (the call and the input lines for pseudo, lingo and matho; the build level and stdin for Mojo; the machine and the setup block for x86-64, in fixed-size boxes), Output, Problems (with the count on its tab), Compiler (Mojo) and Machine (the Hardware area's board); ▾ folds it away. Until the divider is moved the dock takes about a quarter of the height in the Bridge (a call, a line of output, a short list of problems) and about a third in Developer (the compiler's answer and its listing); a double-click on a divider puts it back there (`DEFAULT_DOCK` in `src/ui/shell.ts`).
|
||||
- **Hover** any word or symbol in any editor for its reference entry: keywords, built-ins, operators, English phrasings, speco symbols, instructions, registers, condition codes.
|
||||
- **Language reference** at the bottom of the home page, rendered from core's `src/common/reference.ts`. Where an engine already holds a fact (keywords, built-ins, precedence, sentence forms, instruction glosses, condition codes, machine presets) the reference reads it from the engine; the tables written by hand carry examples, and core's `tests/reference.test.mjs` parses every statement, speco and setup example through the real parsers and runs every idiom against the output its note names, so an example cannot drift from the tool. The meanings beside the examples are written by hand, and no test reads them.
|
||||
- **Save and load**: Share → Download writes `<title>.pplus.json`; Open… loads one back (here or on another machine). A `.pplus.json` file, a share link, or a `state=` shortcode from an earlier state format opens an empty workspace, and a save in the browser from an earlier format is discarded, so the problem opens as written; Programming+ makes no promise to keep old saves and links working. The share link and the embed code carry the same state.
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/**
|
||||
* Why there is no run to step, in words a student can act on. The stepper and the Run view both show this when
|
||||
* `session.trace()` is null, so the two never give different reasons: a pane with problems says how many and
|
||||
* names the first, an engine that stopped says what it said, and an empty pane says that it is empty.
|
||||
*/
|
||||
import type { LangId } from '#core/common/types.js';
|
||||
import { LANG_NAMES } from '#core/common/types.js';
|
||||
import type { Session } from './session.js';
|
||||
|
||||
export interface NoRun {
|
||||
/** One sentence: what is in the way. */
|
||||
headline: string;
|
||||
/** The first problem, with its line, when problems are what is in the way. */
|
||||
detail: string | null;
|
||||
/** How many errors the stepped pane has. */
|
||||
errors: number;
|
||||
/** The pane the run would step (the pseudo behind a lingo or matho pane that is not in step). */
|
||||
lang: LangId;
|
||||
/** The first error's line, to show it in the editor. */
|
||||
line: number | null;
|
||||
}
|
||||
|
||||
/** Call it after `session.trace()` returned null (the run error it reads is the one that call left). */
|
||||
export function whyNoRun(s: Session): NoRun {
|
||||
const lang = s.traceLang();
|
||||
const name = LANG_NAMES[lang];
|
||||
const errors = s.diagnostics(lang).filter((d) => d.severity === 'error');
|
||||
if (errors.length) {
|
||||
const first = errors[0]!;
|
||||
return {
|
||||
headline: `No run yet: the ${name} pane has ${errors.length === 1 ? 'a problem' : `${errors.length} problems`} to fix first.`,
|
||||
detail: `Line ${first.line}: ${first.message}`, errors: errors.length, lang, line: first.line ?? null,
|
||||
};
|
||||
}
|
||||
if (s.runError) return { headline: s.runError, detail: null, errors: 0, lang, line: null };
|
||||
if (!s.source(lang).trim()) return { headline: `Nothing to run yet: the ${name} pane is empty.`, detail: null, errors: 0, lang, line: null };
|
||||
return { headline: 'Nothing to run yet.', detail: null, errors: 0, lang, line: null };
|
||||
}
|
||||
@@ -155,6 +155,8 @@ export class Session extends Workspace {
|
||||
* text is what the pane already shows (a stale pane the student chose to edit becomes the authority).
|
||||
*/
|
||||
setSource(lang: LangId, text: string, force = false): void {
|
||||
// the Bridge's Mojo is computed from the pseudo and never stored: nothing typed or loaded there is the student's Mojo
|
||||
if (lang === 'mojo' && this.derivesMojo()) return;
|
||||
// Mojo the student started from a generated program is theirs once they change it, and says so
|
||||
const wasGenerated = lang === 'mojo' && this.state.mojoOrigin === 'generated' && this.state.sources.mojo !== text;
|
||||
if (!this.edit(lang, text, force)) return;
|
||||
|
||||
+26
-5
@@ -12,6 +12,7 @@ import { parseRoute, decodeState, loadLocal, migrateLocal, type PlayState, embed
|
||||
import { takeCrashed, settle, setAside, markBusy } from './core/guard.js';
|
||||
import { notice, messagePage } from './ui/notice.js';
|
||||
import { homeView } from './ui/home.js';
|
||||
import { siteNav } from './ui/nav.js';
|
||||
import { quartoView } from './ui/quarto.js';
|
||||
import { libraryView } from './ui/library.js';
|
||||
import { libraryState } from './core/library.js';
|
||||
@@ -76,9 +77,23 @@ async function stateForRoute(): Promise<Resolved> {
|
||||
return null;
|
||||
}
|
||||
|
||||
function scrollToAnchor(): void {
|
||||
/**
|
||||
* Bring the section the address names to the top. On a page already on screen the move is shown (`built` false).
|
||||
* A page built this moment is still waiting for its fonts, and when they arrive the text above the section changes
|
||||
* height: a move started before that ends short of the heading or past it. So there the page goes straight to the
|
||||
* section, and once more when the fonts are in, unless the reader has gone elsewhere by then.
|
||||
*/
|
||||
function scrollToAnchor(built = false): void {
|
||||
const m = /#(problems|reference|quarto-teaser)$/.exec(location.hash) ?? /^#\/quarto#([\w-]+)$/.exec(location.hash);
|
||||
if (m) requestAnimationFrame(() => document.getElementById(m[1])?.scrollIntoView({ behavior: 'smooth', block: 'start' }));
|
||||
if (!m) return;
|
||||
const go = (behavior: ScrollBehavior) => document.getElementById(m[1]!)?.scrollIntoView({ behavior, block: 'start' });
|
||||
if (!built) { requestAnimationFrame(() => go(matchMedia('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth')); return; }
|
||||
const hash = location.hash;
|
||||
requestAnimationFrame(() => {
|
||||
go('auto');
|
||||
const at = window.scrollY;
|
||||
void document.fonts?.ready.then(() => { if (location.hash === hash && Math.abs(window.scrollY - at) < 200) go('auto'); });
|
||||
});
|
||||
}
|
||||
|
||||
/** In a host page (the Quarto extension's pplus.js), follow its light/dark switch: the host posts
|
||||
@@ -125,11 +140,17 @@ async function show(): Promise<void> {
|
||||
add(app, messagePage('That link did not open', String(e?.message || e)));
|
||||
return;
|
||||
}
|
||||
if (resolved && 'missing' in resolved) { add(app, messagePage(resolved.missing.title, resolved.missing.text)); document.title = `${resolved.missing.title} · Programming+`; return; }
|
||||
if (resolved && 'missing' in resolved) {
|
||||
// in the app the page keeps the site's navigation and offers the problem list; an embed is somebody's page, so it says what is missing and no more
|
||||
const inApp = route.kind !== 'embed';
|
||||
const page = messagePage(resolved.missing.title, resolved.missing.text, ...(inApp ? [el('a', { class: 'btn btn-primary', href: '#/#problems' }, 'Browse the problems')] : []));
|
||||
if (inApp) page.insertBefore(siteNav('home'), page.firstChild);
|
||||
add(app, page); document.title = `${resolved.missing.title} · Programming+`; return;
|
||||
}
|
||||
if (!resolved && route.kind === 'library') { add(app, libraryView(route.id)); document.title = `${route.id ? `${route.id} · ` : ''}Library · Programming+`; window.scrollTo(0, 0); return; }
|
||||
if (!resolved && route.kind === 'quarto') { add(app, quartoView()); document.title = 'With Quarto · Programming+'; if (route.anchor) scrollToAnchor(); else window.scrollTo(0, 0); return; }
|
||||
if (!resolved && route.kind === 'quarto') { add(app, quartoView()); document.title = 'With Quarto · Programming+'; if (route.anchor) scrollToAnchor(true); else window.scrollTo(0, 0); return; }
|
||||
if (!resolved) {
|
||||
add(app, homeView()); document.title = HOME_TITLE; scrollToAnchor();
|
||||
add(app, homeView()); document.title = HOME_TITLE; scrollToAnchor(true);
|
||||
if (isUnknownRoute(location.hash)) notice('There is no page at that address, so this is the home page. Links from before the three areas open here too.');
|
||||
return;
|
||||
}
|
||||
|
||||
+7
-4
@@ -310,8 +310,9 @@ export class Editor {
|
||||
opts.placeholder ? placeholder(opts.placeholder) : [],
|
||||
this.readOnlyPart.of(opts.readOnly ? [EditorState.readOnly.of(true), EditorView.editable.of(false)] : []),
|
||||
EditorView.updateListener.of((u) => {
|
||||
// a change the app made to follow another pane (setSynced) is not the student typing: nothing is told
|
||||
if (u.transactions.some((tr) => tr.docChanged && !tr.isUserEvent('sync'))) this.opts.onChange?.(u.state.doc.toString());
|
||||
// a change the app made, to follow another pane (setSynced) or to load a text (the value setter), is not
|
||||
// the student typing: nothing is told
|
||||
if (u.transactions.some((tr) => tr.docChanged && !tr.isUserEvent('sync') && !tr.isUserEvent('load'))) this.opts.onChange?.(u.state.doc.toString());
|
||||
if (u.selectionSet || u.docChanged) this.opts.onCursorLine?.(u.state.doc.lineAt(u.state.selection.main.head).number);
|
||||
if (u.docChanged || u.selectionSet) tooltip.hide();
|
||||
}),
|
||||
@@ -361,8 +362,10 @@ export class Editor {
|
||||
set value(v: string) {
|
||||
const cur = this.view.state.doc.toString();
|
||||
if (cur === v) return;
|
||||
// loading text (opening a problem, Reset, a file) is not an edit: Ctrl+Z must not be able to undo the pane to empty
|
||||
this.view.dispatch({ changes: { from: 0, to: cur.length, insert: v }, annotations: Transaction.addToHistory.of(false) });
|
||||
// loading text (opening a problem, Reset, a file) is not an edit: Ctrl+Z must not be able to undo the pane to empty,
|
||||
// and nothing is told (the `load` user event), or the Bridge's generated Mojo, loaded into its read-only pane,
|
||||
// would be saved as the student's own Mojo
|
||||
this.view.dispatch({ changes: { from: 0, to: cur.length, insert: v }, annotations: Transaction.addToHistory.of(false), userEvent: 'load' });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+25
-9
@@ -124,6 +124,13 @@ const LINK_TEXT: Record<'authored' | 'sync' | 'authority', string> = {
|
||||
};
|
||||
|
||||
/** The line comment each pane toggles with Ctrl+/ (Cmd+/). */
|
||||
/**
|
||||
* How much of the workspace's height the code and the inspect panel get before the student moves the divider; the
|
||||
* dock under them gets the rest. In the Bridge the dock holds a call, a line or two of output, or a short list of
|
||||
* problems, so it starts at about a quarter. In Developer it holds the real compiler's answer and its listing, so
|
||||
* it starts at about a third (styles.css has the Bridge's number for the first paint).
|
||||
*/
|
||||
const DEFAULT_DOCK: Partial<Record<AreaId, number>> = { bridge: 0.76, dev: 0.68 };
|
||||
const LINE_COMMENTS: Partial<Record<LangId, string>> = { pseudo: '//', mojo: MOJO_LINE_COMMENT, asm: ';' };
|
||||
|
||||
/** A row's tabs as one tablist with nothing else in it; `display: contents`, so the row lays out as before. */
|
||||
@@ -236,7 +243,7 @@ export class Shell {
|
||||
|
||||
this.main = el('div', { class: 'main' + (this.boardMode ? ' main-board' : '') });
|
||||
const split = splitter({
|
||||
container: this.main, axis: 'x', initial: lay.split ?? (this.boardMode ? 0.46 : 0.54), min: 0.25, max: 0.8,
|
||||
container: this.main, axis: 'x', initial: this.boardMode ? 0.46 : 0.54, start: lay.split, min: 0.25, max: 0.8,
|
||||
apply: (f) => this.main.style.setProperty('--split', `${(f * 100).toFixed(2)}%`),
|
||||
onChange: (f) => session.setLayout({ split: f }),
|
||||
});
|
||||
@@ -248,14 +255,14 @@ export class Shell {
|
||||
if (this.boardMode) add(this.workspace, this.main);
|
||||
else {
|
||||
const dockBar = splitter({
|
||||
container: this.workspace, axis: 'y', initial: lay.dock ?? 0.68, min: 0.3, max: 0.9,
|
||||
container: this.workspace, axis: 'y', initial: DEFAULT_DOCK[area.id] ?? 0.72, start: lay.dock, min: 0.3, max: 0.9,
|
||||
apply: (f) => this.workspace.style.setProperty('--dock', `${(f * 100).toFixed(2)}%`),
|
||||
onChange: (f) => session.setLayout({ dock: f }),
|
||||
});
|
||||
add(this.workspace, this.main, dockBar, this.dock);
|
||||
}
|
||||
this.workspace.dataset.narrow = this.narrow;
|
||||
this.root = el('div', { class: 'shell' }, this.toolbar, this.banner, this.workspace);
|
||||
this.root = el('div', { class: 'shell' + (this.embed ? ' shell-embed' : '') }, this.toolbar, this.banner, this.workspace);
|
||||
this.renderBanner();
|
||||
|
||||
for (const lang of LANG_ORDER) this.editors.set(lang, this.makeEditor(lang));
|
||||
@@ -714,7 +721,11 @@ export class Shell {
|
||||
const hooks = this.hooks();
|
||||
const gotoStep = (t: number) => { this.session.setT(t); this.stepper?.goto(t); this.showInspect('trace'); };
|
||||
switch (view) {
|
||||
case 'trace': this.inspectOff = runView(this.session, host, { goto: (t) => { this.session.setT(t); this.stepper?.goto(t); }, follow: () => this.session.layout().follow ?? null, setFollow: (follow) => this.session.setLayout({ follow }) }); break;
|
||||
case 'trace': this.inspectOff = runView(this.session, host, {
|
||||
goto: (t) => { this.session.setT(t); this.stepper?.goto(t); }, follow: () => this.session.layout().follow ?? null, setFollow: (follow) => this.session.setLayout({ follow }),
|
||||
// the line first, then the list: on a phone-width screen the last one asked for is the part that shows
|
||||
problems: (lang, line) => { if (line) hooks.reveal(lang, line); this.showDock('problems', true); },
|
||||
}); break;
|
||||
case 'proof': this.inspectOff = proofView(this.session, host, hooks); break;
|
||||
case 'tests': this.inspectOff = testsView(this.session, host, { ...hooks, stepThrough: (call) => { this.session.setCall(call); this.renderSetup(); this.stepper?.goto(0); this.showInspect('trace'); } }); break;
|
||||
case 'life': this.inspectOff = lifetimesView(this.session, host, { goto: gotoStep }); break;
|
||||
@@ -800,7 +811,7 @@ export class Shell {
|
||||
const open = el('a', { class: 'brand', href: '#', target: '_blank', rel: 'noopener', title: 'Open this example, as it is now, in Programming+' }, el('span', { class: 'brand-mark' }, 'P+'), 'Programming+ ↗');
|
||||
void encodeState(s).then((blob) => { open.href = `${location.href.split('#')[0]}${routeFor({ kind: 'shared', area: this.area.id, blob })}`; });
|
||||
add(this.toolbar, open, el('span', { class: 'embed-name' }, s.title || PROBLEMS.find((p) => p.id === s.problem)?.title || 'Example'), this.areaSwitch() ?? this.areaName());
|
||||
} else add(this.toolbar, el('a', { class: 'brand', href: '#/' }, el('span', { class: 'brand-mark' }, 'P+'), 'Programming+'), this.areaSwitch() ?? this.areaName(), select, this.versionsControl());
|
||||
} else add(this.toolbar, el('a', { class: 'brand', href: '#/', title: 'Programming+: the home page' }, el('span', { class: 'brand-mark' }, 'P+'), el('span', { class: 'brand-name' }, 'Programming+')), this.areaSwitch() ?? this.areaName(), select, this.versionsControl());
|
||||
const lang = s.lang;
|
||||
const primary = lang === 'mojo'
|
||||
? button(this.session.compiling ? 'Compiling…' : '▶ Compile & run', () => void this.compileNow(), { class: 'btn btn-primary', disabled: !!this.session.compiling, title: `Build and run the Mojo pane with the real Mojo ${MOJO_VERSION} compiler: sends the program and its input to godbolt.org (Ctrl+Enter)` })
|
||||
@@ -811,11 +822,16 @@ export class Shell {
|
||||
button('Share', () => this.share(), { class: 'btn', title: 'Link, embed code, or a file' }),
|
||||
this.embed ? null : button('Open…', () => this.openFile(), { class: 'btn', title: 'Load a saved .pplus.json file' }),
|
||||
this.embed ? (this.embed.reset && this.embed.edited?.() ? button('Reset', () => { if (confirm('Discard your changes to this example and show the original again?')) this.embed!.reset!(); }, { class: 'btn btn-quiet', title: 'Your changes here are saved in this browser. Reset shows the original example again.' }) : null) :
|
||||
s.problem ? button('Reset', () => this.resetProblem(), { class: 'btn btn-quiet', title: 'Show the problem as written. Your work is saved as a version first, so Reset can be undone from the Versions menu.' }) : null,
|
||||
s.problem ? button('Reset', () => this.resetProblem(), { class: 'btn btn-quiet tool-reset', title: 'Show the problem as written. Your work is saved as a version first, so Reset can be undone from the Versions menu.' }) : null,
|
||||
!this.embed && (PRACTICE_AREAS as readonly string[]).includes(this.area.id)
|
||||
? button(practicesOn(this.area.id) ? 'Best practices: on' : 'Best practices: off', () => setPracticesOn(this.area.id, !practicesOn(this.area.id)), { class: `btn btn-quiet${practicesOn(this.area.id) ? ' btn-on' : ''}`, 'aria-pressed': practicesOn(this.area.id), title: 'Notes on how a Mojo programmer would write the Mojo here. Off until you turn it on; each area remembers its own choice in this browser.' }) : null,
|
||||
button('?', () => this.helpDialog(), { class: 'btn btn-quiet icon-btn', title: 'Keyboard shortcuts and how the panes fit together' }),
|
||||
button(effectiveTheme() === 'dark' ? '☀' : '☾', (e) => { cycleTheme(); (e.target as HTMLButtonElement).textContent = effectiveTheme() === 'dark' ? '☀' : '☾'; }, { class: 'btn btn-quiet icon-btn', title: 'Switch between light and dark' }),
|
||||
? (() => {
|
||||
// a toggle: its name is what it switches (aria-pressed says which way), and a small phone gets the short form
|
||||
const b = button('', () => setPracticesOn(this.area.id, !practicesOn(this.area.id)), { class: `btn btn-quiet tool-practices${practicesOn(this.area.id) ? ' btn-on' : ''}`, 'aria-label': 'Best practices', 'aria-pressed': practicesOn(this.area.id), title: 'Notes on how a Mojo programmer would write the Mojo here. Off until you turn it on; each area remembers its own choice in this browser.' });
|
||||
add(b, el('span', { class: 'tool-wide' }, 'Best practices'), el('span', { class: 'tool-tight' }, 'Practices'), practicesOn(this.area.id) ? ': on' : ': off');
|
||||
return b;
|
||||
})() : null,
|
||||
button('?', () => this.helpDialog(), { class: 'btn btn-quiet icon-btn tool-help', 'aria-label': 'Help: keyboard shortcuts and how the panes fit together', title: 'Keyboard shortcuts and how the panes fit together' }),
|
||||
button(effectiveTheme() === 'dark' ? '☀' : '☾', (e) => { cycleTheme(); (e.target as HTMLButtonElement).textContent = effectiveTheme() === 'dark' ? '☀' : '☾'; }, { class: 'btn btn-quiet icon-btn', 'aria-label': 'Switch between light and dark', title: 'Switch between light and dark' }),
|
||||
this.narrowBar,
|
||||
);
|
||||
this.renderNarrowBar();
|
||||
|
||||
+14
-1
@@ -13,12 +13,16 @@ import { el, add, clear } from '../dom.js';
|
||||
import type { Session } from '../../core/session.js';
|
||||
import { runColumns, runRows, defaultFollow, valuesAt, type RunColumn, type RunRow, type LifeKind } from '#core/common/runview.js';
|
||||
import { familyOf, FAMILY_LABEL } from '../stepkinds.js';
|
||||
import { whyNoRun } from '../../core/norun.js';
|
||||
import type { LangId } from '#core/common/types.js';
|
||||
|
||||
export interface RunHooks {
|
||||
goto(t: number): void;
|
||||
/** The followed variables kept for this area (null: not chosen yet), and where a new choice is kept. */
|
||||
follow(): string[] | null;
|
||||
setFollow(keys: string[]): void;
|
||||
/** Show the problems of a pane that has no run because of them (and its first one, in the editor). */
|
||||
problems?(lang: LangId, line: number | null): void;
|
||||
}
|
||||
|
||||
const LIFE_MARK: Record<LifeKind, string> = { made: '●', copied: '⧉', 'moved-in': '⇢', 'moved-out': '⇥', destroyed: '✕' };
|
||||
@@ -143,7 +147,16 @@ export function runView(session: Session, root: HTMLElement, hooks: RunHooks): (
|
||||
|
||||
function build(force = false) {
|
||||
const trace = session.trace();
|
||||
if (!trace) { clear(head); clear(now); clear(scroll); add(scroll, el('p', { class: 'muted run-empty' }, session.runError || 'Nothing to run yet.')); built = null; return; }
|
||||
if (!trace) {
|
||||
// say what is in the way (the same reason the stepper gives), and offer the way to it
|
||||
const why = whyNoRun(session);
|
||||
clear(head); clear(now); clear(scroll);
|
||||
add(scroll, el('div', { class: 'run-empty' },
|
||||
el('p', { class: 'run-empty-head' }, why.headline),
|
||||
why.detail ? el('p', { class: 'run-empty-detail mono' }, why.detail) : null,
|
||||
why.errors && hooks.problems ? el('button', { type: 'button', class: 'btn btn-small', onClick: () => hooks.problems!(why.lang, why.line) }, why.errors === 1 ? 'Show the problem' : `Show the ${why.errors} problems`) : null));
|
||||
built = null; return;
|
||||
}
|
||||
if (trace.lang === 'asm') { clear(head); clear(now); clear(scroll); add(scroll, el('p', { class: 'muted run-empty' }, 'The machine\'s run is drawn on the board: registers, memory and the rest.')); built = null; return; }
|
||||
const cols = runColumns(trace);
|
||||
const follow = followed(cols);
|
||||
|
||||
+8
-12
@@ -15,6 +15,7 @@ import { varIn } from '#core/common/runview.js';
|
||||
import { formatHex, FLAG_NAMES } from '#core/engines/asm86/interp.js';
|
||||
import type { Session } from '../../core/session.js';
|
||||
import { familyOf, FAMILY_LABEL } from '../stepkinds.js';
|
||||
import { whyNoRun } from '../../core/norun.js';
|
||||
|
||||
export interface StepperApi { goto(t: number): void; t: number; destroy(): void; toggleBreakpoint(line: number): void; breakpoints: Set<number> }
|
||||
|
||||
@@ -75,10 +76,10 @@ export function traceView(session: Session, root: HTMLElement, opts: TraceOption
|
||||
const counter = el('span', { class: 'stepper-count' });
|
||||
const playBtn = button('Play', () => (timer ? pause() : play()), { title: 'Space' });
|
||||
add(controls,
|
||||
button('⏮', () => goto(0), { title: 'First step (Home)' }),
|
||||
button('◀', () => goto(t - 1), { title: 'Back one step (←)' }),
|
||||
button('▶', () => stepForward(), { title: 'One step (→)' }),
|
||||
button('⏭', () => goto(trace?.count ?? 0), { title: 'Last step (End)' }),
|
||||
button('⏮', () => goto(0), { title: 'First step (Home)', 'aria-label': 'First step' }),
|
||||
button('◀', () => goto(t - 1), { title: 'Back one step (←)', 'aria-label': 'Back one step' }),
|
||||
button('▶', () => stepForward(), { title: 'One step (→)', 'aria-label': 'One step forward' }),
|
||||
button('⏭', () => goto(trace?.count ?? 0), { title: 'Last step (End)', 'aria-label': 'Last step' }),
|
||||
playBtn, slider, counter,
|
||||
);
|
||||
const passBack = button('↶ pass', () => jumpPass(-1), { class: 'btn-small', title: 'Previous pass of the loop you are in (Shift+←)' });
|
||||
@@ -88,7 +89,7 @@ export function traceView(session: Session, root: HTMLElement, opts: TraceOption
|
||||
const writesBtn = button('Only writes', () => { onlyWrites = !onlyWrites; writesBtn.classList.toggle('on', onlyWrites); goto(t); }, { class: 'btn-small', title: 'Hide steps that change nothing' });
|
||||
const speedCtl = el('input', { type: 'range', min: 60, max: 1200, step: 10, value: 1200 - speed + 60, class: 'speed', title: 'Play speed', 'aria-label': 'Play speed', onInput: () => { speed = 1200 - Number(speedCtl.value) + 60; if (timer) { pause(); play(); } } });
|
||||
const csvBtn = button('CSV', () => exportCsv(), { class: 'btn-small btn-quiet', title: 'Download the trace table' });
|
||||
add(row2, passBack, passFwd, toBreak, predictBtn, drawsBody ? writesBtn : null, el('span', { class: 'spacer' }), el('span', {}, 'speed'), speedCtl, csvBtn);
|
||||
add(row2, passBack, passFwd, toBreak, predictBtn, drawsBody ? writesBtn : null, el('span', { class: 'spacer' }), el('label', { class: 'speed-wrap' }, 'speed', speedCtl), csvBtn);
|
||||
|
||||
function pause() { if (timer) { clearInterval(timer); timer = null; playBtn.textContent = 'Play'; } }
|
||||
function play() {
|
||||
@@ -490,7 +491,8 @@ export function traceView(session: Session, root: HTMLElement, opts: TraceOption
|
||||
histCache.clear();
|
||||
clear(body);
|
||||
if (!trace) {
|
||||
const why = session.runError || firstError(session) || 'Nothing to run yet.';
|
||||
const no = whyNoRun(session);
|
||||
const why = no.detail ?? no.headline;
|
||||
status.textContent = '';
|
||||
clear(nextBox); nextBox.className = 'trace-next k-empty'; add(nextBox, el('div', { class: 'trace-next-line' }, why)); nextBox.title = String(why); predictBox.style.display = 'none';
|
||||
output.style.display = 'none'; opts.onOutput?.([], null);
|
||||
@@ -504,12 +506,6 @@ export function traceView(session: Session, root: HTMLElement, opts: TraceOption
|
||||
goto(Math.min(t, trace.count));
|
||||
}
|
||||
|
||||
function firstError(s: Session): string | null {
|
||||
const lang = s.traceLang();
|
||||
const d = s.diagnostics(lang).find((x) => x.severity === 'error');
|
||||
return d ? `Line ${d.line}: ${d.message}` : null;
|
||||
}
|
||||
|
||||
const key = (e: KeyboardEvent) => {
|
||||
const target = e.target as HTMLElement | null;
|
||||
const tag = target?.tagName;
|
||||
|
||||
+64
-2
@@ -792,7 +792,8 @@ kbd {
|
||||
}
|
||||
|
||||
.workspace {
|
||||
--dock: 68%;
|
||||
/* the first paint; DEFAULT_DOCK in src/ui/shell.ts sets each area's own */
|
||||
--dock: 76%;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: grid;
|
||||
@@ -899,6 +900,14 @@ kbd {
|
||||
color: var(--warn);
|
||||
}
|
||||
|
||||
/* why a pane is not in step is the one thing to read before choosing Edit anyway: it wraps, it is never cut short */
|
||||
.pane-note.pane-stale {
|
||||
white-space: normal;
|
||||
overflow: visible;
|
||||
line-height: 1.35;
|
||||
padding: 2px 0;
|
||||
}
|
||||
|
||||
.badge-generated {
|
||||
background: var(--warn-bg);
|
||||
color: var(--warn);
|
||||
@@ -1024,6 +1033,12 @@ kbd {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* a button in the pane's head keeps its words on one line; the note beside it is what gives way */
|
||||
.pane-head .btn {
|
||||
white-space: nowrap;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.pane-note {
|
||||
color: var(--ink-2);
|
||||
min-width: 0;
|
||||
@@ -1984,6 +1999,14 @@ body.resizing textarea {
|
||||
accent-color: var(--accent);
|
||||
}
|
||||
|
||||
/* the word and its slider wrap as one, never the word at the end of a row and the slider on the next */
|
||||
.speed-wrap {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.trace-status {
|
||||
font-size: 12.5px;
|
||||
color: var(--ink-2);
|
||||
@@ -2489,6 +2512,13 @@ button.asm-src:hover {
|
||||
color: var(--ink-2);
|
||||
}
|
||||
|
||||
/* a narrow dialog: each row's name above what it holds, so no column is squeezed to a word per line */
|
||||
@media (max-width: 560px) {
|
||||
.share-row { grid-template-columns: minmax(0, 1fr) auto; gap: 4px 8px; margin: 10px 0; }
|
||||
.share-row > label:first-child, .share-row > .small { grid-column: 1 / -1; }
|
||||
.share-row > .btn { justify-self: start; }
|
||||
}
|
||||
|
||||
.share-actions {
|
||||
text-align: right;
|
||||
margin-top: 10px;
|
||||
@@ -3998,6 +4028,9 @@ button.asm-src:hover {
|
||||
.run-life-destroyed { color: #c0392b; }
|
||||
.run-more td { text-align: center; padding: 6px; }
|
||||
.run-empty, .run-error { padding: 10px 12px; }
|
||||
/* no run to show: what is in the way, the first problem, and the way to the rest */
|
||||
.run-empty-head { margin: 0 0 6px; color: var(--ink); }
|
||||
.run-empty-detail { margin: 0 0 10px; padding: 6px 10px; border-left: 3px solid var(--err); background: var(--paper-2); font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
|
||||
.run-now { align-items: flex-start; }
|
||||
.run-chip { display: inline-flex; align-items: center; gap: 2px; }
|
||||
.run-chip-fn { color: var(--ink-3); }
|
||||
@@ -4189,6 +4222,8 @@ button.asm-src:hover {
|
||||
.qg-index a.qg-kind-rendered { color: var(--ok); }
|
||||
.qg-index a.qg-kind-live { color: var(--accent); }
|
||||
.qg-gallery { display: flex; flex-direction: column; gap: 22px; margin-top: 14px; }
|
||||
/* a section the address names stops a little under the top of the window, not flush against it */
|
||||
#problems, #reference, #quarto-teaser { scroll-margin-top: 16px; }
|
||||
.qg-card { scroll-margin-top: 16px; padding: 18px 18px 14px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--paper); }
|
||||
.qg-card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
|
||||
.qg-card-head h3 { margin: 0; font-size: 17px; order: -1; flex-basis: 100%; }
|
||||
@@ -4325,10 +4360,32 @@ button.asm-src:hover {
|
||||
bar at the foot of the toolbar (shell.ts, setNarrow): the code with the stepper under it; the side column (or the
|
||||
board) with the stepper above it; or the dock. Each part scrolls inside itself. A wider screen never sees the bar. */
|
||||
.narrow-bar { display: none; }
|
||||
/* a label with a short form for a small phone (the Best practices switch) */
|
||||
.tool-tight { display: none; }
|
||||
@media (max-width: 700px) {
|
||||
.toolbar { gap: 6px 8px; padding: 6px 10px; }
|
||||
.narrow-bar { display: flex; flex-basis: 100%; }
|
||||
.narrow-bar .seg-opt { flex: 1; }
|
||||
.narrow-bar .seg-opt { flex: 1; padding-left: 6px; padding-right: 6px; white-space: nowrap; }
|
||||
/* three rows above the bar: the mark, the area, help and the theme; the problem, its versions and Reset; the
|
||||
actions. The spacer that pushes the actions right on a wide screen has nothing to push here, and the ::after is
|
||||
the line break between the second row and the third (a flex line of no height; its margin takes the gap back). */
|
||||
.shell:not(.shell-embed) > .toolbar { gap: 0 6px; padding-top: 3px; padding-bottom: 3px; }
|
||||
.shell:not(.shell-embed) > .toolbar > * { margin-top: 3px; margin-bottom: 3px; }
|
||||
.shell:not(.shell-embed) > .toolbar > .spacer, .shell:not(.shell-embed) > .toolbar > .brand .brand-name { display: none; }
|
||||
.shell:not(.shell-embed) > .toolbar > .seg .seg-opt { padding-left: 10px; padding-right: 10px; }
|
||||
.shell:not(.shell-embed) > .toolbar > .icon-btn { order: 1; }
|
||||
.shell:not(.shell-embed) > .toolbar > .tool-help { margin-left: auto; }
|
||||
.shell:not(.shell-embed) > .toolbar::before, .shell:not(.shell-embed) > .toolbar::after { content: ""; flex-basis: 100%; height: 0; }
|
||||
.shell:not(.shell-embed) > .toolbar::before { order: 2; }
|
||||
.shell:not(.shell-embed) > .toolbar > .select { order: 3; flex: 1 1 0; min-width: 120px; }
|
||||
.shell:not(.shell-embed) > .toolbar > .versions, .shell:not(.shell-embed) > .toolbar > .tool-reset { order: 3; }
|
||||
.shell:not(.shell-embed) > .toolbar::after { order: 4; }
|
||||
.shell:not(.shell-embed) > .toolbar > .btn:not(.icon-btn):not(.tool-reset) { order: 5; padding-left: 8px; padding-right: 8px; }
|
||||
.shell:not(.shell-embed) > .toolbar > .narrow-bar { order: 6; }
|
||||
/* the Versions menu opens across the screen, under its button, instead of running off the right edge */
|
||||
.toolbar { position: relative; }
|
||||
.toolbar > .versions { position: static; }
|
||||
.toolbar > .versions .versions-menu { left: 10px; right: 10px; top: auto; width: auto; margin-top: 4px; }
|
||||
.shell { height: 100vh; height: 100dvh; min-height: 0; }
|
||||
.workspace, .workspace.workspace-board { flex: 1; min-height: 0; }
|
||||
.main { flex: 1; min-height: 0; }
|
||||
@@ -4346,3 +4403,8 @@ button.asm-src:hover {
|
||||
.workspace[data-narrow="dock"] .dock { flex: 1; min-height: 0; }
|
||||
.workspace[data-narrow="dock"] .dock-body { display: block; max-height: none; }
|
||||
}
|
||||
@media (max-width: 380px) {
|
||||
.tool-wide { display: none; }
|
||||
.tool-tight { display: inline; }
|
||||
.shell:not(.shell-embed) > .toolbar > .btn:not(.icon-btn):not(.tool-reset) { padding-left: 6px; padding-right: 6px; }
|
||||
}
|
||||
+20
-1
@@ -9,7 +9,7 @@ import assert from 'node:assert/strict';
|
||||
import { Session } from '../dist/core/session.js';
|
||||
import { PROBLEMS, stateForProblem, problemById } from '../dist/core/catalog.js';
|
||||
import { SyncHub } from '../core/dist/sync/hub.js';
|
||||
import { normalize } from '../dist/core/state.js';
|
||||
import { normalize, editedFrom } from '../dist/core/state.js';
|
||||
import { GENERATED_HEADER } from '../core/dist/sync/header.js';
|
||||
|
||||
globalThis.localStorage = { getItem() { return null; }, setItem() { }, removeItem() { } };
|
||||
@@ -27,6 +27,25 @@ test('in the Bridge the Mojo pane is the generated Mojo, not the stored Mojo; el
|
||||
assert.equal(new Session(stateForProblem(problemById('count-base')), { storageId: null }).source('mojo'), own, 'a session with no area (an embed of one pane) shows the state\'s own Mojo');
|
||||
});
|
||||
|
||||
test('nothing given to the Bridge\'s Mojo pane is stored: opening a problem there leaves the exercise\'s own Mojo', () => {
|
||||
// the workspace fills every pane's editor as it opens; the generated Mojo, loaded into the Bridge's read-only
|
||||
// pane, had been reported as typing and saved over the exercise's program, which Developer then called "your edits"
|
||||
const own = stateForProblem(problemById('count-base')).sources.mojo;
|
||||
const s = open('count-base', 'bridge');
|
||||
let told = 0;
|
||||
s.onChange(() => told++);
|
||||
s.setSource('mojo', s.source('mojo'));
|
||||
s.setSource('mojo', 'def main():\n pass\n');
|
||||
assert.equal(s.state.sources.mojo, own, 'the stored Mojo is still the exercise\'s');
|
||||
assert.equal(s.state.mojoOrigin, undefined);
|
||||
assert.equal(told, 0, 'and nothing was announced as a change');
|
||||
assert.equal(editedFrom(s.state, stateForProblem(problemById('count-base'))), false, 'so the problem does not count as edited');
|
||||
// elsewhere the Mojo pane is the student's
|
||||
const d = open('count-base', 'dev');
|
||||
d.setSource('mojo', 'def main():\n pass\n');
|
||||
assert.equal(d.state.sources.mojo, 'def main():\n pass\n');
|
||||
});
|
||||
|
||||
test('the Bridge\'s Mojo follows an edit in any linked pane, and every view of it reads the generated source', () => {
|
||||
const s = open('count-base');
|
||||
const before = s.source('mojo');
|
||||
|
||||
@@ -31,3 +31,12 @@ test('textareas are only for the small setup and input boxes, never for code', (
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('text the app loads into an editor is not reported as the student typing', () => {
|
||||
// the value setter and setSynced mark their change (the `load` and `sync` user events), and the listener that
|
||||
// reports edits leaves both out; without it, filling the Bridge's read-only Mojo pane saved the generated Mojo
|
||||
const text = src('src/ui/editor.ts');
|
||||
assert.match(text, /set value\(v: string\) \{[\s\S]{0,700}?userEvent: 'load'/, 'the value setter no longer marks its change as a load');
|
||||
assert.match(text, /setSynced\(v: string\): void \{[\s\S]{0,700}?userEvent: 'sync'/, 'setSynced no longer marks its change as a sync');
|
||||
assert.match(text, /!tr\.isUserEvent\('sync'\) && !tr\.isUserEvent\('load'\)\)\) this\.opts\.onChange/, 'the change listener reports loads or syncs as edits');
|
||||
});
|
||||
@@ -35,3 +35,20 @@ test('the shell offers the parts, and Run, Compile & run and a diagnostic\'s lin
|
||||
assert.match(shell, /if \(open\) this\.setNarrow\('dock'\);/, 'opening the dock (Compile & run) shows it');
|
||||
assert.match(shell, /reveal: \(lang, line\) => \{\n\s*this\.setNarrow\('code'\);/, 'a line in the code shows the code');
|
||||
});
|
||||
|
||||
test('a phone-width toolbar is three rows: the classes its rules order are the ones the shell gives', () => {
|
||||
// the mark, the area, help and the theme; the problem, its versions and Reset; the actions. A wide screen keeps the
|
||||
// toolbar's one row, so every one of these rules is inside the 700px query and none applies to an embed's toolbar.
|
||||
const shell = readFileSync(new URL('../src/ui/shell.ts', import.meta.url), 'utf8');
|
||||
const narrow = blocks(css).filter(([p]) => /^@media \(max-width: 700px\)$/.test(p)).map(([, b]) => b).join('\n');
|
||||
for (const cls of ['tool-help', 'tool-reset', 'brand-name', 'icon-btn', 'versions']) {
|
||||
assert.match(shell, new RegExp(`['\` ]${cls}['\` $]`), `the shell no longer gives .${cls}`);
|
||||
assert.match(narrow, new RegExp(`\\.shell:not\\(\\.shell-embed\\) > \\.toolbar[^{]*\\.${cls}\\b`), `no narrow rule for .${cls}`);
|
||||
}
|
||||
assert.match(shell, /class: 'shell' \+ \(this\.embed \? ' shell-embed' : ''\)/, 'an embedded workspace is marked, so its toolbar keeps its own order');
|
||||
assert.match(narrow, /\.toolbar::before, \.shell:not\(\.shell-embed\) > \.toolbar::after \{[^}]*flex-basis: 100%/, 'the two line breaks between the rows');
|
||||
// the short label of the Best practices switch is for a small phone only
|
||||
assert.match(shell, /class: 'tool-wide' \}, 'Best practices'\), el\('span', \{ class: 'tool-tight' \}, 'Practices'\)/);
|
||||
const outside = blocks(css).filter(([p]) => !p.startsWith('@media')).map(([p, b]) => `${p}{${b}}`.replace(/\s+/g, ' '));
|
||||
assert.ok(outside.some((r) => /^\.tool-tight\s*\{ display: none; \}$/.test(r)), '.tool-tight is hidden on a normal screen');
|
||||
});
|
||||
@@ -0,0 +1,55 @@
|
||||
// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// When there is no run to step, the stepper and the Run view say what is in the way (src/core/norun.ts): how many
|
||||
// problems the stepped pane has and the first one, what an engine said when it stopped, or that the pane is empty.
|
||||
// "Nothing to run yet." alone told a student with a typo nothing.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import { Session } from '../dist/core/session.js';
|
||||
import { stateForProblem, problemById } from '../dist/core/catalog.js';
|
||||
import { whyNoRun } from '../dist/core/norun.js';
|
||||
|
||||
globalThis.localStorage = { getItem() { return null; }, setItem() { }, removeItem() { } };
|
||||
const open = (id, area) => new Session(stateForProblem(problemById(id)), { area, storageId: null });
|
||||
|
||||
test('a pane with problems says how many, and names the first with its line', () => {
|
||||
const s = open('count-base', 'bridge');
|
||||
s.setLang('pseudo');
|
||||
s.setSource('pseudo', s.source('pseudo') + '\nTotal <- Totl + \n');
|
||||
assert.equal(s.trace(), null);
|
||||
const why = whyNoRun(s);
|
||||
assert.equal(why.lang, 'pseudo');
|
||||
assert.ok(why.errors >= 2, `${why.errors} errors`);
|
||||
assert.equal(why.headline, `No run yet: the pseudo pane has ${why.errors} problems to fix first.`);
|
||||
const first = s.diagnostics('pseudo').find((d) => d.severity === 'error');
|
||||
assert.equal(why.detail, `Line ${first.line}: ${first.message}`);
|
||||
assert.equal(why.line, first.line);
|
||||
});
|
||||
|
||||
test('one problem is "a problem", and Mojo\'s own errors are counted the same way', () => {
|
||||
const s = open('count-base', 'dev');
|
||||
s.setLang('mojo');
|
||||
s.setSource('mojo', 'def main():\n var s = String("hi")\n var t = s^\n print(s)\n');
|
||||
assert.equal(s.trace(), null);
|
||||
assert.deepEqual(whyNoRun(s), { headline: 'No run yet: the Mojo pane has a problem to fix first.', detail: "Line 4: use of uninitialized value 's'", errors: 1, lang: 'mojo', line: 4 });
|
||||
});
|
||||
|
||||
test('an empty pane says it is empty', () => {
|
||||
const s = open('count-base', 'dev');
|
||||
s.setLang('mojo');
|
||||
s.setSource('mojo', ' \n');
|
||||
assert.equal(s.trace(), null);
|
||||
assert.deepEqual(whyNoRun(s), { headline: 'Nothing to run yet: the Mojo pane is empty.', detail: null, errors: 0, lang: 'mojo', line: null });
|
||||
});
|
||||
|
||||
test('a pane that runs has no such reason to give: the views ask only when trace() is null', () => {
|
||||
const s = open('count-base', 'bridge');
|
||||
s.setLang('pseudo');
|
||||
assert.ok(s.trace());
|
||||
for (const f of ['src/ui/views/run.ts', 'src/ui/views/trace.ts']) {
|
||||
const text = fs.readFileSync(new URL(`../${f}`, import.meta.url), 'utf8');
|
||||
assert.match(text, /whyNoRun\(session\)/, `${f} no longer asks whyNoRun`);
|
||||
assert.doesNotMatch(text, /'Nothing to run yet\.'/, `${f} has its own "Nothing to run yet." again`);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user