diff --git a/explorer_frontend/src/features/code/Code.tsx b/explorer_frontend/src/features/code/Code.tsx index a9484695f..1e620c5b9 100644 --- a/explorer_frontend/src/features/code/Code.tsx +++ b/explorer_frontend/src/features/code/Code.tsx @@ -13,7 +13,8 @@ import { } from "./model"; import "./init"; import { type Diagnostic, linter } from "@codemirror/lint"; -import type { EditorView } from "@codemirror/view"; +import { Prec } from "@codemirror/state"; +import { type EditorView, keymap } from "@codemirror/view"; import { useStyletron } from "baseui"; import { expandProperty } from "inline-style-expand-shorthand"; import { type ReactNode, memo, useMemo } from "react"; @@ -45,6 +46,20 @@ export const Code = ({ extraMobileButton, extraToolbarButton }: CodeProps) => { const [css] = useStyletron(); const compilerVersionButton = extraToolbarButton === undefined ? : null; + const btnTextContent = useCompileButton(); + + const preventNewlineOnCmdEnter = useMemo( + () => + Prec.highest( + keymap.of([ + { + key: "Mod-Enter", + run: () => true, + }, + ]), + ), + [], + ); const codemirrorExtensions = useMemo(() => { const solidityLinter = (view: EditorView) => { @@ -69,11 +84,10 @@ export const Code = ({ extraMobileButton, extraToolbarButton }: CodeProps) => { return [...displayErrors, ...displayWarnings]; }; - return [linter(solidityLinter)]; - }, [errors, warnings]); + return [preventNewlineOnCmdEnter, linter(solidityLinter)]; + }, [errors, warnings, preventNewlineOnCmdEnter]); const noCode = code.trim().length === 0; - const btnContent = useCompileButton(); return ( { }} data-testid="compile-button" > - {btnContent} + {btnTextContent} )} {!isMobile && extraToolbarButton && extraToolbarButton} @@ -229,7 +243,7 @@ export const Code = ({ extraMobileButton, extraToolbarButton }: CodeProps) => { }} data-testid="compile-button" > - {btnContent} + {btnTextContent}