added sessions support

This commit is contained in:
David Meincke
2023-05-12 09:44:36 +02:00
parent d3a0bd984e
commit e0c998cfac
13 changed files with 533 additions and 11 deletions
@@ -3,11 +3,14 @@ import './code-editor.less';
import * as monaco from 'monaco-editor';
import { OutputFrame } from "../output-frame/output-frame";
import { debounceManager } from "../../../shared/ensure-debounce";
import * as sessionApi from '../../../shared/session-api';
import { isSessionPage } from "../../../shared/page";
export class CodeEditor extends BaseElement {
public input: string = "";
public language: string = "";
public editor!: monaco.editor.IStandaloneCodeEditor;
onInit(): void {
@@ -18,11 +21,12 @@ export class CodeEditor extends BaseElement {
const prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)");
var editor = monaco.editor.create(this, {
value: this.input,
this.editor = monaco.editor.create(this, {
value: isSessionPage() ? "" : this.input,
language: this.language,
automaticLayout: true,
contextmenu: false,
readOnly: isSessionPage(),
minimap: {
enabled: false
},
@@ -31,19 +35,30 @@ export class CodeEditor extends BaseElement {
});
var debounce = debounceManager(1000);
editor.onDidChangeModelContent((e) => {
this.input = editor.getValue();
debounce.ensureDebounce(() => {
this.outputFrame.setContent(this.language, this.input);
});
this.editor.onDidChangeModelContent((e) => {
if (!isSessionPage()) {
this.input = this.editor.getValue();
debounce.ensureDebounce(() => {
sessionApi.setSessionData(this.language, this.input);
this.outputFrame.setContent(this.language, this.input);
});
}
});
this.waitFor(this.outputFrame, () => {
this.outputFrame.setContent(this.language, this.input);
this.outputFrame.setContent(this.language, isSessionPage() ? "" : this.input);
});
}
setInput(input: any) {
if (this.input !== input) {
this.input = input;
this.editor.setValue(input);
this.outputFrame.setContent(this.language, this.input);
}
}
setInitInput(): string {
return "";
}