Skip to content

Commit

Permalink
Merge pull request #4962 from dodona-edu/revert-4933-enhance/codemirror
Browse files Browse the repository at this point in the history
Revert "Replace Ace Editor with CodeMirror"
  • Loading branch information
jorg-vr authored Sep 12, 2023
2 parents 857673b + 98c93fe commit 4140bee
Show file tree
Hide file tree
Showing 21 changed files with 1,272 additions and 1,480 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
app/assets/config/manifest.js
app/assets/javascripts/ace_editor.js
app/assets/javascripts/i18n/translations.js
app/assets/javascripts/types/index.d.ts
app/assets/javascripts/inputServiceWorker.js
4 changes: 0 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ updates:
rails:
patterns:
- "@rails*"
codemirror:
patterns:
- "*codemirror*"
- "@lezer*"
- package-ecosystem: github-actions
directory: "/"
schedule:
Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ gem 'builder', '~>3.2.4'
# generate diffs
gem 'diff-lcs', '~>1.5'

# code editor
gem 'ace-rails-ap', '~>4.5'

# auto css prefixer
gem 'autoprefixer-rails', '~>10.4.15'

Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
ace-rails-ap (4.5)
actioncable (7.0.8)
actionpack (= 7.0.8)
activesupport (= 7.0.8)
Expand Down Expand Up @@ -522,6 +523,7 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
ace-rails-ap (~> 4.5)
after_commit_everywhere (~> 1.3.1)
annotate (~> 3.2.0)
autoprefixer-rails (~> 10.4.15)
Expand Down
1 change: 1 addition & 0 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
//= link_tree ../images
//= link ace_editor.js
//= link_tree ../builds
11 changes: 11 additions & 0 deletions app/assets/javascripts/ace_editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This is legacy code that is not compiled by webpack but fully depended on the sprockets pipeline.
// It is used by the ace editor to provide syntax highlighting and code completion.
// New code should not be added here.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//

//= require ace-rails-ap
//= require ace/ext-language_tools

18 changes: 12 additions & 6 deletions app/assets/javascripts/coding_scratchpad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import { Papyros } from "@dodona/papyros";
import { InputMode } from "@dodona/papyros";
import { ProgrammingLanguage } from "@dodona/papyros";
import { themeState } from "state/Theme";
import { EditorView } from "@codemirror/view";
import { setCode } from "editor";

/**
* Custom interface to not have to add the ace package as dependency
*/
interface Editor {
setValue(v: string): void;
getValue(): string;
}

/** Identifiers used in HTML for relevant elements */
const CODE_EDITOR_PARENT_ID = "scratchpad-editor-wrapper";
Expand All @@ -19,7 +25,7 @@ const SUBMIT_TAB_ID = "activity-handin-link";
function initCodingScratchpad(programmingLanguage: ProgrammingLanguage): void {
if (Papyros.supportsProgrammingLanguage(programmingLanguage)) {
let papyros: Papyros | undefined = undefined;
let editor: EditorView | undefined = undefined;
let editor: Editor | undefined = undefined;
const closeButton = document.getElementById(CLOSE_BUTTON_ID);
// To prevent horizontal scrollbar issues, we delay rendering the button
// until after the page is loaded
Expand All @@ -40,14 +46,14 @@ function initCodingScratchpad(programmingLanguage: ProgrammingLanguage): void {
});
editor ||= window.dodona.editor;
if (editor) {
// Shortcut to copy code to editor
// Shortcut to copy code to ACE editor
papyros.addButton(
{
id: CODE_COPY_BUTTON_ID,
buttonText: I18n.t("js.coding_scratchpad.copy_code")
},
() => {
setCode(editor, papyros.getCode());
editor.setValue(papyros.getCode());
closeButton.click();
// Open submit panel if possible
document.getElementById(SUBMIT_TAB_ID)?.click();
Expand Down Expand Up @@ -82,7 +88,7 @@ function initCodingScratchpad(programmingLanguage: ProgrammingLanguage): void {
document.getElementById(OFFCANVAS_ID).addEventListener("shown.bs.offcanvas", () => {
editor ||= window.dodona.editor;
if (editor) { // Start with code from the editor, if there is any
const editorCode = editor.state.doc.toString();
const editorCode = editor.getValue();
const currentCode = papyros.getCode();
if (!currentCode || // Papyros empty
// Neither code areas are empty, but they differ
Expand Down
221 changes: 0 additions & 221 deletions app/assets/javascripts/editor.ts

This file was deleted.

Loading

0 comments on commit 4140bee

Please sign in to comment.