diff options
Diffstat (limited to 'src/console/hooks')
-rw-r--r-- | src/console/hooks/useAutoResize.ts | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/console/hooks/useAutoResize.ts b/src/console/hooks/useAutoResize.ts new file mode 100644 index 0000000..4253606 --- /dev/null +++ b/src/console/hooks/useAutoResize.ts @@ -0,0 +1,28 @@ +import React from "react"; +import ConsoleFrameClient from "../clients/ConsoleFrameClient"; + +const useAutoResize = () => { + const [prevWidth, setPrevWidth] = React.useState(-1); + const [prevHeight, setPrevHeight] = React.useState(-1); + + const consoleFrameClient = React.useMemo(() => { + return new ConsoleFrameClient(); + }, []); + + React.useLayoutEffect(() => { + const { + scrollWidth: width, + scrollHeight: height, + } = document.getElementById("vimvixen-console")!; + consoleFrameClient.resize(width, height); + + if (width === prevWidth && height === prevHeight) { + return; + } + + setPrevWidth(width); + setPrevHeight(height); + }); +}; + +export default useAutoResize; |