Skip to content

Commit

Permalink
readonly compartment
Browse files Browse the repository at this point in the history
  • Loading branch information
JerryI committed Jul 8, 2024
1 parent c594b40 commit 767cfb6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
9 changes: 9 additions & 0 deletions dist/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -72405,6 +72405,8 @@ class CellTypeWidget extends WidgetType {

const languageConf = new Compartment;

const readWriteCompartment = new Compartment;

const extras = [];

if (!window.EditorGlobalExtensions) window.EditorGlobalExtensions = [];
Expand Down Expand Up @@ -72823,6 +72825,7 @@ window.EditorExtensions = [
() => placeholder$8('Type Wolfram Expression / .md / .html / .js'),

(self, initialLang) => languageConf.of(initialLang),
() => readWriteCompartment.of(EditorState.readOnly.of(false)),
() => autoLanguage,

(self, initialLang) => keymap.of([indentWithTab,
Expand Down Expand Up @@ -72917,6 +72920,12 @@ class CodeMirrorCell {
dispose() {
this.editor.destroy();
}

readOnly(state) {
this.editor.dispatch({
effects: readWriteCompartment.reconfigure(EditorState.readOnly.of(state))
});
}

constructor(parent, data) {
this.origin = parent;
Expand Down
2 changes: 1 addition & 1 deletion dist/kernel.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wljs-editor",
"version": "0.9.1",
"version": "0.9.2",
"description": "WLJS Code editor",
"scripts": {
"build": "node --max-old-space-size=8192 ./node_modules/.bin/rollup --config rollup.config.mjs",
Expand Down
9 changes: 9 additions & 0 deletions src/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ import { cellTypesHighlight } from "../libs/priceless-mathematica/src/sugar/cell

const languageConf = new Compartment

const readWriteCompartment = new Compartment

const extras = []

if (!window.EditorGlobalExtensions) window.EditorGlobalExtensions = [];
Expand Down Expand Up @@ -524,6 +526,7 @@ window.EditorExtensions = [
() => placeholder('Type Wolfram Expression / .md / .html / .js'),

(self, initialLang) => languageConf.of(initialLang),
() => readWriteCompartment.of(EditorState.readOnly.of(false)),
() => autoLanguage,

(self, initialLang) => keymap.of([indentWithTab,
Expand Down Expand Up @@ -618,6 +621,12 @@ class CodeMirrorCell {
dispose() {
this.editor.destroy();
}

readOnly(state) {
this.editor.dispatch({
effects: readWriteCompartment.reconfigure(EditorState.readOnly.of(state))
})
}

constructor(parent, data) {
this.origin = parent;
Expand Down

0 comments on commit 767cfb6

Please sign in to comment.