Skip to content

Commit

Permalink
fix(programming-module): listen for code value changes (#102)
Browse files Browse the repository at this point in the history
fixes "Reset Code" button
  • Loading branch information
xhyrom authored Nov 20, 2024
1 parent e3fe2e3 commit 87c1154
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,37 @@ export class TaskModuleProgrammingComponent implements OnInit, OnDestroy {
}
])

new EditorView({
const editor = new EditorView({
doc: this.module.code || this.module.default_code,
parent: this.codeEditorContainer.nativeElement,
extensions: [
basicSetup, // default extensions
indentUnit.of(" "), // PEP-8 needs 4 spaces
indentUnit.of(' '), // PEP-8 needs 4 spaces
keymap.of([indentWithTab]), // tab keymap
EditorView.updateListener.of((v: ViewUpdate) => {
this.code.setValue(v.state.doc.toString());
this.code.setValue(v.state.doc.toString(), {
emitEvent: false,
});
}),
syntaxHighlighting(highlightStyle), // own colors for highlighting
python(), // support for python
]
})
],
});

this.subs.push(
this.code.valueChanges.subscribe((value: string) => {
// replace all tabs with spaces
value = value.replace(/\t/g, ' ');

editor.dispatch({
changes: {
from: 0,
to: editor.state.doc.length,
insert: value,
},
});
})
);
}

lintCode(): void {
Expand Down

0 comments on commit 87c1154

Please sign in to comment.