From 37f1b4cb7b3e9686b753d322948a9ffe30ba842e Mon Sep 17 00:00:00 2001 From: Dang Hoang Duy <128918146+DiligentPenguinn@users.noreply.github.com> Date: Tue, 26 Mar 2024 22:47:51 +0800 Subject: [PATCH] CSE Machine: Implement navigation arrows to jump to the next/previous change in environment (frontend) (#2869) * Add extra {} when the control item is of type Program * Format files properly and remove unnecessary lines * Update changepointSteps in context to match js-slang * Implement navigation arrows to jump to next/previous change in environment * update changepointSteps in context 2 * Format code * Update changpointSteps in context to match js-slang 3 * Revert unintentional lockfile change * Resolve conflict * please do not remove config files * Fix format * Fix merging mistakes --------- Co-authored-by: NhatMinh0208 --- src/commons/application/ApplicationTypes.ts | 2 ++ .../sagas/WorkspaceSaga/helpers/evalCode.ts | 4 +++ src/commons/sagas/__tests__/PlaygroundSaga.ts | 18 ++++++---- .../content/SideContentCseMachine.tsx | 33 +++++++++++++++++-- src/commons/workspace/WorkspaceActions.ts | 8 +++++ src/commons/workspace/WorkspaceReducer.ts | 9 +++++ src/commons/workspace/WorkspaceTypes.ts | 2 ++ .../workspace/__tests__/WorkspaceReducer.ts | 3 +- 8 files changed, 70 insertions(+), 9 deletions(-) diff --git a/src/commons/application/ApplicationTypes.ts b/src/commons/application/ApplicationTypes.ts index fe9393a1df..603ff84c07 100644 --- a/src/commons/application/ApplicationTypes.ts +++ b/src/commons/application/ApplicationTypes.ts @@ -413,6 +413,7 @@ export const defaultWorkspaceManager: WorkspaceManagerState = { currentStep: -1, stepsTotal: 0, breakpointSteps: [], + changepointSteps: [], activeEditorTabIndex: 0, editorTabs: [ { @@ -466,6 +467,7 @@ export const defaultWorkspaceManager: WorkspaceManagerState = { currentStep: -1, stepsTotal: 0, breakpointSteps: [], + changepointSteps: [], activeEditorTabIndex: 0, editorTabs: [ { diff --git a/src/commons/sagas/WorkspaceSaga/helpers/evalCode.ts b/src/commons/sagas/WorkspaceSaga/helpers/evalCode.ts index 946f643146..b2cb236a16 100644 --- a/src/commons/sagas/WorkspaceSaga/helpers/evalCode.ts +++ b/src/commons/sagas/WorkspaceSaga/helpers/evalCode.ts @@ -248,6 +248,9 @@ export function* evalCode( yield put( actions.updateBreakpointSteps(context.runtime.breakpointSteps, workspaceLocation) ); + yield put( + actions.updateChangePointSteps(context.runtime.changepointSteps, workspaceLocation) + ); } } else { // Safe to use ! as storyEnv will be defined from above when we call from EVAL_STORY @@ -315,6 +318,7 @@ export function* evalCode( // But TS can't infer that yet, so we need a typecast here. yield put(actions.toggleUpdateCse(false, workspaceLocation as any)); yield put(actions.updateBreakpointSteps(context.runtime.breakpointSteps, workspaceLocation)); + yield put(actions.updateChangePointSteps(context.runtime.changepointSteps, workspaceLocation)); } // Stop the home icon from flashing for an error if it is doing so since the evaluation is successful if (context.executionMethod === 'cse-machine' || context.executionMethod === 'interpreter') { diff --git a/src/commons/sagas/__tests__/PlaygroundSaga.ts b/src/commons/sagas/__tests__/PlaygroundSaga.ts index a577224d51..56fa53175c 100644 --- a/src/commons/sagas/__tests__/PlaygroundSaga.ts +++ b/src/commons/sagas/__tests__/PlaygroundSaga.ts @@ -87,7 +87,8 @@ describe('Playground saga tests', () => { updateCse: true, currentStep: -1, stepsTotal: 0, - breakpointSteps: [] + breakpointSteps: [], + changepointSteps: [] } } }; @@ -154,7 +155,8 @@ describe('Playground saga tests', () => { updateCse: true, currentStep: -1, stepsTotal: 0, - breakpointSteps: [] + breakpointSteps: [], + changepointSteps: [] } } }; @@ -221,7 +223,8 @@ describe('Playground saga tests', () => { updateCse: true, currentStep: -1, stepsTotal: 0, - breakpointSteps: [] + breakpointSteps: [], + changepointSteps: [] } } }; @@ -271,7 +274,8 @@ describe('Playground saga tests', () => { updateCse: true, currentStep: -1, stepsTotal: 0, - breakpointSteps: [] + breakpointSteps: [], + changepointSteps: [] } } }; @@ -340,7 +344,8 @@ describe('Playground saga tests', () => { updateCse: true, currentStep: -1, stepsTotal: 0, - breakpointSteps: [] + breakpointSteps: [], + changepointSteps: [] } } }; @@ -398,7 +403,8 @@ describe('Playground saga tests', () => { updateCse: true, currentStep: -1, stepsTotal: 0, - breakpointSteps: [] + breakpointSteps: [], + changepointSteps: [] } } }; diff --git a/src/commons/sideContent/content/SideContentCseMachine.tsx b/src/commons/sideContent/content/SideContentCseMachine.tsx index 39f0a7621c..009c2aec85 100644 --- a/src/commons/sideContent/content/SideContentCseMachine.tsx +++ b/src/commons/sideContent/content/SideContentCseMachine.tsx @@ -50,6 +50,7 @@ type StateProps = { stepsTotal: number; currentStep: number; breakpointSteps: number[]; + changepointSteps: number[]; needCseUpdate: boolean; machineOutput: InterpreterOutput[]; }; @@ -257,12 +258,14 @@ class SideContentCseMachineBase extends React.Component