Skip to content

Add OverlayMetricsManager to avoid workspace shift when flyout is open#508

Open
tracygardner wants to merge 3 commits intomainfrom
codex/locate-toolbox-workaround-implementation
Open

Add OverlayMetricsManager to avoid workspace shift when flyout is open#508
tracygardner wants to merge 3 commits intomainfrom
codex/locate-toolbox-workaround-implementation

Conversation

@tracygardner
Copy link
Copy Markdown
Contributor

@tracygardner tracygardner commented Apr 5, 2026

Motivation

  • Prevent workspace content from shifting when a non-auto-closing flyout (overlay) is visible by computing workspace metrics that exclude the flyout area instead of mutating translation behavior.

Description

  • Add OverlayMetricsManager (subclass of Blockly.MetricsManager) that overrides getAbsoluteMetrics and getViewMetrics to adjust metrics when the flyout is visible and autoClose is false, taking toolbox position and workspace scale into account.
  • Install the custom metrics manager via workspace.setMetricsManager(new OverlayMetricsManager(workspace)) immediately after Blockly.inject.
  • Remove the previous simpleNoBumpTranslate monkeypatch that altered workspace.translate to remove the flyout-width bump.

Testing

  • No automated tests were added or run for this change.

Codex Task

Summary by CodeRabbit

  • Bug Fixes
    • Workspace metrics now account for visible toolbox overlays and toolbox position, improving element placement and spacing.
    • Avoids metric shrinking when overlay/toolbox dimensions fluctuate by tracking stable toolbox size.
    • Removes prior panning/workspace-translation workaround that could cause incorrect horizontal limits and offsets.

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

cloudflare-workers-and-pages bot commented Apr 5, 2026

Deploying flockdev with  Cloudflare Pages  Cloudflare Pages

Latest commit: a361e5e
Status: ✅  Deploy successful!
Preview URL: https://c01e7cc8.flockdev.pages.dev
Branch Preview URL: https://codex-locate-toolbox-workaro.flockdev.pages.dev

View logs

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 5, 2026

Warning

Rate limit exceeded

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

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 6 minutes and 57 seconds.

⌛ 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: 692da722-56fd-4520-9185-19b229fce617

📥 Commits

Reviewing files that changed from the base of the PR and between cb7a8e4 and a361e5e.

📒 Files selected for processing (1)
  • main/blocklyinit.js
📝 Walkthrough

Walkthrough

Replaces a workspace translate monkey-patch with a new OverlayMetricsManager (subclass of Blockly.MetricsManager) that adjusts reported absolute and view metrics to account for a visible toolbox flyout overlay using flyout dimensions and toolbox position; skips adjustments when flyout missing or autoClose is enabled.

Changes

Cohort / File(s) Summary
Metrics Manager
main/blocklyinit.js
Added OverlayMetricsManager subclass overriding getAbsoluteMetrics() and getViewMetrics() to expand/offset workspace bounds based on flyout dimensions and toolbox position (LEFT/TOP/RIGHT/BOTTOM). Removed previous workspace translate monkey-patch that handled flyout-width compensation and left-edge limiting.

Sequence Diagram(s)

sequenceDiagram
    participant Workspace
    participant OverlayMetricsManager
    participant Flyout
    participant Toolbox

    Workspace->>OverlayMetricsManager: getAbsoluteMetrics()
    OverlayMetricsManager->>Flyout: Check existence, visibility, autoClose, dimensions
    OverlayMetricsManager->>Toolbox: Query position (LEFT/TOP/RIGHT/BOTTOM)
    alt Flyout present and not autoClose
        OverlayMetricsManager->>OverlayMetricsManager: Compute offsets / stable toolbox metrics
        OverlayMetricsManager-->>Workspace: Return adjusted absolute metrics
    else
        OverlayMetricsManager-->>Workspace: Return original absolute metrics
    end

    Workspace->>OverlayMetricsManager: getViewMetrics()
    OverlayMetricsManager->>Flyout: Get scaled/visible dimensions
    OverlayMetricsManager->>Toolbox: Get position
    alt Flyout present and not autoClose
        OverlayMetricsManager->>OverlayMetricsManager: Expand/offset view bounds by scaled flyout size
        OverlayMetricsManager-->>Workspace: Return adjusted view metrics
    else
        OverlayMetricsManager-->>Workspace: Return original view metrics
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped in to mend the view,

I tucked the flyout into place, too,
No more odd panning in a race,
Metrics snug, toolbox in its space,
Hop — the workspace finds its grace.

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 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: replacing the old simpleNoBumpTranslate monkey-patch with a new OverlayMetricsManager to prevent workspace shifts when the flyout is open.

✏️ 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/locate-toolbox-workaround-implementation

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.

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: 1

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

Inline comments:
In `@main/blocklyinit.js`:
- Around line 615-617: The code assumes getToolboxMetrics() always returns an
object and immediately accesses .position, which can throw if there's no
toolbox; modify the logic around the toolboxPosition assignment in
blocklyinit.js to first call const toolboxMetrics = this.getToolboxMetrics() and
check for null/undefined before reading toolboxMetrics.position (e.g., set
toolboxPosition to null or a sensible default when toolboxMetrics is falsy), and
ensure subsequent use of toolboxPosition and Blockly.utils.toolbox.Position
handles the missing-toolbox case.
🪄 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: fe502719-4a68-45ac-81a7-9f59f5a33fd4

📥 Commits

Reviewing files that changed from the base of the PR and between 994d440 and 62547d8.

📒 Files selected for processing (1)
  • main/blocklyinit.js

Comment on lines +615 to +617
const flyoutMetrics = this.getFlyoutMetrics();
const toolboxPosition = this.getToolboxMetrics().position;
const Position = Blockly.utils.toolbox.Position;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Potential null access if toolbox is absent.

If getToolboxMetrics() returns null (e.g., workspace without a toolbox), accessing .position will throw. Consider guarding:

 const flyoutMetrics = this.getFlyoutMetrics();
 const toolboxPosition = this.getToolboxMetrics().position;
+const toolboxMetrics = this.getToolboxMetrics();
+if (!toolboxMetrics) return absolute;
+const toolboxPosition = toolboxMetrics.position;

This is a minor edge case but worth defensive handling.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@main/blocklyinit.js` around lines 615 - 617, The code assumes
getToolboxMetrics() always returns an object and immediately accesses .position,
which can throw if there's no toolbox; modify the logic around the
toolboxPosition assignment in blocklyinit.js to first call const toolboxMetrics
= this.getToolboxMetrics() and check for null/undefined before reading
toolboxMetrics.position (e.g., set toolboxPosition to null or a sensible default
when toolboxMetrics is falsy), and ensure subsequent use of toolboxPosition and
Blockly.utils.toolbox.Position handles the missing-toolbox case.

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