fix: Update editor height when resizing window

This commit is contained in:
Billy Vong 2021-12-20 14:04:42 -05:00
parent 5dc9ac040a
commit ee177393fa

@ -125,6 +125,25 @@ export function Root(props: IProps): React.ReactElement {
vim: props.vim || Settings.MonacoVim, vim: props.vim || Settings.MonacoVim,
}); });
const [dimensions, setDimensions] = useState({
height: window.innerHeight,
width: window.innerWidth
});
useEffect(() => {
const debouncedHandleResize = debounce(function handleResize() {
setDimensions({
height: window.innerHeight,
width: window.innerWidth
})
}, 250)
window.addEventListener('resize', debouncedHandleResize)
return () => {
window.removeEventListener('resize', debouncedHandleResize)
}}, [])
useEffect(() => { useEffect(() => {
// Save currentScript // Save currentScript
window.localStorage.setItem( window.localStorage.setItem(
@ -636,10 +655,14 @@ export function Root(props: IProps): React.ReactElement {
} }
// TODO: Make this responsive to window resizes // TODO: Make this responsive to window resizes
// Toolbars are roughly 108px + vim bar 34px // Toolbars are roughly 112px:
// Get percentage of space that toolbars represent and the rest should be the // 8px body margin top
// editor // 38.5px filename tabs
const editorHeight = 100 - ((108 + (options.vim ? 34 : 0)) / window.innerHeight) * 100; // 5px padding for top of editor
// 44px bottom tool bar + 16px margin
// + vim bar 34px
const editorHeight = dimensions.height - (112 + (options.vim ? 34 : 0));
console.log({editorHeight})
return ( return (
<> <>
@ -718,7 +741,7 @@ export function Root(props: IProps): React.ReactElement {
beforeMount={beforeMount} beforeMount={beforeMount}
onMount={onMount} onMount={onMount}
loading={<Typography>Loading script editor!</Typography>} loading={<Typography>Loading script editor!</Typography>}
height={`${editorHeight}%`} height={`${editorHeight}px`}
defaultLanguage="javascript" defaultLanguage="javascript"
defaultValue={""} defaultValue={""}
onChange={updateCode} onChange={updateCode}