Skip to content

Commit 75caf4f

Browse files
committed
fix stepinto when showing opcode
1 parent 30be360 commit 75caf4f

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

apps/remix-ide/src/app/components/bottom-bar.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,18 @@ export const BottomBar = ({ plugin }: BottomBarProps) => {
115115
setStepState('initial')
116116
}
117117

118+
const onShowOpcodesChanged = (showOpcodes: boolean) => {
119+
setStepManager((prevStepManager: any) => {
120+
if (!prevStepManager) return null
121+
return { ...prevStepManager, showOpcodes }
122+
})
123+
}
124+
118125
plugin.on('sidePanel', 'pluginDisabled', onPluginActivated)
119126
plugin.on('sidePanel', 'focusChanged', onPluginActivated)
120127
plugin.on('debugger', 'debuggingStarted', onDebuggingStarted)
121128
plugin.on('debugger', 'debuggingStopped', onDebuggingStopped)
129+
plugin.on('debugger', 'showOpcodesChanged', onShowOpcodesChanged)
122130

123131
return () => {
124132
plugin.off('tabs', 'extChanged')
@@ -128,6 +136,7 @@ export const BottomBar = ({ plugin }: BottomBarProps) => {
128136
plugin.off('sidePanel', 'focusChanged')
129137
plugin.off('debugger', 'debuggingStarted')
130138
plugin.off('debugger', 'debuggingStopped')
139+
plugin.off('debugger', 'showOpcodesChanged')
131140
}
132141
}, [plugin])
133142

@@ -185,7 +194,7 @@ export const BottomBar = ({ plugin }: BottomBarProps) => {
185194
</button>
186195
<button
187196
className="btn btn-sm btn-secondary debug-btn"
188-
onClick={() => stepManager?.stepOverBack && stepManager.stepOverBack(true)}
197+
onClick={() => stepManager?.stepOverBack && stepManager.stepOverBack(!(stepManager.showOpcodes ?? false))}
189198
disabled={stepState === 'initial'}
190199
data-id="btnStepBackward"
191200
>
@@ -194,7 +203,7 @@ export const BottomBar = ({ plugin }: BottomBarProps) => {
194203
</button>
195204
<button
196205
className="btn btn-sm btn-primary debug-btn"
197-
onClick={() => stepManager?.stepIntoBack && stepManager.stepIntoBack(true)}
206+
onClick={() => stepManager?.stepIntoBack && stepManager.stepIntoBack(!(stepManager.showOpcodes ?? false))}
198207
disabled={stepState === 'initial'}
199208
data-id="btnStepBack"
200209
>
@@ -203,7 +212,7 @@ export const BottomBar = ({ plugin }: BottomBarProps) => {
203212
</button>
204213
<button
205214
className="btn btn-sm btn-primary debug-btn"
206-
onClick={() => stepManager?.stepIntoForward && stepManager.stepIntoForward(true)}
215+
onClick={() => stepManager?.stepIntoForward && stepManager.stepIntoForward(!(stepManager.showOpcodes ?? false))}
207216
disabled={stepState === 'end'}
208217
data-id="btnStepInto"
209218
>
@@ -212,7 +221,7 @@ export const BottomBar = ({ plugin }: BottomBarProps) => {
212221
</button>
213222
<button
214223
className="btn btn-sm btn-secondary debug-btn"
215-
onClick={() => stepManager?.stepOverForward && stepManager.stepOverForward()}
224+
onClick={() => stepManager?.stepOverForward && stepManager.stepOverForward(!(stepManager.showOpcodes ?? false))}
216225
disabled={stepState === 'end'}
217226
data-id="btnStepForward"
218227
>

libs/remix-ui/debugger-ui/src/lib/debug-layout/debug-layout.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ interface DebugLayoutProps {
2424
callTree?: any
2525
debugWithGeneratedSources?: boolean
2626
onDebugWithGeneratedSourcesChange?: (checked: boolean) => void
27+
onShowOpcodesChange?: (checked: boolean) => void
28+
showOpcodes?: boolean
2729
registerEvent?: any
2830
}
2931

@@ -47,6 +49,8 @@ export const DebugLayout = ({
4749
callTree,
4850
debugWithGeneratedSources,
4951
onDebugWithGeneratedSourcesChange,
52+
onShowOpcodesChange,
53+
showOpcodes = false,
5054
registerEvent
5155
}: DebugLayoutProps) => {
5256
const [activeObjectTab, setActiveObjectTab] = useState<'stateLocals' | 'stackMemory'>('stateLocals')
@@ -69,6 +73,12 @@ export const DebugLayout = ({
6973
const opcodeRefs = React.useRef<{ [key: number]: HTMLDivElement | null }>({})
7074
const opcodeContainerRef = React.useRef<HTMLDivElement | null>(null)
7175

76+
const handleShowOpcodesChange = (checked: boolean) => {
77+
if (onShowOpcodesChange) {
78+
onShowOpcodesChange(checked)
79+
}
80+
}
81+
7282
// Auto-expand sender node when nestedScopes are loaded
7383
React.useEffect(() => {
7484
if (nestedScopes && nestedScopes.length > 0 && nestedScopes[0].isSenderNode) {
@@ -297,15 +307,25 @@ export const DebugLayout = ({
297307
const toggleObjectPath = (path: string) => {
298308
setExpandedObjectPaths(prev => {
299309
const newSet = new Set(prev)
310+
300311
if (newSet.has(path)) {
301312
newSet.delete(path)
302313
} else {
303314
newSet.add(path)
304315
}
316+
305317
return newSet
306318
})
307319
}
308320

321+
// Watch for opcode expansion/collapse and update showOpcodes accordingly
322+
React.useEffect(() => {
323+
const isOpcodeExpanded = expandedObjectPaths.has('root.opcode')
324+
if (handleShowOpcodesChange && isOpcodeExpanded !== showOpcodes) {
325+
handleShowOpcodesChange(isOpcodeExpanded)
326+
}
327+
}, [expandedObjectPaths, handleShowOpcodesChange, showOpcodes])
328+
309329
const isObject = (value: any): boolean => {
310330
return value !== null && typeof value === 'object'
311331
}

libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {Toaster} from '@remix-ui/toaster' // eslint-disable-line
1212
import { CustomTooltip, isValidHash } from '@remix-ui/helper'
1313
import { DebuggerEvent, MatomoEvent } from '@remix-api';
1414
import { TrackingContext } from '@remix-ide/tracking'
15-
import { ContractDeployment, ContractInteraction } from './transaction-recorder/types'
15+
import { ContractDeployment } from './transaction-recorder/types'
1616
/* eslint-disable-next-line */
1717
import './debugger-ui.css'
1818
import type { CompilerAbstract } from '@remix-project/remix-solidity'
@@ -45,11 +45,10 @@ export const DebuggerUI = (props: DebuggerUIProps) => {
4545
txNumberIsEmpty: true,
4646
isLocalNodeUsed: false,
4747
sourceLocationStatus: '',
48-
showOpcodes: true
48+
showOpcodes: false
4949
})
5050

51-
const [deployments, setDeployments] = useState<ContractDeployment[]>([])
52-
const [transactions, setTransactions] = useState<Map<string, ContractInteraction[]>>(new Map())
51+
const [deployments] = useState<ContractDeployment[]>([])
5352
const [traceData, setTraceData] = useState<{ currentStep: number; traceLength: number } | null>(null)
5453
const [currentFunction, setCurrentFunction] = useState<string>('')
5554
const [functionStack, setFunctionStack] = useState<any[]>([])
@@ -344,7 +343,6 @@ export const DebuggerUI = (props: DebuggerUIProps) => {
344343
})
345344
}
346345
}
347-
348346
const requestDebug = (blockNumber, txNumber, tx) => {
349347
startDebugging(blockNumber, txNumber, tx)
350348
}
@@ -508,7 +506,8 @@ export const DebuggerUI = (props: DebuggerUIProps) => {
508506
jumpNextBreakpoint: debuggerInstance.step_manager?.jumpNextBreakpoint.bind(debuggerInstance.step_manager),
509507
traceLength: debuggerInstance.step_manager?.traceLength,
510508
currentStepIndex: debuggerInstance.step_manager?.currentStepIndex,
511-
registerEvent: debuggerInstance.step_manager?.event.register.bind(debuggerInstance.step_manager?.event)
509+
registerEvent: debuggerInstance.step_manager?.event.register.bind(debuggerInstance.step_manager?.event),
510+
showOpcodes: state.showOpcodes
512511
}
513512
})
514513
})
@@ -547,6 +546,8 @@ export const DebuggerUI = (props: DebuggerUIProps) => {
547546
setState((prevState) => {
548547
return { ...prevState, showOpcodes }
549548
})
549+
// Emit event to update external listeners (like bottom-bar)
550+
debuggerModule.emit('showOpcodesChanged', showOpcodes)
550551
}
551552

552553
const stepManager = {
@@ -698,6 +699,8 @@ export const DebuggerUI = (props: DebuggerUIProps) => {
698699
}
699700
})
700701
}}
702+
onShowOpcodesChange={handleShowOpcodesChange}
703+
showOpcodes={state.showOpcodes}
701704
registerEvent={vmDebugger.registerEvent}
702705
/>
703706
</div>

0 commit comments

Comments
 (0)