Skip to content

Focus selected Blockly block on Ctrl+E before activating keyboard navigation#576

Open
tracygardner wants to merge 4 commits intomainfrom
codex/fix-focus-outline-for-select-and-duplicate-gizmos
Open

Focus selected Blockly block on Ctrl+E before activating keyboard navigation#576
tracygardner wants to merge 4 commits intomainfrom
codex/fix-focus-outline-for-select-and-duplicate-gizmos

Conversation

@tracygardner
Copy link
Copy Markdown
Contributor

@tracygardner tracygardner commented Apr 27, 2026

Motivation

  • Improve keyboard accessibility by focusing the currently highlighted Blockly block when the user presses Ctrl+E, avoiding unnecessary activation of the global keyboard navigation and preventing loss of cursor position.

Description

  • Added focusHighlightedBlock(workspace = Blockly.getMainWorkspace()) to ui/blocklyutil.js which attempts to focus and select the currently selected/highlighted block, moves the workspace cursor to it, and returns a boolean indicating success.
  • Updated main/main.js to import focusHighlightedBlock and call it in the Ctrl+E keyboard handler, falling back to the previous Blockly.keyboardNavigationController and focusTree behavior only if no highlighted block could be focused.
  • The new focus routine uses safe feature checks and preventScroll to avoid unwanted scrolling when moving focus.

Testing

  • Ran npm test (frontend unit tests) which completed successfully.
  • Ran npm run build to verify the bundle and compilation, which succeeded.

Codex Task

Summary by CodeRabbit

  • New Features
    • Improved Ctrl+E keyboard shortcut with enhanced focus navigation. When a block is highlighted in the Blockly workspace, the shortcut now focuses directly on that block. When no block is highlighted, the shortcut defaults to standard navigation behavior, providing a consistent and intuitive keyboard experience.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

Warning

Rate limit exceeded

@tracygardner has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 21 minutes and 34 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7f1ce25d-8a32-4d40-8d87-f639d5ec265d

📥 Commits

Reviewing files that changed from the base of the PR and between 7e77f5d and 853e37a.

📒 Files selected for processing (1)
  • ui/blocklyutil.js
📝 Walkthrough

Walkthrough

This PR adds a new utility function focusHighlightedBlock to programmatically focus selected Blockly blocks, and modifies the Ctrl+E keyboard shortcut handler to use this function, conditionally bypassing keyboard navigation fallbacks when a block is successfully focused.

Changes

Cohort / File(s) Summary
Blockly Focus Utility
ui/blocklyutil.js
Added focusHighlightedBlock function that focuses the currently selected block within a workspace. Internally uses Blockly's FocusManager, selection, and cursor APIs to locate and focus the block's focusable DOM element with scroll prevention.
Keyboard Shortcut Handler
main/main.js
Updated Ctrl+E shortcut logic to conditionally invoke focusHighlightedBlock first; suppresses legacy keyboardNavigationController activation and focusTree fallback when a highlighted block is successfully focused, preserving prior behavior otherwise.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 With Ctrl+E and a hop-skip-jump,
Blockly blocks no longer slump!
Focus flows where highlights gleam,
A programmer's focused keyboard dream! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding focus to the selected Blockly block on Ctrl+E before activating keyboard navigation, which is directly supported by the code changes in both files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-focus-outline-for-select-and-duplicate-gizmos

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 27, 2026

Deploying flockxr with  Cloudflare Pages  Cloudflare Pages

Latest commit: 853e37a
Status: ✅  Deploy successful!
Preview URL: https://e0fdf0db.flockxr.pages.dev
Branch Preview URL: https://codex-fix-focus-outline-for.flockxr.pages.dev

View logs

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ui/blocklyutil.js`:
- Around line 75-76: selectedBlock returned from Blockly.common.getSelected()
can be ICopyable or null, so accessing selectedBlock.workspace is unsafe; update
the check in the code that uses selectedBlock (the variable and the call to
Blockly.common.getSelected()) to first narrow the type to a BlockSvg (e.g.,
verify the object has block-specific shape or instanceof BlockSvg or check for
the presence of .workspace and other block-only properties) before comparing its
.workspace to workspace, and return false if the selected object is not a block.
- Around line 72-89: The function focusHighlightedBlock currently returns true
when a selected block exists even if no DOM element was focused; update it so it
only returns true when a real DOM focus was applied: locate
focusHighlightedBlock and compute focusableElement via
selectedBlock.getFocusableElement?.() || selectedBlock.getSvgRoot?.() before
returning, call focusableElement?.focus?.({ preventScroll: true }) and only
return true if focusableElement was non-null (and focus was invoked); keep
existing calls to Blockly.keyboardNavigationController?.setIsActive,
Blockly.getFocusManager()?.focusNode, selectedBlock.select, and
workspace.getCursor()?.setCurNode, but change the final return to false when no
focusableElement was found so callers (e.g., focusTree(workspace)) can run
fallback logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e77b540b-345b-4d5e-ac97-314c1f7ca5c6

📥 Commits

Reviewing files that changed from the base of the PR and between 595b03f and 7e77f5d.

📒 Files selected for processing (2)
  • main/main.js
  • ui/blocklyutil.js

Comment thread ui/blocklyutil.js Outdated
Comment thread ui/blocklyutil.js Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant