Skip to content

Commit

Permalink
Add support for Emacs.
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanzdosilovic committed Nov 4, 2019
1 parent fae25f8 commit 0b8f132
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
9 changes: 5 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
paths: {
"vs": "https://unpkg.com/monaco-editor/min/vs",
"monaco-vim": "https://unpkg.com/monaco-vim/dist/monaco-vim",
"monaco-emacs": "https://unpkg.com/monaco-emacs/dist/monaco-emacs"
}
};
</script>
<script src="https://unpkg.com/monaco-editor/min/vs/loader.js"></script>
<script src="https://unpkg.com/monaco-editor@0.17.1/min/vs/editor/editor.main.nls.js"></script>
<script src="https://unpkg.com/monaco-editor@0.17.1/min/vs/editor/editor.main.js"></script>
<script src="https://unpkg.com/monaco-editor@0.18.1/min/vs/editor/editor.main.nls.js"></script>
<script src="https://unpkg.com/monaco-editor@0.18.1/min/vs/editor/editor.main.js"></script>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css" integrity="sha256-9mbkOfVho3ZPXfM7W8sV2SndrGDuh7wuyLjtsWeTI1Q=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js" integrity="sha256-t8GepnyPmw9t+foMh3mKNvcorqNHamSKtKRxxpUEgFI=" crossorigin="anonymous"></script>
Expand Down Expand Up @@ -217,12 +218,12 @@ <h2>Judge0 IDE</h2>
<label>Vim</label>
</div>
</div>
<!-- <div class="field">
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="editor-mode" value="emacs">
<label>Emacs</label>
</div>
</div> -->
</div>
</div>
</div>
</div>
Expand Down
29 changes: 24 additions & 5 deletions js/ide.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var editorMode = localStorageGetItem("editorMode") || "normal";
var editorModeObject = null;

var MonacoVim;
var MonacoEmacs;

var layout;

Expand Down Expand Up @@ -399,12 +400,29 @@ function resizeEditor(layoutInfo) {
}
}

function changeEditorMode() {
if (editorMode == "vim" && editorModeObject == null) {
editorModeObject = MonacoVim.initVimMode(sourceEditor, $("#editor-status-line")[0]);
} else if (editorMode == "normal" && editorModeObject != null) {
function disposeEditorModeObject() {
try {
editorModeObject.dispose();
editorModeObject = null;
} catch(ignorable) {
}
}

function changeEditorMode() {
disposeEditorModeObject();

if (editorMode == "vim") {
editorModeObject = MonacoVim.initVimMode(sourceEditor, $("#editor-status-line")[0]);
} else if (editorMode == "emacs") {
var statusNode = $("#editor-status-line")[0];
editorModeObject = new MonacoEmacs.EmacsExtension(sourceEditor);
editorModeObject.onDidMarkChange(function(e) {
statusNode.textContent = e ? "Mark Set!" : "Mark Unset";
});
editorModeObject.onDidChangeKey(function(str) {
statusNode.textContent = str;
});
editorModeObject.start();
}
}

Expand Down Expand Up @@ -492,10 +510,11 @@ $(document).ready(function () {

showApiUrl();

require(["vs/editor/editor.main", "monaco-vim"], function (ignorable, MVim) {
require(["vs/editor/editor.main", "monaco-vim", "monaco-emacs"], function (ignorable, MVim, MEmacs) {
layout = new GoldenLayout(layoutConfig, $("#site-content"));

MonacoVim = MVim;
MonacoEmacs = MEmacs;

layout.registerComponent("source", function (container, state) {
sourceEditor = monaco.editor.create(container.getElement()[0], {
Expand Down

0 comments on commit 0b8f132

Please sign in to comment.