From 1285bb48a9fb95d4b49da890a4b5f036f8842de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Vogel?= <104342347+cedricvogel-leo@users.noreply.github.com> Date: Sun, 1 Nov 2026 20:57:43 +0100 Subject: [PATCH] Editor: no live completion and no snippets in glpython blocks (P31) LiaScript 2.1.1 turns on live autocompletion and snippets for every executable block: "if" + Enter or + Tab became a whole statement, also in a docstring. The macro switches both off, like tabSize, unless the block's data-ace-options sets them. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 3 ++- README.md | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index e8731d6..b471a62 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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/ -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 `` 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. diff --git a/README.md b/README.md index 61f6a4f..30a2193 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. -``) 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. `` +or `enableLiveAutocompletion=true`) still wins. ## State and navigation