|
|
@ -47,7 +47,7 @@ type sourceMarkerMap = { |
|
|
|
/* eslint-disable-next-line */ |
|
|
|
/* eslint-disable-next-line */ |
|
|
|
export interface EditorUIProps { |
|
|
|
export interface EditorUIProps { |
|
|
|
activated: boolean |
|
|
|
activated: boolean |
|
|
|
theme: string |
|
|
|
themeType: string |
|
|
|
currentFile: string |
|
|
|
currentFile: string |
|
|
|
sourceAnnotationsPerFile: sourceAnnotationMap |
|
|
|
sourceAnnotationsPerFile: sourceAnnotationMap |
|
|
|
markerPerFile: sourceMarkerMap |
|
|
|
markerPerFile: sourceMarkerMap |
|
|
@ -60,7 +60,7 @@ export interface EditorUIProps { |
|
|
|
plugin: { |
|
|
|
plugin: { |
|
|
|
on: (plugin: string, event: string, listener: any) => void |
|
|
|
on: (plugin: string, event: string, listener: any) => void |
|
|
|
} |
|
|
|
} |
|
|
|
editorAPI:{ |
|
|
|
editorAPI: { |
|
|
|
findMatches: (uri: string, value: string) => any |
|
|
|
findMatches: (uri: string, value: string) => any |
|
|
|
getFontSize: () => number, |
|
|
|
getFontSize: () => number, |
|
|
|
getValue: (uri: string) => string |
|
|
|
getValue: (uri: string) => string |
|
|
@ -78,28 +78,40 @@ export const EditorUI = (props: EditorUIProps) => { |
|
|
|
|
|
|
|
|
|
|
|
const [editorModelsState, dispatch] = useReducer(reducerActions, initialState) |
|
|
|
const [editorModelsState, dispatch] = useReducer(reducerActions, initialState) |
|
|
|
|
|
|
|
|
|
|
|
const defineAndSetDarkTheme = (monaco) => { |
|
|
|
const formatColor = (name) => { |
|
|
|
|
|
|
|
let color = window.getComputedStyle(document.documentElement).getPropertyValue(name).trim() |
|
|
|
|
|
|
|
if (color.length === 4) { |
|
|
|
|
|
|
|
color = color.concat(color.substr(1)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return color |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const defineAndSetTheme = (monaco) => { |
|
|
|
|
|
|
|
const themeType = props.themeType === 'dark' ? 'vs-dark' : 'vs' |
|
|
|
|
|
|
|
const themeName = props.themeType === 'dark' ? 'remix-dark' : 'remix-light' |
|
|
|
// see https://microsoft.github.io/monaco-editor/playground.html#customizing-the-appearence-exposed-colors
|
|
|
|
// see https://microsoft.github.io/monaco-editor/playground.html#customizing-the-appearence-exposed-colors
|
|
|
|
const lightColor = window.getComputedStyle(document.documentElement).getPropertyValue('--light').trim() |
|
|
|
const lightColor = formatColor('--light') |
|
|
|
const infoColor = window.getComputedStyle(document.documentElement).getPropertyValue('--info').trim() |
|
|
|
const infoColor = formatColor('--info') |
|
|
|
|
|
|
|
const darkColor = formatColor('--dark') |
|
|
|
const blueColor = window.getComputedStyle(document.documentElement).getPropertyValue('--blue').trim() |
|
|
|
const secondaryColor = formatColor('--secondary') |
|
|
|
const successColor = window.getComputedStyle(document.documentElement).getPropertyValue('--success').trim() |
|
|
|
const textColor = formatColor('--text') || darkColor |
|
|
|
const warningColor = window.getComputedStyle(document.documentElement).getPropertyValue('--warning').trim() |
|
|
|
const textbackground = formatColor('--text-background') || lightColor |
|
|
|
const yellowColor = window.getComputedStyle(document.documentElement).getPropertyValue('--yellow').trim() |
|
|
|
|
|
|
|
const pinkColor = window.getComputedStyle(document.documentElement).getPropertyValue('--pink').trim() |
|
|
|
|
|
|
|
|
|
|
|
const blueColor = formatColor('--blue') |
|
|
|
|
|
|
|
const successColor = formatColor('--success') |
|
|
|
|
|
|
|
const warningColor = formatColor('--warning') |
|
|
|
|
|
|
|
const yellowColor = formatColor('--yellow') |
|
|
|
|
|
|
|
const pinkColor = formatColor('--pink') |
|
|
|
const locationColor = '#9e7e08' |
|
|
|
const locationColor = '#9e7e08' |
|
|
|
const purpleColor = window.getComputedStyle(document.documentElement).getPropertyValue('--purple').trim() |
|
|
|
const purpleColor = formatColor('--purple') |
|
|
|
const dangerColor = window.getComputedStyle(document.documentElement).getPropertyValue('--danger').trim() |
|
|
|
const dangerColor = formatColor('--danger') |
|
|
|
|
|
|
|
|
|
|
|
const darkColor = window.getComputedStyle(document.documentElement).getPropertyValue('--dark').trim() |
|
|
|
monaco.editor.defineTheme(themeName, { |
|
|
|
const grayColor = window.getComputedStyle(document.documentElement).getPropertyValue('--gray-dark').trim() |
|
|
|
base: themeType, |
|
|
|
|
|
|
|
|
|
|
|
monaco.editor.defineTheme('remix-dark', { |
|
|
|
|
|
|
|
base: 'vs-dark', |
|
|
|
|
|
|
|
inherit: true, // can also be false to completely replace the builtin rules
|
|
|
|
inherit: true, // can also be false to completely replace the builtin rules
|
|
|
|
rules: [ |
|
|
|
rules: [ |
|
|
|
{ background: darkColor.replace('#', '') }, |
|
|
|
{ background: darkColor.replace('#', '') }, |
|
|
|
|
|
|
|
{ foreground: textColor.replace('#', '') }, |
|
|
|
|
|
|
|
|
|
|
|
// global variables
|
|
|
|
// global variables
|
|
|
|
{ token: 'keyword.abi', foreground: blueColor }, |
|
|
|
{ token: 'keyword.abi', foreground: blueColor }, |
|
|
@ -165,24 +177,24 @@ export const EditorUI = (props: EditorUIProps) => { |
|
|
|
|
|
|
|
|
|
|
|
], |
|
|
|
], |
|
|
|
colors: { |
|
|
|
colors: { |
|
|
|
'editor.background': darkColor, |
|
|
|
// see https://code.visualstudio.com/api/references/theme-color for more settings
|
|
|
|
|
|
|
|
'editor.background': textbackground, |
|
|
|
'editorSuggestWidget.background': lightColor, |
|
|
|
'editorSuggestWidget.background': lightColor, |
|
|
|
'editorSuggestWidget.selectedBackground': lightColor, |
|
|
|
'editorSuggestWidget.selectedBackground': lightColor, |
|
|
|
'editorSuggestWidget.highlightForeground': infoColor, |
|
|
|
'editorSuggestWidget.highlightForeground': infoColor, |
|
|
|
'editor.lineHighlightBorder': lightColor, |
|
|
|
'editor.lineHighlightBorder': secondaryColor, |
|
|
|
'editor.lineHighlightBackground': grayColor, |
|
|
|
'editor.lineHighlightBackground': textbackground === darkColor ? lightColor : secondaryColor, |
|
|
|
'editorGutter.background': lightColor |
|
|
|
'editorGutter.background': lightColor, |
|
|
|
|
|
|
|
'minimap.background': lightColor |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
monacoRef.current.editor.setTheme('remix-dark') |
|
|
|
monacoRef.current.editor.setTheme(themeName) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (!monacoRef.current) return |
|
|
|
if (!monacoRef.current) return |
|
|
|
if (props.theme === 'remix-dark') { |
|
|
|
defineAndSetTheme(monacoRef.current) |
|
|
|
defineAndSetDarkTheme(monacoRef.current) |
|
|
|
}) |
|
|
|
} else monacoRef.current.editor.setTheme(props.theme) |
|
|
|
|
|
|
|
}, [props.theme]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const setAnnotationsbyFile = (uri) => { |
|
|
|
const setAnnotationsbyFile = (uri) => { |
|
|
|
if (props.sourceAnnotationsPerFile[uri]) { |
|
|
|
if (props.sourceAnnotationsPerFile[uri]) { |
|
|
@ -307,11 +319,9 @@ export const EditorUI = (props: EditorUIProps) => { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function handleEditorDidMount (editor) { |
|
|
|
function handleEditorDidMount(editor) { |
|
|
|
editorRef.current = editor |
|
|
|
editorRef.current = editor |
|
|
|
if (props.theme === 'remix-dark') { |
|
|
|
defineAndSetTheme(monacoRef.current) |
|
|
|
defineAndSetDarkTheme(monacoRef.current) |
|
|
|
|
|
|
|
} else monacoRef.current.editor.setTheme(props.theme) |
|
|
|
|
|
|
|
reducerListener(props.plugin, dispatch, monacoRef.current, editorRef.current, props.events) |
|
|
|
reducerListener(props.plugin, dispatch, monacoRef.current, editorRef.current, props.events) |
|
|
|
props.events.onEditorMounted() |
|
|
|
props.events.onEditorMounted() |
|
|
|
editor.onMouseUp((e) => { |
|
|
|
editor.onMouseUp((e) => { |
|
|
@ -327,7 +337,7 @@ export const EditorUI = (props: EditorUIProps) => { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function handleEditorWillMount (monaco) { |
|
|
|
function handleEditorWillMount(monaco) { |
|
|
|
monacoRef.current = monaco |
|
|
|
monacoRef.current = monaco |
|
|
|
// Register a new language
|
|
|
|
// Register a new language
|
|
|
|
monacoRef.current.languages.register({ id: 'remix-solidity' }) |
|
|
|
monacoRef.current.languages.register({ id: 'remix-solidity' }) |
|
|
@ -343,7 +353,7 @@ export const EditorUI = (props: EditorUIProps) => { |
|
|
|
language={editorModelsState[props.currentFile] ? editorModelsState[props.currentFile].language : 'text'} |
|
|
|
language={editorModelsState[props.currentFile] ? editorModelsState[props.currentFile].language : 'text'} |
|
|
|
onMount={handleEditorDidMount} |
|
|
|
onMount={handleEditorDidMount} |
|
|
|
beforeMount={handleEditorWillMount} |
|
|
|
beforeMount={handleEditorWillMount} |
|
|
|
options= { { glyphMargin: true } } |
|
|
|
options={{ glyphMargin: true }} |
|
|
|
/> |
|
|
|
/> |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|