Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4403341

Browse files
authored
Merge pull request #4 from Max-Leopold/Max-Leopold/Add-monaco-editor-support
Use Monaco editor instead of CodeMirror
2 parents 571aca2 + 816538c commit 4403341

File tree

7 files changed

+27
-47
lines changed

7 files changed

+27
-47
lines changed

Gemfile.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ GEM
55
syntax_tree (2.3.1)
66

77
PLATFORMS
8+
ruby
89
x86_64-darwin-21
910
x86_64-linux
1011

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
"dependencies": {
88
"@wasmer/wasi": "^0.12.0",
99
"@wasmer/wasmfs": "^0.12.0",
10-
"codemirror": "^5.65.3",
10+
"@monaco-editor/loader": "^1.3.2",
1111
"path-browserify": "^1.0.1",
1212
"ruby-head-wasm-wasi": "^0.3.0"
1313
},
1414
"devDependencies": {
15-
"@types/codemirror": "^5.60.5",
1615
"@types/node": "^17.0.27",
1716
"@types/path-browserify": "^1.0.0",
1817
"esbuild": "^0.14.38"

src/CodeMirror.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/index.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,3 @@ textarea {
4848
resize: none;
4949
white-space: pre;
5050
}
51-
52-
.CodeMirror {
53-
height: 100% !important;
54-
}

src/index.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ Promise.all([
77
// We're going to load the editor asynchronously so that we can get to
88
// first-paint faster. This works out nicely since we can use a textarea until
99
// this chunk is loaded.
10-
import("./CodeMirror").then(({ default: CodeMirror }) => {
10+
import("./monacoLoader").then(async ({ default: loader }) => {
11+
const monaco = await loader.init();
1112
const editor = document.getElementById("editor") as HTMLTextAreaElement;
1213
const newEditor = document.createElement("div");
1314
editor.replaceWith(newEditor);
14-
15-
return CodeMirror(newEditor, {
16-
lineNumbers: true,
17-
mode: "ruby",
18-
theme: "xq-light",
19-
value: editor.value
15+
16+
return monaco.editor.create(
17+
newEditor, {
18+
value: editor.value,
19+
language: 'ruby',
2020
});
2121
}),
2222
// We're going to load the Ruby VM chunk asynchronously because it is pretty
@@ -27,7 +27,7 @@ Promise.all([
2727
// First, grab a reference to the output element so that we can update it.
2828
// Then, set it initially to the output represented by the source.
2929
const output = document.getElementById("output") as HTMLTextAreaElement;
30-
output.value = ruby.prettyPrint(editor.getDoc().getValue());
30+
output.value = ruby.prettyPrint(editor.getValue());
3131
output.disabled = false;
3232

3333
// This is the function that will be used to display the output from the
@@ -39,7 +39,7 @@ Promise.all([
3939
displayFunction = ruby[event.detail.kind];
4040

4141
try {
42-
output.value = displayFunction(editor.getDoc().getValue());
42+
output.value = displayFunction(editor.getValue());
4343
} catch (error) {
4444
// For now, just ignoring the error. Eventually I'd like to make this mark
4545
// an error state on the editor to give feedback to the user.
@@ -78,9 +78,9 @@ Promise.all([
7878

7979
// Attach to the editor and dispatch custom source-changed events whenever the
8080
// value is updated in the editor.
81-
editor.on("change", () => {
81+
editor.onDidChangeModelContent(() => {
8282
output.dispatchEvent(new CustomEvent<SourceChangedEvent>("source-changed", {
83-
detail: { source: editor.getDoc().getValue() }
83+
detail: { source: editor.getValue() }
8484
}));
8585
});
8686

@@ -90,6 +90,6 @@ Promise.all([
9090
format.disabled = false;
9191

9292
format.addEventListener("click", () => {
93-
editor.getDoc().setValue(ruby.format(editor.getValue()));
93+
editor.setValue(ruby.format(editor.getValue()));
9494
});
9595
});

src/monacoLoader.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import loader from '@monaco-editor/loader';
2+
3+
export default loader

yarn.lock

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@
22
# yarn lockfile v1
33

44

5-
"@types/codemirror@^5.60.5":
6-
version "5.60.5"
7-
resolved "https://registry.yarnpkg.com/@types/codemirror/-/codemirror-5.60.5.tgz#5b989a3b4bbe657458cf372c92b6bfda6061a2b7"
8-
integrity sha512-TiECZmm8St5YxjFUp64LK0c8WU5bxMDt9YaAek1UqUb9swrSCoJhh92fWu1p3mTEqlHjhB5sY7OFBhWroJXZVg==
5+
"@monaco-editor/loader@^1.3.2":
6+
version "1.3.2"
7+
resolved "https://registry.yarnpkg.com/@monaco-editor/loader/-/loader-1.3.2.tgz#04effbb87052d19cd7d3c9d81c0635490f9bb6d8"
8+
integrity sha512-BTDbpHl3e47r3AAtpfVFTlAi7WXv4UQ/xZmz8atKl4q7epQV5e7+JbigFDViWF71VBi4IIBdcWP57Hj+OWuc9g==
99
dependencies:
10-
"@types/tern" "*"
11-
12-
"@types/estree@*":
13-
version "0.0.51"
14-
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.51.tgz#cfd70924a25a3fd32b218e5e420e6897e1ac4f40"
15-
integrity sha512-CuPgU6f3eT/XgKKPqKd/gLZV1Xmvf1a2R5POBOGQa6uv82xpls89HU5zKeVoyR8XzHd1RGNOlQlvUe3CFkjWNQ==
10+
state-local "^1.0.6"
1611

1712
"@types/node@^17.0.27":
1813
version "17.0.27"
@@ -24,13 +19,6 @@
2419
resolved "https://registry.yarnpkg.com/@types/path-browserify/-/path-browserify-1.0.0.tgz#294ec6e88b6b0d340a3897b7120e5b393f16690e"
2520
integrity sha512-XMCcyhSvxcch8b7rZAtFAaierBYdeHXVvg2iYnxOV0MCQHmPuRRmGZPFDRzPayxcGiiSL1Te9UIO+f3cuj0tfw==
2621

27-
"@types/tern@*":
28-
version "0.23.4"
29-
resolved "https://registry.yarnpkg.com/@types/tern/-/tern-0.23.4.tgz#03926eb13dbeaf3ae0d390caf706b2643a0127fb"
30-
integrity sha512-JAUw1iXGO1qaWwEOzxTKJZ/5JxVeON9kvGZ/osgZaJImBnyjyn0cjovPsf6FNLmyGY8Vw9DoXZCMlfMkMwHRWg==
31-
dependencies:
32-
"@types/estree" "*"
33-
3422
"@wasmer/wasi@^0.12.0":
3523
version "0.12.0"
3624
resolved "https://registry.yarnpkg.com/@wasmer/wasi/-/wasi-0.12.0.tgz#89c7c5e5ba58f7dfae4e323359346639c4ec382a"
@@ -82,11 +70,6 @@ buffer@^5.5.0:
8270
base64-js "^1.3.1"
8371
ieee754 "^1.1.13"
8472

85-
codemirror@^5.65.3:
86-
version "5.65.3"
87-
resolved "https://registry.yarnpkg.com/codemirror/-/codemirror-5.65.3.tgz#2d029930d5a293bc5fb96ceea64654803c0d4ac7"
88-
integrity sha512-kCC0iwGZOVZXHEKW3NDTObvM7pTIyowjty4BUqeREROc/3I6bWbgZDA3fGDwlA+rbgRjvnRnfqs9SfXynel1AQ==
89-
9073
end-of-stream@^1.4.1:
9174
version "1.4.4"
9275
resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0"
@@ -304,6 +287,11 @@ safe-buffer@^5.1.0, safe-buffer@~5.2.0:
304287
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
305288
integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==
306289

290+
state-local@^1.0.6:
291+
version "1.0.7"
292+
resolved "https://registry.yarnpkg.com/state-local/-/state-local-1.0.7.tgz#da50211d07f05748d53009bee46307a37db386d5"
293+
integrity sha512-HTEHMNieakEnoe33shBYcZ7NX83ACUjCu8c40iOGEZsngj9zRnkqS9j1pqQPXwobB0ZcVTk27REb7COQ0UR59w==
294+
307295
string_decoder@^1.1.1:
308296
version "1.3.0"
309297
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e"

0 commit comments

Comments
 (0)