From b93a0da3a380926c87548b69309b2d0c1b7e617f Mon Sep 17 00:00:00 2001 From: Mihajlo Date: Wed, 13 Apr 2022 15:27:41 +0200 Subject: [PATCH] feat: running code with CTRL+ENTER --- web/src/containers/Studio/index.tsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/web/src/containers/Studio/index.tsx b/web/src/containers/Studio/index.tsx index 98db395..c37d6bc 100644 --- a/web/src/containers/Studio/index.tsx +++ b/web/src/containers/Studio/index.tsx @@ -22,8 +22,10 @@ const Studio = () => { const location = useLocation() const [fileContent, setFileContent] = useState('') const [log, setLog] = useState('') + const [ctrlPressed, setCtrlPressed] = useState(false) const [webout, setWebout] = useState('') const [tab, setTab] = React.useState('1') + const handleTabChange = (_e: any, newValue: string) => { setTab(newValue) } @@ -61,6 +63,17 @@ const Studio = () => { .catch((err) => console.log(err)) } + const handleKeyDown = (event: any) => { + if (event.ctrlKey) { + if (event.key === 'Enter') runCode(getSelection() || fileContent) + if (!ctrlPressed) setCtrlPressed(true) + } + } + + const handleKeyUp = (event: any) => { + if (!event.ctrlKey && ctrlPressed) setCtrlPressed(false) + } + useEffect(() => { const content = localStorage.getItem('fileContent') ?? '' setFileContent(content) @@ -86,7 +99,7 @@ const Studio = () => { const classes = useStyles() return ( - + { height="95%" value={fileContent} onMount={handleEditorDidMount} + options={{readOnly: ctrlPressed}} onChange={(val) => { if (val) setFileContent(val) }} @@ -133,6 +147,7 @@ const Studio = () => { Run SAS Code +

Or press CTRL + ENTER