Skip to content

fix: only hide WidgetDiv when its owner is in the given workspace - #10633

Merged
zspriggs merged 3 commits into
RaspberryPiFoundation:mainfrom
ritfiz:fix/widgetdiv-hide-ownership-check
Oct 29, 2026
Merged

zspriggs merged 3 commits into
RaspberryPiFoundation:mainfrom
ritfiz:fix/widgetdiv-hide-ownership-check

Conversation

@ritfiz

@ritfiz ritfiz commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

The basics

The details

Resolves

Fixes #10429

Proposed Changes

  • fixed the ownership check
  • adds tests

Reason for Changes

Blockly uses a single shared WidgetDiv for the whole page, and whichever text editor is open lives inside it.

When you edit a number and press Tab, the value is saved and the editor opens on the next field. If the minimap is on, it replicates the change and calls zoomToFit(), which internally calls hideChaff() to close any open popups.

hideChaff() is supposed to close the WidgetDiv only if it belongs to that workspace (via WidgetDiv.hideIfOwnerIsInWorkspace), but that ownership check is broken and always passes. So the minimap closes the editor that just opened on the main workspace.

Test Coverage

  • test for checking ownership of widgetdiv before closing
  • regression test for minimap open and tab pressed
  • new tests fail without the fix and pass with the fix
  • checked manually in the browser
  • adding screenshots too

Before

failing tests regression test -master

After

passsing tests regression test - pr

Screen recording

Before

On branch master

20261027001607.mp4

After

On this MR

20261027001113.mp4

Documentation

None

Additional Information

AI helped in finding the root cause, fixing and testing the app.

The minimap test is based on RaspberryPiFoundation/blockly-samples#2768.

🤖 Generated with Claude Code

ritfiz and others added 2 commits October 26, 2026 23:21
hideIfOwnerIsInWorkspace started its parent walk from the workspace being
checked instead of the owner's workspace, so the check always passed and
any workspace's hideChaff() closed the WidgetDiv. With the minimap plugin,
its zoomToFit() closed the field editor that Tab had just opened.

Fixes RaspberryPiFoundation#10429

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ritfiz
ritfiz requested a review from a team as a code owner October 26, 2026 17:07
@ritfiz
ritfiz requested a review from zspriggs October 26, 2026 17:07
@github-actions github-actions Bot added PR: fix Fixes a bug and removed PR: fix Fixes a bug labels Oct 26, 2026
});
// jsdom does not implement CSS.escape, which keyboard navigation uses to
// look up elements by ID.
global.CSS = {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically doing a tab on a keyboard, tries to use the querySelector('#' + escaped) to find the next tab-able input. without this, an id starting with numbers or having characters like @ would throw invalid selector error. A bit of overengineering because blockly produces ids.
otherwise even escape: (s) => s would have worked

let currentWorkspace: WorkspaceSvg | null = workspace;
let currentWorkspace: WorkspaceSvg | null = ownerWorkspace;
while (!ownerIsInWorkspace && currentWorkspace) {
if (currentWorkspace === workspace) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check was always true first time as the currentWorkspace was workspace only because of the assignment on line 262. Thus an ownership check would always return true

@ritfiz ritfiz mentioned this pull request Oct 26, 2026
1 task done

@zspriggs zspriggs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this! The changes you've made in widgetdiv.ts look good and the tests in widget_div_test.ts seem reasonable.

However, the behavior you're testing in minimap_tests.mocha.js is pretty well covered by the other tests you've added. Also, although it works generally, the CSS.escape setup may end up being flaky. So for this small change, the core tests are sufficient and you can revert the additions to minimap_tests.mocha.js.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ritfiz

ritfiz commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for tackling this! The changes you've made in widgetdiv.ts look good and the tests in widget_div_test.ts seem reasonable.

However, the behavior you're testing in minimap_tests.mocha.js is pretty well covered by the other tests you've added. Also, although it works generally, the CSS.escape setup may end up being flaky. So for this small change, the core tests are sufficient and you can revert the additions to minimap_tests.mocha.js.

@zspriggs - The minimap test changes are reverted now, please re-review. Thank you !

@zspriggs zspriggs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, thanks for making those changes.

@zspriggs
zspriggs merged commit 8eeb652 into RaspberryPiFoundation:main Oct 29, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: fix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Minimap affecting focus

2 participants