Skip to content

Commit db1d5bd

Browse files
authored
Merge pull request #3473 from paulkaplan/switch-to-code-after-sprite
Make sure to switch back to code when adding new sprites
2 parents 837f99d + 25249f9 commit db1d5bd

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

src/containers/sprite-library.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ class SpriteLibrary extends React.PureComponent {
3939
clearInterval(this.intervalId);
4040
}
4141
handleItemSelect (item) {
42-
this.props.vm.addSprite(JSON.stringify(item.json));
42+
this.props.vm.addSprite(JSON.stringify(item.json)).then(() => {
43+
this.props.onActivateBlocksTab();
44+
});
4345
analytics.event({
4446
category: 'library',
4547
action: 'Select Sprite',
@@ -95,6 +97,7 @@ class SpriteLibrary extends React.PureComponent {
9597

9698
SpriteLibrary.propTypes = {
9799
intl: intlShape.isRequired,
100+
onActivateBlocksTab: PropTypes.func.isRequired,
98101
onRequestClose: PropTypes.func,
99102
vm: PropTypes.instanceOf(VM).isRequired
100103
};

src/containers/target-pane.jsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
closeSpriteLibrary
1010
} from '../reducers/modals';
1111

12-
import {activateTab, COSTUMES_TAB_INDEX} from '../reducers/editor-tab';
12+
import {activateTab, COSTUMES_TAB_INDEX, BLOCKS_TAB_INDEX} from '../reducers/editor-tab';
1313
import {setReceivedBlocks} from '../reducers/hovered-target';
1414
import {setRestore} from '../reducers/restore-deletion';
1515
import DragConstants from '../lib/drag-constants';
@@ -23,6 +23,7 @@ class TargetPane extends React.Component {
2323
constructor (props) {
2424
super(props);
2525
bindAll(this, [
26+
'handleActivateBlocksTab',
2627
'handleBlockDragEnd',
2728
'handleChangeSpriteRotationStyle',
2829
'handleChangeSpriteDirection',
@@ -72,7 +73,9 @@ class TargetPane extends React.Component {
7273
this.props.vm.postSpriteInfo({y});
7374
}
7475
handleDeleteSprite (id) {
75-
const restoreFun = this.props.vm.deleteSprite(id);
76+
const restoreSprite = this.props.vm.deleteSprite(id);
77+
const restoreFun = () => restoreSprite().then(this.handleActivateBlocksTab);
78+
7679
this.props.dispatchUpdateRestore({
7780
restoreFun: restoreFun,
7881
deletedItem: 'Sprite'
@@ -109,7 +112,8 @@ class TargetPane extends React.Component {
109112
}
110113
handleSurpriseSpriteClick () {
111114
const item = spriteLibraryContent[Math.floor(Math.random() * spriteLibraryContent.length)];
112-
this.props.vm.addSprite(JSON.stringify(item.json));
115+
this.props.vm.addSprite(JSON.stringify(item.json))
116+
.then(this.handleActivateBlocksTab);
113117
}
114118
handlePaintSpriteClick () {
115119
const formatMessage = this.props.intl.formatMessage;
@@ -124,8 +128,12 @@ class TargetPane extends React.Component {
124128
});
125129
});
126130
}
131+
handleActivateBlocksTab () {
132+
this.props.onActivateTab(BLOCKS_TAB_INDEX);
133+
}
127134
handleNewSprite (spriteJSONString) {
128-
this.props.vm.addSprite(spriteJSONString);
135+
this.props.vm.addSprite(spriteJSONString)
136+
.then(this.handleActivateBlocksTab);
129137
}
130138
handleFileUploadClick () {
131139
this.fileInput.click();

test/integration/sprites.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe('Working with sprites', () => {
3333
await clickXpath('//button[@aria-label="Choose a Sprite"]');
3434
await clickText('Apple', scope.modal); // Closes modal
3535
await rightClickText('Apple', scope.spriteTile); // Make sure it is there
36+
await findByText('Motion'); // Make sure we are back to the code tab
3637
const logs = await getLogs();
3738
await expect(logs).toEqual([]);
3839
});
@@ -49,6 +50,19 @@ describe('Working with sprites', () => {
4950
await expect(logs).toEqual([]);
5051
});
5152

53+
test('Adding a sprite by paint button', async () => {
54+
await loadUri(uri);
55+
await clickXpath('//button[@title="Try It"]');
56+
const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
57+
await driver.actions().mouseMove(el)
58+
.perform();
59+
await driver.sleep(500); // Wait for thermometer menu to come up
60+
await clickXpath('//button[@aria-label="Paint"]');
61+
await findByText('Convert to Bitmap'); // Make sure we are on the paint editor
62+
const logs = await getLogs();
63+
await expect(logs).toEqual([]);
64+
});
65+
5266
test('Deleting only sprite does not crash', async () => {
5367
await loadUri(uri);
5468
await clickXpath('//button[@title="Try It"]');

0 commit comments

Comments
 (0)