Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make keyboard nav compatible with v10.2.0 #1990

Merged
merged 1 commit into from
Sep 28, 2023
Merged
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
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