fix bug of scroll on ace Editor
This commit is contained in:
parent
7c37c6d74f
commit
cd94c47b0e
1 changed files with 20 additions and 3 deletions
|
|
@ -37,11 +37,11 @@ export default function CodeAreaModal({
|
||||||
const { dark } = useContext(darkContext);
|
const { dark } = useContext(darkContext);
|
||||||
const { setErrorData, setSuccessData } = useContext(alertContext);
|
const { setErrorData, setSuccessData } = useContext(alertContext);
|
||||||
const [activeTab, setActiveTab] = useState("0");
|
const [activeTab, setActiveTab] = useState("0");
|
||||||
|
const [height, setHeight] = useState(null);
|
||||||
const [error, setError] = useState<{
|
const [error, setError] = useState<{
|
||||||
detail: { error: string; traceback: string };
|
detail: { error: string; traceback: string };
|
||||||
}>(null);
|
}>(null);
|
||||||
const { closePopUp, setCloseEdit } = useContext(PopUpContext);
|
const { closePopUp, setCloseEdit } = useContext(PopUpContext);
|
||||||
const ref = useRef();
|
|
||||||
function setModalOpen(x: boolean) {
|
function setModalOpen(x: boolean) {
|
||||||
setOpen(x);
|
setOpen(x);
|
||||||
if (x === false) {
|
if (x === false) {
|
||||||
|
|
@ -109,7 +109,23 @@ export default function CodeAreaModal({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const tabs = [{ name: "code" }, { name: "errors" }];
|
|
||||||
|
/// use effect to update ace editor on error to handle right scroll
|
||||||
|
useEffect(() => {
|
||||||
|
// Function to be executed after the state changes
|
||||||
|
const delayedFunction = setTimeout(() => {
|
||||||
|
if (error?.detail.error !== undefined) {
|
||||||
|
//trigger to update the height, does not really apply any height
|
||||||
|
setHeight("90%");
|
||||||
|
}
|
||||||
|
//600 to happen after the transition of 500ms
|
||||||
|
}, 600);
|
||||||
|
|
||||||
|
// Cleanup function to clear the timeout if the component unmounts or the state changes again
|
||||||
|
return () => {
|
||||||
|
clearTimeout(delayedFunction);
|
||||||
|
};
|
||||||
|
}, [error, setHeight]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BaseModal open={true} setOpen={setOpen}>
|
<BaseModal open={true} setOpen={setOpen}>
|
||||||
|
|
@ -129,6 +145,7 @@ export default function CodeAreaModal({
|
||||||
<AceEditor
|
<AceEditor
|
||||||
value={code}
|
value={code}
|
||||||
mode="python"
|
mode="python"
|
||||||
|
height={height ?? "100%"}
|
||||||
highlightActiveLine={true}
|
highlightActiveLine={true}
|
||||||
showPrintMargin={false}
|
showPrintMargin={false}
|
||||||
fontSize={14}
|
fontSize={14}
|
||||||
|
|
@ -148,7 +165,7 @@ export default function CodeAreaModal({
|
||||||
(error?.detail.error !== undefined ? "h-2/6" : "h-0")
|
(error?.detail.error !== undefined ? "h-2/6" : "h-0")
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<div className="mt-1 h-full w-full overflow-x-clip overflow-y-scroll text-left custom-scroll">
|
<div className="mt-1 h-full w-full overflow-y-auto overflow-x-clip text-left custom-scroll">
|
||||||
<h1 className="text-lg text-destructive">
|
<h1 className="text-lg text-destructive">
|
||||||
{error?.detail?.error}
|
{error?.detail?.error}
|
||||||
</h1>
|
</h1>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue