Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply dodona theme to papyros #5221

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 7 additions & 4 deletions app/assets/javascripts/coding_scratchpad.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Papyros } from "@dodona/papyros";
import { InputMode } from "@dodona/papyros";
import { ProgrammingLanguage } from "@dodona/papyros";
import { CodeEditor, InputMode, Papyros, ProgrammingLanguage } from "@dodona/papyros";

Check warning on line 1 in app/assets/javascripts/coding_scratchpad.ts

View check run for this annotation

Codecov / codecov/patch

app/assets/javascripts/coding_scratchpad.ts#L1

Added line #L1 was not covered by tests
import { themeState } from "state/Theme";
import { EditorView } from "@codemirror/view";
import { setCode } from "editor";
import { rougeStyle, setCode } from "editor";
import { syntaxHighlighting } from "@codemirror/language";

Check warning on line 5 in app/assets/javascripts/coding_scratchpad.ts

View check run for this annotation

Codecov / codecov/patch

app/assets/javascripts/coding_scratchpad.ts#L4-L5

Added lines #L4 - L5 were not covered by tests

/** Identifiers used in HTML for relevant elements */
const CODE_EDITOR_PARENT_ID = "scratchpad-editor-wrapper";
Expand Down Expand Up @@ -76,6 +75,10 @@
darkMode: themeState.theme === "dark"
});
await papyros.launch();

papyros.codeRunner.editor.reconfigure([CodeEditor.STYLE, syntaxHighlighting(rougeStyle, {
fallback: true
})]);
}
});
// Ask user to choose after offcanvas is shown
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ declare type EditorEventHandler = (event: FocusEvent, view: EditorView) => boole

// A custom theme for CodeMirror that applies the same CSS as Rouge does,
// meaning we can use our existing themes.
const rougeStyle = HighlightStyle.define([
export const rougeStyle = HighlightStyle.define([
{ tag: tags.comment, class: "c" },
{ tag: tags.lineComment, class: "c" },
{ tag: tags.blockComment, class: "cm" },
Expand Down
30 changes: 30 additions & 0 deletions app/assets/stylesheets/components/scratchpad.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
// Wrapper around editor provides margin
#scratchpad-editor-wrapper {
margin-bottom: 20px;

:focus-visible {
outline: none;
}
}

// Wrapper and its child should take up as much space as possible
Expand Down Expand Up @@ -86,3 +90,29 @@
#scratchpad-offcanvas.show {
@include shadow-z3;
}

/* stylelint-disable selector-class-pattern */
.tailwind ._tw-border-gray-200 {
border-color: var(--d-divider) !important;
}

.tailwind :is(._tw-dark .dark\:_tw-border-dark-mode-content) {
border-color: var(--d-divider) !important;
}

.tailwind * {
border-color: var(--d-divider) !important;
}
/* stylelint-enable selector-class-pattern */

/* stylelint-disable selector-id-pattern */
#__papyros-code-input-area {
background-color: var(--d-code-bg) !important;
color: var(--d-on-background);
caret-color: var(--d-secondary);
}
/* stylelint-enable selector-id-pattern */

#scratchpad-panel-wrapper {
border-bottom: 0 !important;
}
31 changes: 29 additions & 2 deletions app/assets/stylesheets/theme/codemirror.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
background: var(--d-surface-variant) !important;
}

.cm-cursor {
.cm-cursor, .cm-dropCursor {
// Sets the color of the cursor.
border-left: 1.2px solid var(--d-secondary);
border-left: 1.2px solid var(--d-secondary) !important;
}

.cm-tooltip {
Expand All @@ -41,5 +41,32 @@
color: var(--d-on-secondary) !important;
}
}

.cm-panels {
background-color: var(--d-background);
color: var(--d-on-background);

&.cm-panels-top {
border-bottom: 2px solid var(--d-divider);
}

&.cm-panels-bottom {
border-top: 2px solid var(--d-divider);
}
}

.cm-searchMatch {
background-color: rgba(var(--d-secondary-rgb), 0.3);
}

.cm-searchMatch.cm-searchMatch-selected {
background-color: rgba(var(--d-surface-variant-rgb), 0.3);
outline: 1px solid var(--d-outline);
}

.cm-selectionMatch {
background-color: rgba(var(--d-secondary-rgb), 0.3);
}

/* stylelint-enable selector-class-pattern */
}
2 changes: 1 addition & 1 deletion app/views/activities/_coding_scratchpad.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ data-bs-target="#scratchpad-offcanvas" aria-controls="scratchpad-offcanvas" id="
<%= t ".experimental_feature_html", :url => contact_path %>
</div>
<div class="offcanvas-body scratchpad-content">
<div id="scratchpad-editor-wrapper"></div>
<div id="scratchpad-editor-wrapper" class="highlighter-rouge"></div>
<div id="scratchpad-panel-wrapper"></div>
<div id="scratchpad-output-wrapper"></div>
<div id="scratchpad-input-wrapper"></div>
Expand Down