@@ -25,6 +25,7 @@ import {
2525import { setCustomStageSize } from '../reducers/custom-stage-size' ;
2626import { openUnknownPlatformModal } from '../reducers/modals' ;
2727import implementGuiAPI from './tw-extension-gui-api' ;
28+ import { BLOCKS_TAB_INDEX } from '../reducers/editor-tab' ;
2829
2930let compileErrorCounter = 0 ;
3031
@@ -176,6 +177,23 @@ const vmListenerHOC = function (WrappedComponent) {
176177 if ( e . keyCode === 8 ) {
177178 e . preventDefault ( ) ;
178179 }
180+
181+ // TW: prevent delete and backspace from deleting blocks in the editor while in fullscreen
182+ // or in the editor too if the project has been using these keys for something
183+ const blockEditorDeleteOperation = scratchKey => (
184+ this . props . isEditorObscured || (
185+ this . props . isEditorUsable &&
186+ this . props . vm . runtime . ioDevices . keyboard . hasUsedKey ( scratchKey )
187+ )
188+ ) ;
189+ if (
190+ ( e . keyCode === 8 && blockEditorDeleteOperation ( 'backspace' ) ) ||
191+ ( e . keyCode === 46 && blockEditorDeleteOperation ( 'delete' ) )
192+ ) {
193+ e . stopPropagation ( ) ;
194+ e . stopImmediatePropagation ( ) ;
195+ }
196+
179197 // tw: prevent ' and / from opening quick find in Firefox
180198 if ( e . keyCode === 222 || e . keyCode === 191 ) {
181199 e . preventDefault ( ) ;
@@ -200,6 +218,8 @@ const vmListenerHOC = function (WrappedComponent) {
200218 const {
201219 /* eslint-disable no-unused-vars */
202220 attachKeyboardEvents,
221+ isEditorObscured,
222+ isEditorUsable,
203223 projectChanged,
204224 shouldUpdateTargets,
205225 shouldUpdateProjectChanged,
@@ -237,6 +257,8 @@ const vmListenerHOC = function (WrappedComponent) {
237257 }
238258 VMListener . propTypes = {
239259 attachKeyboardEvents : PropTypes . bool ,
260+ isEditorObscured : PropTypes . bool . isRequired ,
261+ isEditorUsable : PropTypes . bool . isRequired ,
240262 onBlockDragUpdate : PropTypes . func . isRequired ,
241263 onGreenFlag : PropTypes . func ,
242264 onKeyDown : PropTypes . func ,
@@ -275,6 +297,15 @@ const vmListenerHOC = function (WrappedComponent) {
275297 } ;
276298 const mapStateToProps = state => ( {
277299 hasCloudVariables : state . scratchGui . tw . hasCloudVariables ,
300+ isEditorObscured : (
301+ ! state . scratchGui . mode . isPlayerOnly &&
302+ state . scratchGui . mode . isFullScreen
303+ ) ,
304+ isEditorUsable : (
305+ ! state . scratchGui . mode . isPlayerOnly &&
306+ ! state . scratchGui . mode . isFullScreen &&
307+ state . scratchGui . editorTab . activeTabIndex === BLOCKS_TAB_INDEX
308+ ) ,
278309 projectChanged : state . scratchGui . projectChanged ,
279310 // Do not emit target or project updates in fullscreen or player only mode
280311 // or when recording sounds (it leads to garbled recordings on low-power machines)
0 commit comments