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

Merge pull request #126 from sasjs/issue-119

running code with CTRL+ENTER
This commit is contained in:
Allan Bowe
2022-04-15 16:29:23 +03:00
committed by GitHub
5 changed files with 64 additions and 16 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
web/public/running-sas.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -28,10 +28,10 @@ const Header = (props: any) => {
> >
<Toolbar variant="dense"> <Toolbar variant="dense">
<img <img
src="logo-white.png" src="logo.png"
alt="logo" alt="logo"
style={{ style={{
width: '50px', width: '35px',
cursor: 'pointer', cursor: 'pointer',
marginRight: '25px' marginRight: '25px'
}} }}

View File

@@ -15,6 +15,17 @@ const useStyles = makeStyles(() => ({
'&.Mui-selected': { '&.Mui-selected': {
color: 'black' color: 'black'
} }
},
subMenu: {
marginTop: '25px',
display: 'flex',
justifyContent: 'center'
},
runButton: {
display: 'flex',
alignItems: 'center',
padding: '5px 5px',
minWidth: 'unset'
} }
})) }))
@@ -22,8 +33,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 +74,21 @@ const Studio = () => {
.catch((err) => console.log(err)) .catch((err) => console.log(err))
} }
const handleKeyDown = (event: any) => {
if (event.ctrlKey) {
if (event.key === 'v') {
setCtrlPressed(false)
}
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 +114,11 @@ 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={{
@@ -103,12 +135,24 @@ const Studio = () => {
</Tooltip> </Tooltip>
</TabList> </TabList>
</Box> </Box>
<TabPanel value="1">
<TabPanel style={{ paddingBottom: 0 }} value="1">
<div className={classes.subMenu}>
<Tooltip title="CTRL+ENTER will also run SAS code">
<Button onClick={handleRunBtnClick} className={classes.runButton}>
<img
draggable="false"
style={{ width: '25px' }}
src="/running-sas.png"
></img>
<span style={{ fontSize: '12px' }}>RUN</span>
</Button>
</Tooltip>
</div>
{/* <Toolbar /> */} {/* <Toolbar /> */}
<Paper <Paper
sx={{ sx={{
height: '70vh', height: 'calc(100vh - 170px)',
marginTop: '50px',
padding: '10px', padding: '10px',
overflow: 'auto', overflow: 'auto',
position: 'relative' position: 'relative'
@@ -116,23 +160,27 @@ const Studio = () => {
elevation={3} elevation={3}
> >
<Editor <Editor
height="95%" height="98%"
value={fileContent} value={fileContent}
onMount={handleEditorDidMount} onMount={handleEditorDidMount}
options={{ readOnly: ctrlPressed }}
onChange={(val) => { onChange={(val) => {
if (val) setFileContent(val) if (val) setFileContent(val)
}} }}
/> />
<p
style={{
position: 'absolute',
left: 0,
right: 0,
bottom: -10,
textAlign: 'center',
fontSize: '13px'
}}
>
Press CTRL + ENTER to run SAS code
</p>
</Paper> </Paper>
<Stack
spacing={3}
direction="row"
sx={{ justifyContent: 'center', marginTop: '20px' }}
>
<Button variant="contained" onClick={handleRunBtnClick}>
Run SAS Code
</Button>
</Stack>
</TabPanel> </TabPanel>
<TabPanel value="2"> <TabPanel value="2">
<div style={{ marginTop: '50px' }}> <div style={{ marginTop: '50px' }}>