|
|
@ -1,11 +1,11 @@
|
|
|
|
import { Component, ViewChild } from '@angular/core';
|
|
|
|
import {Component, ViewChild} from '@angular/core';
|
|
|
|
import { CodeExecutionService } from 'src/app/services/codeExecution.service';
|
|
|
|
import {CodeExecutionService} from 'src/app/services/codeExecution.service';
|
|
|
|
import { Compartment } from '@codemirror/state';
|
|
|
|
import {Compartment} from '@codemirror/state';
|
|
|
|
import { CodeMirrorComponent } from '@sandkasten/codemirror6-editor';
|
|
|
|
import {CodeMirrorComponent} from '@sandkasten/codemirror6-editor';
|
|
|
|
import { LanguageDescription } from '@codemirror/language';
|
|
|
|
import {LanguageDescription} from '@codemirror/language';
|
|
|
|
import { CODE_DEFAULTS, LANGUAGES } from '../languages';
|
|
|
|
import {CODE_DEFAULTS, LANGUAGES} from '../languages';
|
|
|
|
import { SafeHTMLPipe } from '../../safe-html.pipe';
|
|
|
|
import {SafeHTMLPipe} from '../../safe-html.pipe';
|
|
|
|
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
|
|
|
|
import {ReactiveFormsModule, FormsModule} from '@angular/forms';
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
keymap,
|
|
|
|
keymap,
|
|
|
|
highlightSpecialChars,
|
|
|
|
highlightSpecialChars,
|
|
|
@ -18,7 +18,7 @@ import {
|
|
|
|
highlightActiveLineGutter,
|
|
|
|
highlightActiveLineGutter,
|
|
|
|
gutter,
|
|
|
|
gutter,
|
|
|
|
} from '@codemirror/view';
|
|
|
|
} from '@codemirror/view';
|
|
|
|
import { Extension, EditorState } from '@codemirror/state';
|
|
|
|
import {Extension, EditorState} from '@codemirror/state';
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
defaultHighlightStyle,
|
|
|
|
defaultHighlightStyle,
|
|
|
|
syntaxHighlighting,
|
|
|
|
syntaxHighlighting,
|
|
|
@ -27,15 +27,16 @@ import {
|
|
|
|
foldGutter,
|
|
|
|
foldGutter,
|
|
|
|
foldKeymap,
|
|
|
|
foldKeymap,
|
|
|
|
} from '@codemirror/language';
|
|
|
|
} from '@codemirror/language';
|
|
|
|
import { defaultKeymap, history, historyKeymap } from '@codemirror/commands';
|
|
|
|
import {defaultKeymap, history, historyKeymap} from '@codemirror/commands';
|
|
|
|
import { searchKeymap, highlightSelectionMatches } from '@codemirror/search';
|
|
|
|
import {searchKeymap, highlightSelectionMatches} from '@codemirror/search';
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
autocompletion,
|
|
|
|
autocompletion,
|
|
|
|
completionKeymap,
|
|
|
|
completionKeymap,
|
|
|
|
closeBrackets,
|
|
|
|
closeBrackets,
|
|
|
|
closeBracketsKeymap,
|
|
|
|
closeBracketsKeymap,
|
|
|
|
} from '@codemirror/autocomplete';
|
|
|
|
} from '@codemirror/autocomplete';
|
|
|
|
import { lintKeymap } from '@codemirror/lint';
|
|
|
|
import {lintKeymap} from '@codemirror/lint';
|
|
|
|
|
|
|
|
import {WorksService} from "../../services/works.service";
|
|
|
|
|
|
|
|
|
|
|
|
const basicSetup: Extension = (() => [
|
|
|
|
const basicSetup: Extension = (() => [
|
|
|
|
highlightActiveLineGutter(),
|
|
|
|
highlightActiveLineGutter(),
|
|
|
@ -46,7 +47,7 @@ const basicSetup: Extension = (() => [
|
|
|
|
dropCursor(),
|
|
|
|
dropCursor(),
|
|
|
|
EditorState.allowMultipleSelections.of(true),
|
|
|
|
EditorState.allowMultipleSelections.of(true),
|
|
|
|
indentOnInput(),
|
|
|
|
indentOnInput(),
|
|
|
|
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
|
|
|
|
syntaxHighlighting(defaultHighlightStyle, {fallback: true}),
|
|
|
|
bracketMatching(),
|
|
|
|
bracketMatching(),
|
|
|
|
closeBrackets(),
|
|
|
|
closeBrackets(),
|
|
|
|
autocompletion(),
|
|
|
|
autocompletion(),
|
|
|
@ -88,6 +89,7 @@ export class EditorComponent {
|
|
|
|
get selectedLanguage(): LanguageDescription {
|
|
|
|
get selectedLanguage(): LanguageDescription {
|
|
|
|
return this._selectedLanguage;
|
|
|
|
return this._selectedLanguage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
set selectedLanguage(value: LanguageDescription) {
|
|
|
|
set selectedLanguage(value: LanguageDescription) {
|
|
|
|
this._selectedLanguage = value;
|
|
|
|
this._selectedLanguage = value;
|
|
|
|
if (value.name in CODE_DEFAULTS) {
|
|
|
|
if (value.name in CODE_DEFAULTS) {
|
|
|
@ -100,10 +102,12 @@ export class EditorComponent {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private _linesNumbers: boolean = true;
|
|
|
|
private _linesNumbers: boolean = true;
|
|
|
|
get linesNumbers() {
|
|
|
|
get linesNumbers() {
|
|
|
|
return this._linesNumbers;
|
|
|
|
return this._linesNumbers;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
set linesNumbers(lines: boolean) {
|
|
|
|
set linesNumbers(lines: boolean) {
|
|
|
|
this._linesNumbers = lines;
|
|
|
|
this._linesNumbers = lines;
|
|
|
|
this.codemirror.editor?.dispatch({
|
|
|
|
this.codemirror.editor?.dispatch({
|
|
|
@ -131,7 +135,8 @@ export class EditorComponent {
|
|
|
|
this.languageCompartment.of(this.selectedLanguage.support!),
|
|
|
|
this.languageCompartment.of(this.selectedLanguage.support!),
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
constructor(private codeExecutionService: CodeExecutionService) {}
|
|
|
|
constructor(private codeExecutionService: CodeExecutionService, protected workService: WorksService) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Efface le contenu de l'éditeur
|
|
|
|
// Efface le contenu de l'éditeur
|
|
|
|
clear(): void {
|
|
|
|
clear(): void {
|
|
|
@ -170,10 +175,16 @@ export class EditorComponent {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
saveToFile() {
|
|
|
|
saveToFile() {
|
|
|
|
const blob = new Blob([this.editorContent], { type: 'text/plain' });
|
|
|
|
const blob = new Blob([this.editorContent], {type: 'text/plain'});
|
|
|
|
const a = document.createElement('a');
|
|
|
|
const a = document.createElement('a');
|
|
|
|
a.download = `code.${this.selectedLanguage.extensions![0]}`;
|
|
|
|
a.download = `code.${this.selectedLanguage.extensions![0]}`;
|
|
|
|
a.href = URL.createObjectURL(blob);
|
|
|
|
a.href = URL.createObjectURL(blob);
|
|
|
|
a.click();
|
|
|
|
a.click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addToDatabase() {
|
|
|
|
|
|
|
|
this.workService.postWorkCode(this.editorContent);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected readonly console = console;
|
|
|
|
}
|
|
|
|
}
|
|
|
|