Add support for self-modifying programs to core
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import monaco from "monaco-editor";
|
||||
import { DocumentRange } from "../../engines/types";
|
||||
import { DocumentEdit, DocumentRange } from "../../engines/types";
|
||||
import { WorkerParseError } from "../../engines/worker-errors";
|
||||
|
||||
/** Type alias for an instance of Monaco editor */
|
||||
@@ -60,6 +60,26 @@ export const createValidationMarker = (
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a DocumentEdit instance to Monaco edit object format.
|
||||
* @param edit DocumentEdit to convert to Monaco format
|
||||
* @returns Instance of Monaco's edit object
|
||||
*/
|
||||
export const createMonacoDocEdit = (
|
||||
edit: DocumentEdit
|
||||
): monaco.editor.IIdentifiedSingleEditOperation => {
|
||||
const location = get1IndexedLocation(edit.range);
|
||||
return {
|
||||
text: edit.text,
|
||||
range: {
|
||||
startLineNumber: location.line,
|
||||
endLineNumber: location.line,
|
||||
startColumn: location.charRange?.start || 0,
|
||||
endColumn: location.charRange?.end || 1000,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a DocumentRange to use 1-indexed values. Used since language engines
|
||||
* use 0-indexed ranges but Monaco requires 1-indexed ranges.
|
||||
|
||||
Reference in New Issue
Block a user