Skip to content

Commit

Permalink
fix(controller/core): breakpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
exuanbo committed Dec 15, 2023
1 parent e767687 commit 43f0fe2
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/features/controller/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { produce } from 'immer'
import { first } from 'rxjs'

import { store } from '@/app/store'
Expand Down Expand Up @@ -327,20 +328,26 @@ export class Controller {
}
let hasBreakpoint = false
const breakpoints = store.getState(selectEditorBreakpoints)
const currentStatementRange = store.getState(selectCurrentStatementRange)
if (breakpoints.length && currentStatementRange && isRunning && !willSuspend) {
const breakpointLineLoc = breakpoints.find((lineLoc) =>
lineRangesOverlap(lineLoc, currentStatementRange),
)
if (breakpointLineLoc !== undefined) {
hasBreakpoint = true
if (breakpointLineLoc.number !== this.lastBreakpointLineNumber) {
if (!this.willDispatchChanges) {
dispatchChanges()
if (breakpoints.length && isRunning && !willSuspend) {
const nextState = produce(store.getState(), (draft) => {
draft.cpu.registers = cpuRegisters
draft.memory.data = memoryData
})
const nextStatementRange = selectCurrentStatementRange(nextState)
if (nextStatementRange) {
const breakpointLineLoc = breakpoints.find((lineLoc) =>
lineRangesOverlap(lineLoc, nextStatementRange),
)
if (breakpointLineLoc !== undefined) {
hasBreakpoint = true
if (breakpointLineLoc.number !== this.lastBreakpointLineNumber) {
if (!this.willDispatchChanges) {
dispatchChanges()
}
// `isRunning` is already checked
this.stop()
this.lastBreakpointLineNumber = breakpointLineLoc.number
}
// `isRunning` is already checked
this.stop()
this.lastBreakpointLineNumber = breakpointLineLoc.number
}
}
}
Expand Down

0 comments on commit 43f0fe2

Please sign in to comment.