fix: check for a drag specifically rather than a gesture for shortcuts (#9194)

This commit is contained in:
Maribeth Moffatt
2025-07-07 09:49:38 -07:00
committed by GitHub
parent 7ad18f717a
commit efb5a2e7f1
2 changed files with 11 additions and 12 deletions

View File

@@ -11,7 +11,6 @@ import * as clipboard from './clipboard.js';
import {RenderedWorkspaceComment} from './comments.js'; import {RenderedWorkspaceComment} from './comments.js';
import * as eventUtils from './events/utils.js'; import * as eventUtils from './events/utils.js';
import {getFocusManager} from './focus_manager.js'; import {getFocusManager} from './focus_manager.js';
import {Gesture} from './gesture.js';
import {ICopyData, isCopyable as isICopyable} from './interfaces/i_copyable.js'; import {ICopyData, isCopyable as isICopyable} from './interfaces/i_copyable.js';
import {isDeletable as isIDeletable} from './interfaces/i_deletable.js'; import {isDeletable as isIDeletable} from './interfaces/i_deletable.js';
import {isDraggable} from './interfaces/i_draggable.js'; import {isDraggable} from './interfaces/i_draggable.js';
@@ -67,7 +66,7 @@ export function registerDelete() {
focused != null && focused != null &&
isIDeletable(focused) && isIDeletable(focused) &&
focused.isDeletable() && focused.isDeletable() &&
!Gesture.inProgress() && !workspace.isDragging() &&
// Don't delete the block if a field editor is open // Don't delete the block if a field editor is open
!getFocusManager().ephemeralFocusTaken() !getFocusManager().ephemeralFocusTaken()
); );
@@ -322,7 +321,7 @@ export function registerUndo() {
preconditionFn(workspace) { preconditionFn(workspace) {
return ( return (
!workspace.isReadOnly() && !workspace.isReadOnly() &&
!Gesture.inProgress() && !workspace.isDragging() &&
!getFocusManager().ephemeralFocusTaken() !getFocusManager().ephemeralFocusTaken()
); );
}, },
@@ -360,7 +359,7 @@ export function registerRedo() {
name: names.REDO, name: names.REDO,
preconditionFn(workspace) { preconditionFn(workspace) {
return ( return (
!Gesture.inProgress() && !workspace.isDragging() &&
!workspace.isReadOnly() && !workspace.isReadOnly() &&
!getFocusManager().ephemeralFocusTaken() !getFocusManager().ephemeralFocusTaken()
); );

View File

@@ -434,13 +434,13 @@ suite('Keyboard Shortcut Items', function () {
}); });
}); });
}); });
// Do not undo if a gesture is in progress. // Do not undo if a drag is in progress.
suite('Gesture in progress', function () { suite('Drag in progress', function () {
testCases.forEach(function (testCase) { testCases.forEach(function (testCase) {
const testCaseName = testCase[0]; const testCaseName = testCase[0];
const keyEvent = testCase[1]; const keyEvent = testCase[1];
test(testCaseName, function () { test(testCaseName, function () {
sinon.stub(Blockly.Gesture, 'inProgress').returns(true); sinon.stub(this.workspace, 'isDragging').returns(true);
this.injectionDiv.dispatchEvent(keyEvent); this.injectionDiv.dispatchEvent(keyEvent);
sinon.assert.notCalled(this.undoSpy); sinon.assert.notCalled(this.undoSpy);
sinon.assert.notCalled(this.hideChaffSpy); sinon.assert.notCalled(this.hideChaffSpy);
@@ -494,13 +494,13 @@ suite('Keyboard Shortcut Items', function () {
}); });
}); });
}); });
// Do not undo if a gesture is in progress. // Do not redo if a drag is in progress.
suite('Gesture in progress', function () { suite('Drag in progress', function () {
testCases.forEach(function (testCase) { testCases.forEach(function (testCase) {
const testCaseName = testCase[0]; const testCaseName = testCase[0];
const keyEvent = testCase[1]; const keyEvent = testCase[1];
test(testCaseName, function () { test(testCaseName, function () {
sinon.stub(Blockly.Gesture, 'inProgress').returns(true); sinon.stub(this.workspace, 'isDragging').returns(true);
this.injectionDiv.dispatchEvent(keyEvent); this.injectionDiv.dispatchEvent(keyEvent);
sinon.assert.notCalled(this.redoSpy); sinon.assert.notCalled(this.redoSpy);
sinon.assert.notCalled(this.hideChaffSpy); sinon.assert.notCalled(this.hideChaffSpy);
@@ -534,8 +534,8 @@ suite('Keyboard Shortcut Items', function () {
sinon.assert.calledWith(this.undoSpy, true); sinon.assert.calledWith(this.undoSpy, true);
sinon.assert.calledOnce(this.hideChaffSpy); sinon.assert.calledOnce(this.hideChaffSpy);
}); });
test('Not called when a gesture is in progress', function () { test('Not called when a drag is in progress', function () {
sinon.stub(Blockly.Gesture, 'inProgress').returns(true); sinon.stub(this.workspace, 'isDragging').returns(true);
this.injectionDiv.dispatchEvent(this.ctrlYEvent); this.injectionDiv.dispatchEvent(this.ctrlYEvent);
sinon.assert.notCalled(this.undoSpy); sinon.assert.notCalled(this.undoSpy);
sinon.assert.notCalled(this.hideChaffSpy); sinon.assert.notCalled(this.hideChaffSpy);