Skip to content

Commit 00f0a7a

Browse files
committed
Revert "feat: Lua syntax highlighting in Settings → Scripts editor"
This reverts commit faf9cac.
1 parent a67cfe2 commit 00f0a7a

4 files changed

Lines changed: 31 additions & 80 deletions

File tree

src/app/components/controls/codejar-wrapper/codejar-wrapper.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{{ errorMessage }}
44
</div>
55
<ngx-codejar
6-
[highlightMethod]="resolvedHighlighter"
6+
[highlightMethod]="mode ? highlightMethod : highlightMethodJSON"
77
[code]="code"
88
(codeChange)="onChangeCode($event)"
99
[showLineNumbers]="false"

src/app/components/controls/codejar-wrapper/codejar-wrapper.component.ts

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
Component, EventEmitter, Input, OnInit, Output, AfterViewInit,
44
ChangeDetectionStrategy, ChangeDetectorRef, ViewChild, HostListener
55
} from '@angular/core';
6-
import { CodeJarContainer, NgxCodeJarComponent } from 'ngx-codejar';
6+
import { CodeJarContainer } from 'ngx-codejar';
77

88
@Component({
99
selector: 'app-codejar-wrapper',
@@ -21,18 +21,7 @@ export class CodeJarWrapperComponent implements OnInit, AfterViewInit {
2121
return this.code;
2222
}
2323
@Output() textChange = new EventEmitter<string>();
24-
private _mode: string;
25-
@Input()
26-
set mode(value: string) {
27-
const prev = this._mode;
28-
this._mode = value;
29-
if (prev !== undefined && prev !== value) {
30-
requestAnimationFrame(() => this.refreshHighlight());
31-
}
32-
}
33-
get mode(): string {
34-
return this._mode;
35-
}
24+
@Input() mode: string;
3625
@Input() jsonValidator: boolean = false;
3726
@Input() theme = 'monokai';
3827
_readOnly = false;
@@ -61,7 +50,6 @@ export class CodeJarWrapperComponent implements OnInit, AfterViewInit {
6150
isReadyToShow = false;
6251

6352
@ViewChild('codejar') codejar: any;
64-
@ViewChild(NgxCodeJarComponent) private ngxCodeJar: NgxCodeJarComponent;
6553

6654
constructor(private cdr: ChangeDetectorRef) {
6755
}
@@ -84,27 +72,6 @@ export class CodeJarWrapperComponent implements OnInit, AfterViewInit {
8472
editor.innerHTML = hljs.highlight(editor.textContent, { language: 'javascript' }).value;
8573
}
8674
}
87-
resolvedHighlighter = (editor: CodeJarContainer) => {
88-
if (editor.textContent === null || editor.textContent === undefined) {
89-
return;
90-
}
91-
let language: string;
92-
switch ((this.mode || '').toLowerCase()) {
93-
case 'lua':
94-
language = 'lua';
95-
break;
96-
case 'json':
97-
language = 'json';
98-
break;
99-
case 'javascript':
100-
case 'js':
101-
language = 'javascript';
102-
break;
103-
default:
104-
language = this.mode ? 'javascript' : 'json';
105-
}
106-
editor.innerHTML = hljs.highlight(editor.textContent, { language }).value;
107-
}
10875

10976
ngAfterViewInit(): void {
11077

@@ -126,13 +93,6 @@ export class CodeJarWrapperComponent implements OnInit, AfterViewInit {
12693
this.editor?.updateOptions({ readOnly: this._readOnly });
12794
console.log(line);
12895
}
129-
refreshHighlight() {
130-
if (!this.ngxCodeJar) {
131-
return;
132-
}
133-
this.ngxCodeJar.updateCode(this.code ?? '');
134-
requestAnimationFrame(() => this.cdr.detectChanges());
135-
}
13696
onChangeCode(event: any) {
13797
this.code = event;
13898
if (this.jsonValidator) {

src/app/components/preference/dialogs/dialog-scripts/dialog-scripts.component.html

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,32 +112,23 @@
112112
<mat-tab [label]="'preference.scripts.dialog.jsScripts' | translate">
113113
<hr />
114114

115-
<p style="display:flex; align-items:center; justify-content:space-between;">
115+
<p>
116116
<strong>{{ 'preference.scripts.dialog.jsScripts' | translate }}</strong>
117-
<span>
118-
<mat-button-toggle-group [value]="editorMode"
119-
(change)="setEditorMode($event.value)"
120-
aria-label="Script language">
121-
<mat-button-toggle value="javascript">JavaScript</mat-button-toggle>
122-
<mat-button-toggle value="lua">Lua</mat-button-toggle>
123-
</mat-button-toggle-group>
124-
</span>
125117
</p>
126118
<small>{{ 'preference.scripts.dialog.jsScriptsDescription' | translate }}</small>
127119
<hr />
128120
<full-screen (fullPage)='disableClose($event)'
129121
(import)='import($event)'
130-
[data]='{json:data.data.data, title: "Script " + data.data.hep_alias + " " + data.data.profile, type: editorMode}'>
131-
<app-codejar-wrapper
132-
[mode]="editorMode"
122+
[data]='{json:data.data.data, title: "Script " + data.data.hep_alias + " " + data.data.profile, type: "js"}'>
123+
<ace-editor [mode]="'javascript'"
133124
[theme]="'monokai'"
134-
[readOnly]="!isAdmin"
125+
[readOnly]="false"
135126
[(text)]="data.data.data"
136127
#data_view
137128
[style.min-height.%]="100"
138-
style="padding: 5px; display:block; min-height: 400px;"
129+
style="padding: 5px"
139130
[disabled]="!isAdmin"
140-
></app-codejar-wrapper>
131+
></ace-editor>
141132
</full-screen>
142133
</mat-tab>
143134
</mat-tab-group>

src/app/components/preference/dialogs/dialog-scripts/dialog-scripts.component.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Component, Inject, ChangeDetectionStrategy, ViewChild, AfterViewInit, ChangeDetectorRef } from '@angular/core';
22
import { FormControl, Validators } from '@angular/forms';
33
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
4+
// import 'brace';
5+
// import 'brace/mode/text';
6+
// import 'brace/theme/github';
47
import { TranslateService } from '@ngx-translate/core'
5-
6-
const LUA_TYPES = new Set(['correlation', 'lua']);
7-
88
@Component({
99
selector: 'app-dialog-scripts',
1010
templateUrl: './dialog-scripts.component.html',
@@ -17,7 +17,6 @@ export class DialogScriptsComponent implements AfterViewInit {
1717
isAdmin = false;
1818
regNum = /^[0-9]+$/;
1919
regString = /^[a-zA-Z0-9\-\_]+$/;
20-
editorMode: 'lua' | 'javascript' = 'javascript';
2120

2221
@ViewChild('data_view', { static: false }) editor;
2322
partid = new FormControl('', [
@@ -87,27 +86,28 @@ export class DialogScriptsComponent implements AfterViewInit {
8786
this.profile.setValue(d.profile);
8887
this.type.setValue(d.type);
8988
})(data.data);
90-
this.editorMode = this.resolveEditorMode(data.data?.type);
91-
this.type.valueChanges.subscribe(val => {
92-
const next = this.resolveEditorMode(val);
93-
if (next !== this.editorMode) {
94-
this.editorMode = next;
95-
this.cdr.detectChanges();
96-
}
97-
});
9889
this.isValidForm = true;
90+
// const test = this.editor.getEditor().getSession().getAnnotations().filter(annotation => annotation.raw !== `['{a}'] is better written in dot notation.`);
91+
9992
}
10093
ngAfterViewInit() {
101-
this.cdr.detectChanges();
102-
}
103-
private resolveEditorMode(t: string | null | undefined): 'lua' | 'javascript' {
104-
if (typeof t === 'string' && LUA_TYPES.has(t.toLowerCase())) {
105-
return 'lua';
106-
}
107-
return 'javascript';
108-
}
109-
setEditorMode(mode: 'lua' | 'javascript') {
110-
this.editorMode = mode;
94+
const options = {
95+
esnext: true,
96+
moz: true,
97+
devel: true,
98+
browser: true,
99+
node: true,
100+
laxcomma: true,
101+
laxbreak: true,
102+
lastsemic: true,
103+
onevar: false,
104+
passfail: false,
105+
maxerr: 10000,
106+
expr: true,
107+
multistr: true,
108+
globalstrict: true
109+
};
110+
this.editor.getEditor().getSession().$worker.call("setOptions", [options]);
111111
this.cdr.detectChanges();
112112
}
113113
disableClose(e) {

0 commit comments

Comments
 (0)