Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/lib/acode.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import fsOperation from "fileSystem";
import sidebarApps from "sidebarApps";
import * as cmAutocomplete from "@codemirror/autocomplete";
import * as cmCommands from "@codemirror/commands";
import * as cmLanguage from "@codemirror/language";
import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
import * as cmLint from "@codemirror/lint";
import * as cmSearch from "@codemirror/search";
import * as cmState from "@codemirror/state";
import { Compartment, EditorState, Prec, StateEffect } from "@codemirror/state";
import * as cmView from "@codemirror/view";
import { EditorView } from "@codemirror/view";
Comment thread
bajrangCoder marked this conversation as resolved.
Outdated
import ajax from "@deadlyjack/ajax";
import { tags } from "@lezer/highlight";
Expand Down Expand Up @@ -314,6 +321,16 @@ export default class Acode {
},
};

const codemirrorModule = Object.freeze({
autocomplete: cmAutocomplete,
commands: cmCommands,
language: cmLanguage,
lint: cmLint,
search: cmSearch,
state: cmState,
view: cmView,
});

this.define("Url", Url);
this.define("page", Page);
this.define("Color", Color);
Expand Down Expand Up @@ -356,6 +373,14 @@ export default class Acode {
this.define("selectionMenu", selectionMenu);
this.define("sidebarApps", sidebarAppsModule);
this.define("terminal", terminalModule);
this.define("codemirror", codemirrorModule);
this.define("@codemirror/autocomplete", cmAutocomplete);
this.define("@codemirror/commands", cmCommands);
this.define("@codemirror/language", cmLanguage);
this.define("@codemirror/lint", cmLint);
this.define("@codemirror/search", cmSearch);
this.define("@codemirror/state", cmState);
this.define("@codemirror/view", cmView);
Comment thread
bajrangCoder marked this conversation as resolved.
this.define("createKeyboardEvent", KeyboardEvent);
this.define("toInternalUrl", helpers.toInternalUri);
this.define("commands", this.#createCommandApi());
Expand Down
27 changes: 27 additions & 0 deletions src/test/editor.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,33 @@ export async function runCodeMirrorTests(writeOutput) {
);
});

runner.test("Acode exposes shared CodeMirror modules", async (test) => {
const codemirror = acode.require("codemirror");
const language = acode.require("@codemirror/language");
const state = acode.require("@codemirror/state");
const view = acode.require("@codemirror/view");

test.assert(codemirror != null, "codemirror namespace should exist");
test.assert(language != null, "@codemirror/language should exist");
test.assert(state != null, "@codemirror/state should exist");
test.assert(view != null, "@codemirror/view should exist");
test.assertEqual(
language.StreamLanguage,
codemirror.language.StreamLanguage,
"language exports should share the same singleton instance",
);
test.assertEqual(
state.EditorState,
codemirror.state.EditorState,
"state exports should share the same singleton instance",
);
test.assertEqual(
view.EditorView,
codemirror.view.EditorView,
"view exports should share the same singleton instance",
);
Comment thread
bajrangCoder marked this conversation as resolved.
});
Comment thread
bajrangCoder marked this conversation as resolved.

runner.test("Editor creation", async (test) => {
const { view, container } = createEditor();
test.assert(view != null, "EditorView instance should be created");
Expand Down