Skip to content
Open
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
26 changes: 23 additions & 3 deletions experimenter/experimenter/nimbus_ui/static/js/branch_detail.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { basicSetup } from "codemirror";
import { EditorView } from "@codemirror/view";
import {
drawSelection,
EditorView,
highlightSpecialChars,
lineNumbers,
} from "@codemirror/view";
import { EditorState } from "@codemirror/state";
import { json, jsonParseLinter } from "@codemirror/lang-json";
import { linter } from "@codemirror/lint";
import {
HighlightStyle,
syntaxHighlighting,
defaultHighlightStyle,
foldGutter,
} from "@codemirror/language";
import { tags } from "@lezer/highlight";

import $ from "jquery";

Expand All @@ -12,11 +23,20 @@ const setupCodemirroReadOnlyJSON = () => {
const selector = ".readonly-json";
const textareas = document.querySelectorAll(selector);

const highlightStyle = HighlightStyle.define([
{ tag: tags.bool, color: "#ffaa00ff", themeType: "dark" },
]);

textareas.forEach((textarea) => {
if (textarea.dataset.is_rendered) return;
textarea.dataset.is_rendered = true;
const extensions = [
basicSetup,
lineNumbers(),
drawSelection(),
highlightSpecialChars(),
foldGutter(),
syntaxHighlighting(highlightStyle),
syntaxHighlighting(defaultHighlightStyle),
json(),
linter(jsonParseLinter()),
EditorState.readOnly.of(true),
Expand Down
47 changes: 43 additions & 4 deletions experimenter/experimenter/nimbus_ui/static/js/edit_branches.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
import { basicSetup } from "codemirror";
import { EditorView } from "@codemirror/view";
import {
drawSelection,
EditorView,
highlightActiveLine,
highlightSpecialChars,
keymap,
lineNumbers,
} from "@codemirror/view";
import { json, jsonParseLinter } from "@codemirror/lang-json";
import { linter } from "@codemirror/lint";
import { autocompletion } from "@codemirror/autocomplete";
import { autocompletion, closeBrackets } from "@codemirror/autocomplete";
import {
HighlightStyle,
syntaxHighlighting,
defaultHighlightStyle,
foldGutter,
bracketMatching,
indentOnInput,
} from "@codemirror/language";
import {
highlightSelectionMatches,
searchKeymap,
search,
} from "@codemirror/search";
import { defaultKeymap, historyKeymap, history } from "@codemirror/commands";
import { tags } from "@lezer/highlight";
import { schemaAutocomplete, schemaLinter } from "./validator.js";
import $ from "jquery";

Expand All @@ -12,8 +33,26 @@ const setupCodemirror = (selector, textarea, extraExtensions) => {
return;
}

const highlightStyle = HighlightStyle.define([
{ tag: tags.bool, color: "#ffaa00ff", themeType: "dark" },
]);

const extensions = [
basicSetup,
lineNumbers(),
drawSelection(),
highlightSpecialChars(),
foldGutter(),
autocompletion(),
bracketMatching(),
closeBrackets(),
highlightSelectionMatches(),
indentOnInput(),
highlightActiveLine(),
syntaxHighlighting(highlightStyle),
syntaxHighlighting(defaultHighlightStyle),
history(),
search(),
keymap.of([...defaultKeymap, ...searchKeymap, ...historyKeymap]),
Comment on lines -16 to +55
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is a bit hairy. If using dedicated light/dark themes is too complicated let's just go back to your original approach of just overriding the colour of the bools. Simplest, smallest solution is usually best 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach i have here is only changing the colour of the boolean text. basicSetup packages all of these extensions without any option to exclude specific ones, which is an issue because this included extension prevents me from setting a custom HighlightStyle that overrides boolean text colour. Annoyingly, the only way to fix this is to manually include all the extensions except defaultHighlightStyle

EditorView.updateListener.of((v) => {
if (v.docChanged) {
const value = v.state.doc.toString();
Expand Down
1 change: 1 addition & 0 deletions experimenter/experimenter/nimbus_ui/static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"dependencies": {
"@fortawesome/fontawesome-free": "^6.5.2",
"@lezer/highlight": "^1.2.2",
"bootstrap": "^5.3.3",
"bootstrap-select": "1.14.0-beta3",
"codemirror": "^6.0.1",
Expand Down
Loading