Skip to content

Commit 570dc96

Browse files
Merge pull request #40 from yontank/yona_dev
Add setError function to SimulationContext and update EditorPanel to …
2 parents 8189993 + 2df5d65 commit 570dc96

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/components/EditorPanel.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function EditorPanel(props: { editorInterface: Ref<EditorInterface> }) {
2323
editor.IEditorDecorationsCollection | undefined
2424
>(undefined)
2525
const monaco = useMonaco()
26-
const { initialPC, setInitialPC, editorRef, error, simulation } =
26+
const { initialPC, setInitialPC, editorRef, error, simulation, setError } =
2727
useSimulationContext()
2828

2929
useImperativeHandle(props.editorInterface, () => ({
@@ -38,7 +38,7 @@ export function EditorPanel(props: { editorInterface: Ref<EditorInterface> }) {
3838
else localStorage.setItem(LOCAL_STORAGE_EDITOR_KEY, current.getValue())
3939
}
4040

41-
addEventListener("beforeunload", onBeforeUnload )
41+
addEventListener("beforeunload", onBeforeUnload)
4242

4343
return () => {
4444
window.removeEventListener("beforeunload", onBeforeUnload)
@@ -70,7 +70,7 @@ export function EditorPanel(props: { editorInterface: Ref<EditorInterface> }) {
7070
options: {
7171
isWholeLine: true,
7272
blockClassName: "errorVscode",
73-
blockPadding: [error.line, 0, error.line, 55],
73+
blockPadding: [0, 55, 0, 85],
7474
shouldFillLineOnLineBreak: true,
7575
stickiness:
7676
monaco.editor.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
@@ -81,8 +81,8 @@ export function EditorPanel(props: { editorInterface: Ref<EditorInterface> }) {
8181

8282
const handleChange = () => {
8383
// When the user is editing his code, we should dismiss the error line \ toast.
84+
if (error) setError(undefined)
8485
toasts.forEach((t) => toast.dismiss(t.id))
85-
decorations?.clear()
8686
}
8787

8888
return (

src/context/SimulationContext.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,34 @@ type Context = {
4545
*/
4646
initialPC: string
4747
setInitialPC: React.Dispatch<React.SetStateAction<string>>
48-
48+
/**
49+
* Initial Registers before starting a simulation.
50+
*/
4951
initialRegisters: number[]
52+
/**
53+
* Sets the initial registers as a state.
54+
*/
5055
setInitialRegisters: React.Dispatch<React.SetStateAction<number[]>>
51-
56+
/**
57+
* Gets the previous PC.
58+
*/
5259
prevPc: number | undefined
53-
60+
/**
61+
* Right Tab value for Editor\Execution.
62+
*/
5463
rightTabValue: "IDE" | "debugger"
64+
/**
65+
* Setter for Editor Tabs (Right side)
66+
*/
5567
setRightTabValue: React.Dispatch<React.SetStateAction<"IDE" | "debugger">>
68+
/**
69+
* Error line controller for toasts, editor highlight
70+
*/
71+
setError : React.Dispatch<React.SetStateAction<{
72+
code?: number;
73+
line: number;
74+
msg: string;
75+
} | undefined>>
5676
}
5777

5878
type RunningState = {
@@ -179,6 +199,7 @@ export function SimulationContextProvider({ children }: Props) {
179199
setInitialRegisters,
180200
prevPc,
181201
editorRef,
202+
setError
182203
}}
183204
>
184205
{children}

0 commit comments

Comments
 (0)