1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-10 16:00:05 +00:00

feat: running code with CTRL+ENTER

This commit is contained in:
2022-04-13 15:27:41 +02:00
parent e5facbf54c
commit b93a0da3a3

View File

@@ -22,8 +22,10 @@ const Studio = () => {
const location = useLocation() const location = useLocation()
const [fileContent, setFileContent] = useState('') const [fileContent, setFileContent] = useState('')
const [log, setLog] = useState('') const [log, setLog] = useState('')
const [ctrlPressed, setCtrlPressed] = useState(false)
const [webout, setWebout] = useState('') const [webout, setWebout] = useState('')
const [tab, setTab] = React.useState('1') const [tab, setTab] = React.useState('1')
const handleTabChange = (_e: any, newValue: string) => { const handleTabChange = (_e: any, newValue: string) => {
setTab(newValue) setTab(newValue)
} }
@@ -61,6 +63,17 @@ const Studio = () => {
.catch((err) => console.log(err)) .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(() => { useEffect(() => {
const content = localStorage.getItem('fileContent') ?? '' const content = localStorage.getItem('fileContent') ?? ''
setFileContent(content) setFileContent(content)
@@ -86,7 +99,7 @@ const Studio = () => {
const classes = useStyles() const classes = useStyles()
return ( return (
<Box sx={{ width: '100%', typography: 'body1', marginTop: '50px' }}> <Box onKeyUp={handleKeyUp} onKeyDown={handleKeyDown} sx={{ width: '100%', typography: 'body1', marginTop: '50px' }}>
<TabContext value={tab}> <TabContext value={tab}>
<Box <Box
sx={{ sx={{
@@ -119,6 +132,7 @@ const Studio = () => {
height="95%" height="95%"
value={fileContent} value={fileContent}
onMount={handleEditorDidMount} onMount={handleEditorDidMount}
options={{readOnly: ctrlPressed}}
onChange={(val) => { onChange={(val) => {
if (val) setFileContent(val) if (val) setFileContent(val)
}} }}
@@ -133,6 +147,7 @@ const Studio = () => {
Run SAS Code Run SAS Code
</Button> </Button>
</Stack> </Stack>
<p style={{ textAlign: 'center', fontSize: '13px' }}>Or press CTRL + ENTER</p>
</TabPanel> </TabPanel>
<TabPanel value="2"> <TabPanel value="2">
<div style={{ marginTop: '50px' }}> <div style={{ marginTop: '50px' }}>