Skip to content

Commit a791374

Browse files
authored
Make Gas editable when not in run mode (#318)
1 parent 783b8ee commit a791374

File tree

2 files changed

+59
-25
lines changed

2 files changed

+59
-25
lines changed

src/components/Registers/index.tsx

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,44 @@ const ComputedValue = ({
110110
);
111111
};
112112

113+
const EditableField = ({
114+
onChange,
115+
value,
116+
}: {
117+
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
118+
value?: number | bigint;
119+
}) => {
120+
const { numeralSystem } = useContext(NumeralSystemContext);
121+
122+
return (
123+
<div className="flex-[3]">
124+
<Input
125+
className="w-20 h-6 m-0 py-0 px-[4px] text-md border-white hover:border-input"
126+
onChange={onChange}
127+
onKeyUp={(e) => {
128+
if (e.key === "Enter") {
129+
e.currentTarget.blur();
130+
}
131+
}}
132+
value={valueToNumeralSystem(value ?? 0, numeralSystem)}
133+
/>
134+
</div>
135+
);
136+
};
137+
113138
export const Registers = ({
114139
currentState,
115140
previousState,
116141
onCurrentStateChange,
117142
allowEditingPc,
143+
allowEditingGas,
118144
allowEditingRegisters,
119145
}: {
120146
currentState: ExpectedState;
121147
previousState: ExpectedState;
122148
onCurrentStateChange: (changedState: ExpectedState) => void;
123149
allowEditingPc: boolean;
150+
allowEditingGas: boolean;
124151
allowEditingRegisters: boolean;
125152
}) => {
126153
const { numeralSystem } = useContext(NumeralSystemContext);
@@ -134,25 +161,17 @@ export const Registers = ({
134161
<div className="flex flex-row items-center justify-between w-full mb-2">
135162
<p className="flex-[2]">PC</p>
136163
{allowEditingPc ? (
137-
<div className="flex-[3]">
138-
<Input
139-
className="w-20 h-6 m-0 py-0 px-[4px] text-md border-white hover:border-input"
140-
onChange={(e) => {
141-
const value = e.target?.value;
142-
const newValue = stringToNumber(value, Number);
143-
onCurrentStateChange({
144-
...currentState,
145-
pc: newValue,
146-
});
147-
}}
148-
onKeyUp={(e) => {
149-
if (e.key === "Enter") {
150-
e.currentTarget.blur();
151-
}
152-
}}
153-
value={valueToNumeralSystem(currentState.pc ?? 0, numeralSystem)}
154-
/>
155-
</div>
164+
<EditableField
165+
onChange={(e) => {
166+
const value = e.target?.value;
167+
const newValue = stringToNumber(value, Number);
168+
onCurrentStateChange({
169+
...currentState,
170+
pc: newValue,
171+
});
172+
}}
173+
value={currentState.pc}
174+
/>
156175
) : (
157176
<ComputedValue
158177
value={currentState.pc}
@@ -164,12 +183,26 @@ export const Registers = ({
164183
</div>
165184
<div className="flex flex-row items-center justify-between w-full mb-2">
166185
<p className="flex-[2]">Gas</p>
167-
<ComputedValue
168-
value={currentState.gas}
169-
previousValue={previousState.gas}
170-
propName="gas"
171-
workers={workers}
172-
/>
186+
{allowEditingGas ? (
187+
<EditableField
188+
onChange={(e) => {
189+
const value = e.target?.value;
190+
const newValue = BigInt(stringToNumber(value, Number));
191+
onCurrentStateChange({
192+
...currentState,
193+
gas: newValue,
194+
});
195+
}}
196+
value={currentState.gas}
197+
/>
198+
) : (
199+
<ComputedValue
200+
value={currentState.gas}
201+
previousValue={previousState.gas}
202+
propName="gas"
203+
workers={workers}
204+
/>
205+
)}
173206
</div>
174207
<div className="flex flex-row items-center justify-between w-full">
175208
<p className="flex-[2]">Status</p>

src/pages/DebuggerContent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ const DebuggerContent = () => {
129129
debuggerActions.restartProgram(state);
130130
}}
131131
allowEditingPc={!isDebugFinished && !isRunMode && !isStepMode}
132+
allowEditingGas={!isDebugFinished && !isRunMode && !isStepMode}
132133
allowEditingRegisters={false}
133134
/>
134135
</div>

0 commit comments

Comments
 (0)