diff --git a/app/assets/javascripts/coding_scratchpad.ts b/app/assets/javascripts/coding_scratchpad.ts index cd7b312fa6..9baa5d291c 100644 --- a/app/assets/javascripts/coding_scratchpad.ts +++ b/app/assets/javascripts/coding_scratchpad.ts @@ -1,10 +1,9 @@ -import { BackendManager, CodeEditor, InputMode, Papyros, ProgrammingLanguage } from "@dodona/papyros"; +import { CodeEditor, InputMode, Papyros, ProgrammingLanguage } from "@dodona/papyros"; import { themeState } from "state/Theme"; import { EditorView } from "@codemirror/view"; import { rougeStyle, setCode } from "editor"; import { syntaxHighlighting } from "@codemirror/language"; import { i18n } from "i18n/i18n"; -import { BackendEventType } from "@dodona/papyros/dist/BackendEvent"; import { Tab } from "bootstrap"; /** Identifiers used in HTML for relevant elements */ @@ -96,26 +95,17 @@ export async function initPapyros(programmingLanguage: ProgrammingLanguage): Pro fallback: true })]); - // Hide Trace tab when a new run is started - BackendManager.subscribe(BackendEventType.Start, () => { + papyros.codeRunner.addEventListener("debug-mode", (event: CustomEvent) => { + const debugMode = event.detail; const traceTab = document.getElementById(TRACE_TAB_ID); - if (traceTab) { - traceTab.classList.add("hidden"); - const descriptionTab = document.getElementById(DESCRIPTION_TAB_ID); - if (descriptionTab) { - const tabTrigger = new Tab(descriptionTab.querySelector("a")); - tabTrigger.show(); - } - } - }); - - // Show Trace tab when a new frame is added - BackendManager.subscribe(BackendEventType.Frame, () => { - const traceTab = document.getElementById(TRACE_TAB_ID); - if (traceTab) { - traceTab.classList.remove("hidden"); + traceTab.classList.toggle("hidden", !debugMode); + if (debugMode) { const tabTrigger = new Tab(traceTab.querySelector("a")); tabTrigger.show(); + } else { + const descriptionTab = document.getElementById(DESCRIPTION_TAB_ID); + const tabTrigger = new Tab(descriptionTab.querySelector("a")); + tabTrigger.show(); } }); } diff --git a/app/assets/javascripts/tutor.ts b/app/assets/javascripts/tutor.ts index aa016064be..56d727e8f3 100644 --- a/app/assets/javascripts/tutor.ts +++ b/app/assets/javascripts/tutor.ts @@ -49,15 +49,7 @@ export function initTutor(submissionCode: string): void { async function loadTutor(exerciseId: string, studentCode: string, statements: string, stdin: string, inlineFiles: Record, hrefFiles: Record): Promise { const papyros = await initPapyros(ProgrammingLanguage.Python); - if (papyros.codeRunner.getState() !== RunState.Ready && papyros.codeRunner.getState() !== RunState.Loading) { - // stop the code runner if it is running - await papyros.codeRunner.stop(); - - // wait to make sure the code runner is stopped - while (papyros.codeRunner.getState() === RunState.Stopping) { - await new Promise(resolve => setTimeout(resolve, 100)); - } - } + await papyros.codeRunner.reset(); papyros.setCode(studentCode); papyros.codeRunner.inputManager.setInputMode(InputMode.Batch); diff --git a/package.json b/package.json index 67d977df7a..0b7b56d481 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "@codemirror/language-data": "^6.4.1", "@codemirror/state": "^6.3.3", "@codemirror/view": "^6.24.0", - "@dodona/papyros": "2.2.0", + "@dodona/papyros": "2.3.2", "@lezer/common": "^1.2.1", "@lezer/highlight": "^1.2.0", "@lezer/lr": "^1.4.0", diff --git a/yarn.lock b/yarn.lock index 2bf181af24..40ea45a7f8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1327,10 +1327,10 @@ resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70" integrity sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw== -"@dodona/papyros@2.2.0": - version "2.2.0" - resolved "https://registry.yarnpkg.com/@dodona/papyros/-/papyros-2.2.0.tgz#eb80c8d9263c7e8cefbf55661b884736f02bf892" - integrity sha512-DGXKWegvOMWEGhxNoYVwNkWwF3Y+odWc8is6qiLlETKCh78rvw5fUlb0mGhWRw7VPZANxAOqXa4O9royJnp5YQ== +"@dodona/papyros@2.3.2": + version "2.3.2" + resolved "https://registry.yarnpkg.com/@dodona/papyros/-/papyros-2.3.2.tgz#4572f1a7a70a4c0b731bc5d0d116e364e198af34" + integrity sha512-rCQYQxggtlWEPkj8srGYlJFX+dKH4JTJAEUeU4N+35bN3VfATdscLaqHd/kLRoM6fUsbl9IZRWsn7GIRSjI4OQ== dependencies: "@codemirror/autocomplete" "^6.11.1" "@codemirror/commands" "^6.3.1" @@ -1349,7 +1349,7 @@ comsync "^0.0.9" escape-html "^1.0.3" file-loader "^6.2.0" - i18n-js "4.4.0" + i18n-js "4.4.3" pyodide "^0.22.0" pyodide-worker-runner "1.3.2" sync-message "^0.0.12" @@ -4858,10 +4858,10 @@ human-signals@^1.1.1: resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3" integrity sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw== -i18n-js@4.4.0: - version "4.4.0" - resolved "https://registry.yarnpkg.com/i18n-js/-/i18n-js-4.4.0.tgz#fddb46ea7dec8fbdb20176a7d89f0b2dba5035d5" - integrity sha512-nAOY1z+lPX4dCEUbl9Uw7JtrJFRDjQm7XLk5Lf8iQYFOwZ0yA//jzp42r+OwOt7SazUkYr55R6Dt9ziQGUlxFQ== +i18n-js@4.4.3: + version "4.4.3" + resolved "https://registry.yarnpkg.com/i18n-js/-/i18n-js-4.4.3.tgz#09744ddd377261f614502cc5622ce6981026ea4a" + integrity sha512-QIIyvJ+wOKdigL4BlgwiFFrpoXeGdlC8EYgori64YSWm1mnhNYYjIfRu5wETFrmiNP2fyD6xIjVG8dlzaiQr/A== dependencies: bignumber.js "*" lodash "*"