Skip to content

Calculate for prevent-overflow items correctly in toolbar#1058

Open
zoltanhosszu wants to merge 3 commits into
mainfrom
toolbar-respect-preventoverflow
Open

Calculate for prevent-overflow items correctly in toolbar#1058
zoltanhosszu wants to merge 3 commits into
mainfrom
toolbar-respect-preventoverflow

Conversation

@zoltanhosszu
Copy link
Copy Markdown
Contributor

The calculation of toolbar overflow didn't account for elements with data-prevent-overflow attribute, so inserting those items via an extension still broke out of the toolbar's container width.

This PR updates that calculation logic.

Copilot AI review requested due to automatic review settings May 20, 2026 08:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes toolbar overflow compaction so that items marked with data-prevent-overflow (including extension-injected buttons) are properly accounted for during overflow measurement, preventing them from visually breaking outside the toolbar’s padded bounds.

Changes:

  • Reworks the toolbar overflow compaction logic to measure actual overflow against the toolbar’s content bounds and compact accordingly.
  • Treats data-prevent-overflow as a presence-based flag (any value) when determining which buttons are eligible to move into the overflow menu.
  • Adds a browser test to ensure injected non-overflowable buttons remain in the toolbar and that visible toolbar items stay within bounds.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
test/browser/tests/formatting/toolbar.test.js Adds coverage ensuring injected data-prevent-overflow buttons don’t end up in the overflow menu and don’t cause layout spillover.
src/elements/toolbar.js Updates overflow detection/compaction to measure real overflow and respect non-overflowable injected items.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zoltanhosszu zoltanhosszu changed the title Toolbar respect prevent-overflow Calculate for prevent-overflow items correctly in toolbar May 20, 2026
@zoltanhosszu zoltanhosszu requested a review from samuelpecher May 20, 2026 13:15
@samuelpecher samuelpecher requested a review from Copilot May 25, 2026 10:27
@samuelpecher
Copy link
Copy Markdown
Collaborator

Implemented my review thoughts in #1062

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread src/elements/toolbar.js Outdated
Comment on lines +291 to +295
this.#showOverflowMenu()
const overflowWidth = this.#getOverflowWidth()

const availableWidth = this.clientWidth
const buttonRightEdges = buttons.map(button => {
const style = window.getComputedStyle(button)
return button.offsetLeft + button.offsetWidth + parseFloat(style.marginRight)
})

let firstOverflowing = -1
for (let i = 0; i < buttons.length; i++) {
if (buttonRightEdges[i] > availableWidth) {
firstOverflowing = i
break
}
if (overflowWidth > 0) {
this.#reclaimWidth(overflowWidth)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fixed; it wasn't changing anything in practice.

Comment thread src/elements/toolbar.js
Comment thread src/elements/toolbar.js Outdated
Use clientWidth vs scrollWidth to determine whether the toolbar is
overflowing and offsetWidth to directly get the button widths. The
single-pass design is kept to prevent forced layouts by recalculating
the widths on every button move.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread src/elements/toolbar.js
recoveredWidth += button.offsetWidth + gap
}

this.#overflowMenuDropdown.prepend(...overflowButtons)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants