Skip to content

Commit 4efef01

Browse files
Web 0.13.35: Java-Beispiele mit „Im Editor öffnen“, Lektion 4 „Text in Java“ (#222)
```java editor zeigt unter dem Beispiel den Knopf „Im Editor öffnen“: neuer Reiter, Spalte Programmieren auf Java, das Struktogramm entsteht aus dem Code. Lektion 4 (Mia, 14, 1.62) nutzt ihn (de/en/pt). Test: jedes solche Beispiel parst ohne Fehler. Claude-Session: https://claude.ai/code/session_01Ugz28SXiSAUwXyrxcvRaHn Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9d2951c commit 4efef01

19 files changed

Lines changed: 91 additions & 36 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The format is loosely inspired by Keep a Changelog.
1414

1515
### Added
1616

17+
- **Web 0.13.35, open Java examples in the editor:** a Java example in a lesson can now carry the button „Im Editor öffnen“. It opens the example in a new tab with Programmieren set to Java, so students can run it, change values and try again; the structure chart builds itself from the code. Lesson 4 step „Text in Java“ (Mia, 14, 1.62) uses it and says how to try it (de/en/pt). For authors: write ```` ```java editor ```` instead of ```` ```java ````; a test checks that every such example parses without errors.
1718
- **Web 0.13.32, every exercise says where to solve it:** below the title of each exercise card a small label names the area: „Löse diese Übung im Struktogramm.“ or, for `code: java` exercises, „Löse diese Übung in Programmieren.“ The area names are taken from the on-screen headings, so they always match (de/en/pt; applies to all VisuStruct, VisuBot and task-area exercises).
1819
- **Web 0.13.28, data type char:** lesson 4 now names `char` after the four data types (a single character in single quotation marks, e.g. `char note = 'C'`, more in lesson 17). Lesson 17 has its own step „Ein einzelnes Zeichen: char“: `'C'` vs. `"C"`, no empty char, `charAt`, comparing with `==`, and the character code from the ASCII table with `(int)` and `(char)` as preparation for the Caesar task, plus a competence, a checklist line and two quiz questions for it. Nachschlagen has a new table „Datentypen“ with int, double, String, boolean and char; the glossary has new entries char and Zeichencode, and Datentyp mentions char (de/en/pt).
1920
- **Web 0.13.26, competences and „Ich kann“ checklists in the VisuBot lessons:** all 22 VisuBot lessons follow the pattern of the VisuStruct lessons: first step „Diese Kompetenzen erwerbe ich jetzt“, „Ich kann …“ checklist with ☂️ ⛅ ☀️, quiz questions linked to their steps (de/en).

‎web/lessons/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ Eine Ausgabe mit Text in Anführungszeichen.
4646
:::
4747
```
4848

49+
Ein Java-Beispiel im Text mit Knopf „Im Editor öffnen“: Statt ```` ```java ```` schreibt man ```` ```java editor ````. Der Knopf
50+
öffnet das Beispiel in einem neuen Reiter, die Spalte Programmieren auf Java; dort kann man es ausführen und verändern.
51+
Der Test prüft, dass jedes solche Beispiel ohne Fehler geparst wird.
52+
4953
Eine Übung, die VisuStruct beim Klick auf „Prüfen“ automatisch kontrolliert:
5054

5155
```

‎web/lessons/de/04-variablen-und-datentypen.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ Java hieß zuerst **Oak** (Eiche), nach dem Baum vor dem Bürofenster von James
184184

185185
Variablen speichern nicht nur Zahlen. Für Text gibt es den Datentyp `String`:
186186

187-
```java
187+
```java editor
188188
String name = "Mia";
189189
int alter = 14;
190190
double groesse = 1.62;
@@ -196,7 +196,7 @@ System.out.println("Größe: " + groesse + " m");
196196
- `String` schreibst du groß, `int`, `double` und `boolean` klein. Java unterscheidet das.
197197
- Mit `+` hängst du Text und Zahlen aneinander.
198198

199-
Java tippst du im Bereich [Programmieren](#zeige-codelive). Das Struktogramm entsteht dabei von selbst.
199+
Java tippst du im Bereich [Programmieren](#zeige-codelive). Das Struktogramm entsteht dabei von selbst. „Im Editor öffnen“ holt das Beispiel in den Bereich Programmieren. Klicke dort auf „Ausführen“, ändere dann Name, Alter oder Größe und probiere es noch einmal.
200200

201201
::: übung l04-java-steckbrief
202202
titel: Steckbrief in Java

‎web/lessons/en/04-variablen-und-datentypen.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ Java was first called **Oak**, after the tree outside James Gosling’s office w
184184

185185
Variables do not only store numbers. For text there is the data type `String`:
186186

187-
```java
187+
```java editor
188188
String name = "Mia";
189189
int age = 14;
190190
double height = 1.62;
@@ -196,7 +196,7 @@ System.out.println("Height: " + height + " m");
196196
- You write `String` with a capital letter, `int`, `double` and `boolean` in lowercase. Java tells them apart.
197197
- With `+` you join text and numbers together.
198198

199-
You type Java in the [Programming](#zeige-codelive) area. The structure chart builds itself as you type.
199+
You type Java in the [Programming](#zeige-codelive) area. The structure chart builds itself as you type. “Open in editor” brings the example into the Programming area. Click “Run” there, then change the name, age or height and try again.
200200

201201
::: übung l04-java-steckbrief
202202
titel: Profile in Java

‎web/lessons/pt/04-variablen-und-datentypen.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ O Java chamava-se primeiro **Oak** (carvalho), por causa da árvore em frente à
184184

185185
As variáveis não guardam só números. Para texto existe o tipo de dados `String`:
186186

187-
```java
187+
```java editor
188188
String nome = "Inês";
189189
int idade = 14;
190190
double altura = 1.62;
@@ -196,7 +196,7 @@ System.out.println("Altura: " + altura + " m");
196196
- `String` escreve-se com maiúscula, `int`, `double` e `boolean` com minúscula. O Java distingue-os.
197197
- Com `+` juntas texto e números.
198198

199-
Escreves Java na área [Programação](#zeige-codelive). O estrutograma constrói-se sozinho enquanto escreves.
199+
Escreves Java na área [Programação](#zeige-codelive). O estrutograma constrói-se sozinho enquanto escreves. “Abrir no editor” leva o exemplo para a área Programação. Clica aí em “Executar”, depois muda o nome, a idade ou a altura e experimenta outra vez.
200200

201201
::: übung l04-java-steckbrief
202202
titel: Ficha em Java

‎web/package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎web/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "visustruct-web",
33
"private": true,
4-
"version": "0.13.34",
4+
"version": "0.13.35",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

‎web/src/learn/markdown.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ export function markdownToHTML(source: string): string {
3434
continue
3535
}
3636
if (line.startsWith('```')) {
37-
const java = line.slice(3).trim() === 'java'
37+
// ```java editor: Unter dem Beispiel steht „Im Editor öffnen“, dann kann man es in Programmieren ausprobieren.
38+
const [lang, extra] = line.slice(3).trim().split(/\s+/)
39+
const java = lang === 'java'
40+
const open = java && extra === 'editor'
3841
const code: string[] = []
3942
i++
4043
while (i < lines.length && !lines[i].startsWith('```')) code.push(lines[i++])
4144
i++
42-
out.push(`<pre class="lesson-code"${java ? ' data-lang="java"' : ''} dir="ltr"><code>${escape(code.join('\n'))}</code></pre>`)
45+
out.push(`<pre class="lesson-code"${java ? ' data-lang="java"' : ''}${open ? ' data-open="editor"' : ''} dir="ltr"><code>${escape(code.join('\n'))}</code></pre>`)
4346
continue
4447
}
4548
const heading = /^(#{2,4})\s+(.*)$/.exec(line)

‎web/src/ui/app.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,19 @@ export class App {
12451245
this.setSimulating(false)
12461246
this.render()
12471247
},
1248+
openJavaCode: (java: string) => {
1249+
this.openJavaColumn()
1250+
const tab = this.makeTab()
1251+
tab.doc = this.live.documentFromJavaText(java)
1252+
// Ein unberührter leerer Reiter wird ersetzt statt einen weiteren zu öffnen.
1253+
if (this.isPristine(this.tab)) this.tabs[this.tabIndex] = tab
1254+
else this.tabs.push(tab)
1255+
this.tabIndex = this.tabs.indexOf(tab)
1256+
this.setSimulating(false)
1257+
// Der Code bleibt so stehen, wie er in der Lektion steht.
1258+
this.live.adoptJava(tab.doc, java)
1259+
this.render()
1260+
},
12481261
openDiagram: (doc: VSDocument, fileName: string) => {
12491262
this.setEditorHidden(false)
12501263
// Tab nach der Diagrammüberschrift benennen, nicht nach der Datei (l1-tee)

‎web/src/ui/learnPanel.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import { attachPointers, attachTermTips, markPointers, markTerms, pointsIntoEdit
3030
export interface LearnHost {
3131
/** Übung im Editor öffnen (vorhandenen Reiter wählen oder neuen anlegen). */
3232
openExercise(exercise: Exercise, doc: VSDocument): void
33+
/** Java-Beispiel aus dem Text in einem neuen Reiter öffnen, Spalte „Programmieren“ auf Java. */
34+
openJavaCode(java: string): void
3335
/** Beispieldiagramm in einem neuen Reiter öffnen. */
3436
openDiagram(doc: VSDocument, fileName: string): void
3537
/** Diagramm des Reiters, in dem die Übung offen ist. */
@@ -434,7 +436,7 @@ export class LearnPanel {
434436
private renderBlock(block: Block, key: string, lesson?: Lesson): HTMLElement {
435437
switch (block.kind) {
436438
case 'markdown':
437-
return html('div', { class: 'learn-text' }, markdownToHTML(block.text))
439+
return this.withOpenButtons(html('div', { class: 'learn-text' }, markdownToHTML(block.text)))
438440
case 'diagram':
439441
return this.renderDiagram(block.file, block.caption)
440442
case 'exercise':
@@ -576,6 +578,17 @@ export class LearnPanel {
576578
return figure
577579
}
578580

581+
/** Unter jedes Java-Beispiel mit ```java editor kommt „Im Editor öffnen“. */
582+
private withOpenButtons(text: HTMLElement): HTMLElement {
583+
for (const pre of text.querySelectorAll<HTMLElement>('pre.lesson-code[data-open=editor]')) {
584+
const code = pre.textContent ?? ''
585+
const open = h('button', { class: 'learn-open-code' }, t('web_learn_open_in_editor'))
586+
open.addEventListener('click', () => this.host.openJavaCode(code))
587+
pre.after(open)
588+
}
589+
return text
590+
}
591+
579592
private renderDiagram(file: string, caption: string): HTMLElement {
580593
const doc = diagram(file)
581594
const figure = h('figure', { class: 'learn-figure' })

0 commit comments

Comments
 (0)