Skip to content

Commit

Permalink
🧹 Remove ace death code (#5364)
Browse files Browse the repository at this point in the history
Fixes #4941
  • Loading branch information
Annelein authored Apr 3, 2024
1 parent 7350174 commit 09ae9e5
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 1,075 deletions.
441 changes: 0 additions & 441 deletions static/js/ace-editor.ts

This file was deleted.

242 changes: 3 additions & 239 deletions static/js/appbundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -97016,235 +97016,6 @@ def note_with_error(value, err):
}
}

// static/js/ace-editor.ts
var MOVE_CURSOR_TO_END = 1;
var BP_DISABLED_LINE = "ace_breakpoint";
var HedyAceEditor = class {
constructor(element, isReadOnly, editorType, dir = "ltr") {
this.editorEvent = new EventEmitter({
change: true,
guttermousedown: true,
changeBreakpoint: true,
click: true
});
this.markerClasses = new Map();
this.strikeMarkers = new Map();
this._editor = ace.edit(element);
this.isReadOnly = isReadOnly;
this._editor.setTheme("ace/theme/monokai");
if (isReadOnly) {
this._editor.setValue(this._editor.getValue().trimRight(), -1);
this._editor.renderer.$cursorLayer.element.style.display = "none";
this._editor.setOptions({
readOnly: editorType === EditorType.MAIN,
showGutter: false,
showPrintMargin: false,
highlightActiveLine: false
});
this._editor.renderer.setScrollMargin(3, 3, 10, 20);
this._editor.setOptions({ maxLines: Infinity });
if (editorType === EditorType.CHEATSHEET) {
this._editor.setOptions({ minLines: 1 });
} else if (editorType === EditorType.COMMON_MISTAKES) {
this._editor.setOptions({
showGutter: true,
showPrintMargin: true,
highlightActiveLine: true,
minLines: 5
});
} else if (editorType === EditorType.PARSONS) {
this._editor.setOptions({
minLines: 1,
showGutter: false,
showPrintMargin: false,
highlightActiveLine: false
});
} else if (editorType === EditorType.EXAMPLE) {
this._editor.setOptions({ minLines: 2 });
}
} else {
if (editorType === EditorType.MAIN) {
this._editor.setShowPrintMargin(false);
this._editor.renderer.setScrollMargin(0, 0, 0, 20);
}
}
if (theLevel) {
this.setHighlighterForLevel(theLevel);
}
if (dir === "rtl") {
this._editor.setOptions({ rtl: true });
}
}
setHighlighterForLevel(level3) {
const mode = this.getHighlighter(level3);
this._editor.session.setMode(mode);
}
get contents() {
return this._editor.getValue();
}
set contents(content2) {
this._editor.setValue(content2, MOVE_CURSOR_TO_END);
}
get isReadOnly() {
return this._editor.getReadOnly();
}
set isReadOnly(isReadMode) {
this._editor.setReadOnly(isReadMode);
}
resize() {
console.warn("Oops! editor.resize() should not have been called anymore");
this._editor.resize();
}
focus() {
this._editor.focus();
}
clearErrors() {
this._editor.session.clearAnnotations();
for (const marker of this.findMarkers("editor-error")) {
this.removeMarker(marker);
}
}
moveCursorToEndOfFile() {
this._editor.navigateFileEnd();
}
clearSelection() {
this._editor.clearSelection();
}
clearBreakpoints() {
this._editor.session.clearBreakpoints();
}
getDeactivatedLines() {
return this._editor.session.getBreakpoints();
}
getHighlighter(level3) {
return `ace/mode/level${level3}`;
}
trimTrailingSpace() {
try {
const whitespace = ace.require("ace/ext/whitespace");
whitespace.trimTrailingSpace(this._editor.session, true);
} catch (e) {
console.error(e);
}
}
on(key, handler2) {
const ret = this.editorEvent.on(key, handler2);
if (key == "changeBreakpoint") {
this._editor.session.on(key, handler2);
} else {
this._editor.addEventListener(key, handler2);
}
return ret;
}
highlightError(row, col) {
if (col === void 0) {
this.addMarker(new ace.Range(row - 1, 1, row - 1, 2), "editor-error", "fullLine");
return;
}
const length = this._editor.session.getLine(row - 1).slice(col - 1).split(/(\s+)/)[0].length;
if (length > 0) {
this.addMarker(new ace.Range(row - 1, col - 1, row - 1, col - 1 + length), "editor-error", "text");
} else {
this.addMarker(new ace.Range(row - 1, 1, row - 1, 2), "editor-error", "fullLine");
}
}
setIncorrectLine(range10, lineIndex) {
const aceRange = new ace.Range(range10.startLine - 1, range10.startColumn - 1, range10.endLine - 1, range10.endColumn - 1);
this.addMarker(aceRange, `ace_incorrect_hedy_code_${lineIndex}`, "text", true);
}
clearIncorrectLines() {
const markers = this._editor.session.getMarkers(true);
if (markers) {
for (const index3 in markers) {
let marker = markers[index3];
if (marker.clazz.includes("ace_incorrect_hedy_code")) {
this.removeMarker(Number(index3));
}
}
}
}
setDebuggerCurrentLine(line, startPos, finishPos) {
if (this.currentLineMarker) {
this.removeMarker(this.currentLineMarker.id);
}
if (line === void 0) {
this.currentLineMarker = void 0;
return;
}
line = line - 1;
let id2;
if (startPos === void 0 || finishPos === void 0) {
id2 = this.addMarker(new ace.Range(line, 0, line, 999), "debugger-current-line", "fullLine");
} else {
id2 = this.addMarker(new ace.Range(line, startPos - 1, line, finishPos - 1), "debugger-current-line", "text");
}
this.currentLineMarker = { line, id: id2 };
}
strikethroughLines(lines) {
const struckLines = new Set(lines);
const noLongerStruck = Array.from(this.strikeMarkers.entries()).filter(([line, _]) => !struckLines.has(line));
for (const [line, id2] of noLongerStruck) {
this.removeMarker(id2);
this.strikeMarkers.delete(line);
}
const newlyStruck = lines.filter((line) => !this.strikeMarkers.has(line));
for (const line of newlyStruck) {
const id2 = this.addMarker(new ace.Range(line, 0, line, 999), "disabled-line", "text", true);
this.strikeMarkers.set(line, id2);
}
}
addMarker(range10, klass, scope, inFront = false) {
const id2 = this._editor.session.addMarker(range10, klass, scope, inFront);
this.markerClasses.set(id2, klass);
return id2;
}
removeMarker(id2) {
this._editor.session.removeMarker(id2);
this.markerClasses.delete(id2);
}
findMarkers(klass) {
return Array.from(this.markerClasses.entries()).filter(([_, k]) => k === klass).map(([id2, _]) => id2);
}
getActiveContents(debugLine2) {
let code = this._editor.session.getValue();
const breakpoints = this.getDeactivatedLines();
if (code) {
let lines = code.split("\n");
if (debugLine2 != null) {
lines = lines.slice(0, parseInt(debugLine2) + 1);
}
for (let i = 0; i < lines.length; i++) {
if (breakpoints[i] == BP_DISABLED_LINE) {
lines[i] = "";
}
}
code = lines.join("\n");
}
return code;
}
skipFaultyHandler() {
$(document).on("click", "div[class*=ace_content], div[class*=ace_incorrect_hedy_code]", function(e) {
let className = e.target.className;
if ($("div[class*=ace_incorrect_hedy_code]")[0]) {
if (className === "ace_content") {
$("#okbox").hide();
$("#warningbox").hide();
$("#errorbox").hide();
} else {
let mapIndex = className;
mapIndex = mapIndex.replace("ace_incorrect_hedy_code_", "");
mapIndex = mapIndex.replace("ace_start ace_br15", "");
let mapError = theGlobalSourcemap[Number(mapIndex)];
$("#okbox").hide();
$("#warningbox").hide();
$("#errorbox").hide();
error.show(ClientMessages["Transpile_error"], mapError.error);
}
}
});
}
};

// static/js/debugging.ts
var theGlobalEditor2;
var theLevel2;
Expand Down Expand Up @@ -97348,7 +97119,7 @@ def note_with_error(value, err):
function unfixReserved(name2) {
return name2.replace(/_\$rw\$$/, "");
}
var BP_DISABLED_LINE2 = "ace_breakpoint";
var BP_DISABLED_LINE = "ace_breakpoint";
function initializeDebugger(options) {
theGlobalEditor2 = options.editor;
theLevel2 = options.level;
Expand Down Expand Up @@ -97397,23 +97168,16 @@ def note_with_error(value, err):
}
}
for (let i = highest_key; i <= row; i++) {
e.editor.session.setBreakpoint(i, BP_DISABLED_LINE2);
e.editor.session.setBreakpoint(i, BP_DISABLED_LINE);
}
} else {
e.editor.session.setBreakpoint(row, BP_DISABLED_LINE2);
e.editor.session.setBreakpoint(row, BP_DISABLED_LINE);
}
} else {
e.editor.session.clearBreakpoint(row);
}
e.stop();
});
editor.on("changeBreakpoint", function() {
if (theGlobalEditor2 instanceof HedyAceEditor) {
const breakpoints = theGlobalEditor2.getDeactivatedLines();
const disabledLines = Object.entries(breakpoints).filter(([_, bpClass]) => bpClass === BP_DISABLED_LINE2).map(([line, _]) => line).map((x) => parseInt(x, 10));
theGlobalEditor2.strikethroughLines(disabledLines);
}
});
}
function get_shift_key(event2) {
if (event2.shiftKey) {
Expand Down
6 changes: 3 additions & 3 deletions static/js/appbundle.js.map

Large diffs are not rendered by default.

18 changes: 0 additions & 18 deletions static/js/debugging.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { HedyAceEditor } from "./ace-editor";
import { runit, theGlobalDebugger,theGlobalSourcemap } from "./app";
import { HedyEditor, Breakpoints } from "./editor";
import TRADUCTION_IMPORT from '../../highlighting/highlighting-trad.json'
Expand Down Expand Up @@ -226,23 +225,6 @@ function initializeBreakpoints(editor: HedyEditor) {
}
e.stop();
});

/**
* Render markers for all lines that have breakpoints
*
* (Breakpoints mean "disabled lines" in Hedy).
* */
editor.on('changeBreakpoint', function() {
if (theGlobalEditor instanceof HedyAceEditor) {
const breakpoints = theGlobalEditor.getDeactivatedLines();
const disabledLines = Object.entries(breakpoints)
.filter(([_, bpClass]) => bpClass === BP_DISABLED_LINE)
.map(([line, _]) => line)
.map(x => parseInt(x, 10));

theGlobalEditor.strikethroughLines(disabledLines);
}
});
}

function get_shift_key(event: Event | undefined) {
Expand Down
17 changes: 0 additions & 17 deletions static/vendor/ace.js

This file was deleted.

8 changes: 0 additions & 8 deletions static/vendor/ext-rtl.js

This file was deleted.

Loading

0 comments on commit 09ae9e5

Please sign in to comment.