Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/keyboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ follows.
| Ctrl + Alt + b | addCommandToBeginning |
| Ctrl + Alt + e | addCommandToEnd |
| Ctrl + Alt + d | deleteCurrentStep |
| Ctrl + Alt + l | deleteLastStep |
| Ctrl + Alt + i | announceScene |
| Ctrl + Alt + p | playPauseProgram |
| Ctrl + Alt + r | refreshScene |
Expand Down Expand Up @@ -85,6 +86,7 @@ with the starting key of a sequence. Those key bindings are as follows:
| Alt + b | addCommandToBeginning |
| Alt + e | addCommandToEnd |
| Alt + d | deleteCurrentStep |
| Alt + l | deleteLastStep |
| Alt + i | announceScene |
| Alt + p | playPauseProgram |
| Alt + r | refreshScene |
Expand Down
5 changes: 5 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,11 @@ export class App extends React.Component<AppProps, AppState> {
}
}
break;
case("deleteLastStep"):
if (!this.editingIsDisabled()) {
this.programChangeController.deleteLastStep(this.programBlockEditorRef.current);
}
break;
case("deleteAll"): {
if (!this.editingIsDisabled()) {
const newProgramSequence = this.state.programSequence.updateProgram([]);
Expand Down
9 changes: 9 additions & 0 deletions src/KeyboardInputSchemes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type ActionName =
| "addCommandToBeginning"
| "addCommandToEnd"
| "deleteCurrentStep"
| "deleteLastStep"
| "announceScene"
| "decreaseProgramSpeed"
| "increaseProgramSpeed"
Expand Down Expand Up @@ -294,6 +295,10 @@ const AltInputScheme: KeyboardInputScheme = Object.assign({
keyDef: { code: "KeyD", key: "d", altKey: true},
actionName: "deleteCurrentStep"
},
deleteLastStep: {
keyDef: { code: "KeyL", key: "l", altKey: true},
actionName: "deleteLastStep"
},
announceScene: {
keyDef: { code: "KeyI", key: "i", altKey: true},
actionName: "announceScene"
Expand Down Expand Up @@ -359,6 +364,10 @@ const ControlAltInputScheme = Object.assign({
keyDef: { code: "KeyD", key: "d", altKey: true, ctrlKey: true},
actionName: "deleteCurrentStep"
},
deleteLastStep: {
keyDef: { code: "KeyL", key: "l", altKey: true, ctrlKey: true},
actionName: "deleteLastStep"
},
announceScene: {
keyDef: {code: "KeyI", key: "i", altKey: true, ctrlKey: true},
actionName: "announceScene"
Expand Down
43 changes: 32 additions & 11 deletions src/ProgramChangeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,7 @@ export default class ProgramChangeController {
// Check that the step to delete hasn't changed since the
// user made the deletion
if (command === state.programSequence.getProgramStepAt(index)) {
// Play the announcement
const commandString = this.intl.formatMessage({
id: "Announcement." + command
});
this.audioManager.playAnnouncement(
'delete',
this.intl,
{ command: commandString }
);
this.playAnnouncementForDelete(command);

// If there are steps following the one being deleted, focus
// the next step. Otherwise, focus the final add node.
Expand All @@ -94,14 +86,43 @@ export default class ProgramChangeController {
});
}

deleteLastStep(programBlockEditor: ?ProgramBlockEditor) {
this.app.setState((state) => {
const index = state.programSequence.getProgramLength() - 1;
if (index >= 0) {
const command = state.programSequence.getProgramStepAt(index);
this.playAnnouncementForDelete(command);

// As we are deleting the last step, focus the final add node.
if (programBlockEditor) {
programBlockEditor.focusAddNodeAfterUpdate(index);
}

return {
programSequence: state.programSequence.deleteStep(index)
};
} else {
return {};
}
});
}

// Internal methods

playAnnouncementForAdd(command: string) {
this.playAnnouncementForChange(command, 'add');
}

playAnnouncementForDelete(command:string) {
this.playAnnouncementForChange(command, 'delete');
}

playAnnouncementForChange(command:string, changeType: string) {
const commandString = this.intl.formatMessage({
id: "Announcement." + (command || "")
id: "Announcement." + command
});
this.audioManager.playAnnouncement(
'add',
changeType,
this.intl,
{ command: commandString }
);
Expand Down
40 changes: 40 additions & 0 deletions src/ProgramChangeController.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,43 @@ describe('Test deleteProgramStep()', () => {
});

});

describe('Test deleteLastStep()', () => {
test('When deleting the last step, then focus is set to the add-node after the program', (done) => {
expect.assertions(7);

const { controller, appMock, audioManagerMock } = createProgramChangeController();

appMock.setState.mockImplementation((callback) => {
const newState = callback({
programSequence: new ProgramSequence(['forward1', 'forward2'], 0)
});

// The program should be updated
expect(newState.programSequence.getProgram()).toStrictEqual(
['forward1']);

// The announcement should be made
expect(audioManagerMock.playAnnouncement.mock.calls.length).toBe(1);
expect(audioManagerMock.playAnnouncement.mock.calls[0][0]).toBe('delete');
expect(audioManagerMock.playAnnouncement.mock.calls[0][2]).toStrictEqual({
command: 'forward 2 squares'
});

// The add-node after the program should be focused
// $FlowFixMe: Jest mock API
const programBlockEditorMock = ProgramBlockEditor.mock.instances[0];
expect(programBlockEditorMock.focusCommandBlockAfterUpdate.mock.calls.length).toBe(0);
expect(programBlockEditorMock.focusAddNodeAfterUpdate.mock.calls.length).toBe(1);
expect(programBlockEditorMock.focusAddNodeAfterUpdate.mock.calls[0][0]).toBe(1);

done();
});

// $FlowFixMe: Jest mock API
ProgramBlockEditor.mockClear();
// $FlowFixMe: Jest mock API
controller.deleteLastStep(new ProgramBlockEditor());
});
});