Skip to content

Ensure that only 6-character hex values are passed to monaco editor #18943

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

Merged
merged 2 commits into from
Nov 7, 2022
Merged
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
20 changes: 15 additions & 5 deletions airbyte-webapp/src/components/ui/CodeEditor/CodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ interface CodeEditorProps {
lineNumberCharacterWidth?: number;
}

// Converts 3-character hex values into 6-character ones.
// Required for custom monaco theme, because it fails when receiving 3-character hex values.
function expandHexValue(input: string) {
const match = /^#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])$/.exec(input);
if (match) {
return `#${match[1].repeat(2)}${match[2].repeat(2)}${match[3].repeat(2)}`;
}
return input;
}

export const CodeEditor: React.FC<CodeEditorProps> = ({
value,
language,
Expand All @@ -27,11 +37,11 @@ export const CodeEditor: React.FC<CodeEditorProps> = ({
base: "vs-dark",
inherit: true,
rules: [
{ token: "string", foreground: styles.tokenString },
{ token: "type", foreground: styles.tokenType },
{ token: "number", foreground: styles.tokenNumber },
{ token: "delimiter", foreground: styles.tokenDelimiter },
{ token: "keyword", foreground: styles.tokenKeyword },
{ token: "string", foreground: expandHexValue(styles.tokenString) },
{ token: "type", foreground: expandHexValue(styles.tokenType) },
{ token: "number", foreground: expandHexValue(styles.tokenNumber) },
{ token: "delimiter", foreground: expandHexValue(styles.tokenDelimiter) },
{ token: "keyword", foreground: expandHexValue(styles.tokenKeyword) },
],
colors: {
"editor.background": "#00000000", // transparent, so that parent background is shown instead
Expand Down