Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Nothing runs LiaScript automatically, so test a change in the hosted player:
## How LiaScript behaves (source: github.com/LiaScript/LiaScript)

`../liascript` is an empty folder. Read the sources with `gh api repos/LiaScript/LiaScript/contents/<path> -H "Accept: application/vnd.github.raw"`.
- **The code editor** is the `lia-editor` web component (`src/typescript/webcomponents/editor.ts`). Its options (`tabSize`, `useSoftTabs`, `aceOptions`, …) are properties with setters that pass them on to Ace. Elm sets them from `src/elm/Lia/Markdown/Code/View.elm` (defaults there, e.g. tab size 2 and hard tabs). It re-sets one only when its own value changes or the element is new.
- **The code editor** is the `lia-editor` web component (`src/typescript/webcomponents/editor.ts`). Its options (`tabSize`, `useSoftTabs`, `aceOptions`, …) are properties with setters that pass them on to Ace. Elm sets them from `src/elm/Lia/Markdown/Code/View.elm` (defaults there, e.g. tab size 2 and hard tabs). It re-sets one only when its own value changes or the element is new. Since LiaScript 2.1.1 it turns on `enableBasicAutocompletion`, `enableLiveAutocompletion` and `enableSnippets` for every executable block; the macro switches the last two off (`indentWithSpaces`).
- **Storing code:** LiaScript stores a block (a new version, if the code differs from the active one) when its run button is clicked (`Eval` in `Code/Update.elm`), before the result. The run's script runs inside that click, so the macro's `commandAfterLiaRun` is used up before a second click.
- **Block options:** a block's `<!-- data-… -->` options end up as attributes on its `lia-editor`. A course's own `data-*` options must keep winning over the macro.
- **`attach()`** in the run-once block runs on every DOM change (MutationObserver). Everything it does must be idempotent and must compare before it writes, or it loops. Don't set properties on a `lia-editor` that isn't upgraded yet (`"tabSize" in editor`), or they would hide the setters.

Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,14 @@ window.__glpythonMount = (args, send) => {
const aceOptions = (editor.getAttribute("data-ace-options") ?? "").split(/[\s,]+/).map((entry) => entry.split("=")[0])
if (!editor.hasAttribute("data-tabsize") && !aceOptions.includes("tabSize") && editor.tabSize !== 4) editor.tabSize = 4
if (!aceOptions.includes("useSoftTabs") && editor.useSoftTabs !== true) editor.useSoftTabs = true
// Since LiaScript 2.1.1 every executable block completes as one types and
// expands snippets: a word like "if" + Enter, or + Tab, became a whole
// statement, also in a docstring. Off in glpython blocks, the same way and
// with the same exceptions as above. Ctrl+Space still completes a name on
// request (keywords and the block's words, no snippets).
for (const option of ["enableLiveAutocompletion", "enableSnippets"]) {
if (option in editor && !aceOptions.includes(option) && editor[option] !== false) editor[option] = false
}
}

// Every code block right before the iframe (LiaScript groups consecutive
Expand Down Expand Up @@ -821,8 +829,12 @@ does not reserve space for turtle graphics.

The macro makes the block's editor indent with 4 spaces: Tab inserts spaces, not
LiaScript's default tab character, which would stop Python with a `TabError` in a block
indented with spaces. A block's own `data-tabsize` or `data-ace-options` (e.g.
`<!-- data-ace-options="useSoftTabs=false" -->`) still wins.
indented with spaces. It also switches off the completion as one types and the
snippets LiaScript turns on since version 2.1.1, so Enter is always a new line and Tab
never expands a word (`if` + Enter became a whole `if` statement, also in a
docstring); Ctrl+Space still completes a name on request. A block's own
`data-tabsize` or `data-ace-options` (e.g. `<!-- data-ace-options="useSoftTabs=false" -->`
or `enableLiveAutocompletion=true`) still wins.

## State and navigation

Expand Down
Loading