Skip to content

Commit

Permalink
fix: make keyboard nav compatible with v10.2.0 (#1990)
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega authored Sep 28, 2023
1 parent a4509e0 commit e0915b3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
17 changes: 16 additions & 1 deletion plugins/keyboard-navigation/src/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,22 @@ export class Navigation {
// other block when they are connected.
if (!destConnection.isSuperior()) {
const rootBlock = movingBlock.getRootBlock();
rootBlock.positionNearConnection(movingConnection, destConnection);

// DO NOT DO CHECKS BASED ON BLOCKLY VERSION.
// We have to do this because are calling an internal method, which we
// should not be doing.
if (/** @type {string} */ (Blockly.VERSION) === '10.2.0') {
const originalOffsetToTarget = {
x: destConnection.x - movingConnection.x,
y: destConnection.y - movingConnection.y,
};
const originalOffsetInBlock =
movingConnection.getOffsetInBlock().clone();
rootBlock.positionNearConnection(
movingConnection, originalOffsetToTarget, originalOffsetInBlock);
} else {
rootBlock.positionNearConnection(movingConnection, destConnection);
}
}
destConnection.connect(movingConnection);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ suite('Insert/Modify', function() {
setup(function() {
this.jsdomCleanup =
require('jsdom-global')('<!DOCTYPE html><div id="blocklyDiv"></div>');
// We are running these tests in node even thought they require a rendered
// workspace, which doesn't exactly work. The rendering system expects
// cancelAnimationFrame to be defined so we need to define it.
window.cancelAnimationFrame = function() {};

// NOTE: block positions chosen such that they aren't unintentionally
// bumped out of bounds during tests.
const xmlText = `<xml xmlns="https://developers.google.com/blockly/xml">
Expand Down Expand Up @@ -116,6 +121,7 @@ suite('Insert/Modify', function() {
delete Blockly.Blocks['stack_block'];
delete Blockly.Blocks['row_block'];
delete Blockly.Blocks['statement_block'];
window.cancelAnimationFrame = undefined;
this.jsdomCleanup();
});

Expand Down
5 changes: 5 additions & 0 deletions plugins/keyboard-navigation/test/navigation_test.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ suite('Navigation', function() {
setup(function() {
this.jsdomCleanup =
require('jsdom-global')('<!DOCTYPE html><div id="blocklyDiv"></div>');
// We are running these tests in node even thought they require a rendered
// workspace, which doesn't exactly work. The rendering system expects
// cancelAnimationFrame to be defined so we need to define it.
window.cancelAnimationFrame = function() {};
this.controller = new NavigationController();
this.controller.init();
this.navigation = this.controller.navigation;
});

teardown(function() {
this.controller.dispose();
window.cancelAnimationFrame = undefined;
this.jsdomCleanup();
});

Expand Down

0 comments on commit e0915b3

Please sign in to comment.