Skip to content

fix(popup): prevent width jumping when content changes in Window popupType - #670

Open
Ivy233 wants to merge 1 commit into
linuxdeepin:masterfrom
Ivy233:fix/popup-width-jumping-373843
Open

fix(popup): prevent width jumping when content changes in Window popupType#670
Ivy233 wants to merge 1 commit into
linuxdeepin:masterfrom
Ivy233:fix/popup-width-jumping-373843

Conversation

@Ivy233

@Ivy233 Ivy233 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

After commit cba9773 removed the background Item's implicitWidth binding to break a binding loop, Popup's implicitWidth started tracking contentImplicitWidth directly. When popupType is Popup.Window, QQuickPopupWindow::implicitWidthChanged() unconditionally adopts popup->implicitWidth(), so search filtering that shrinks the content causes the popup window to jump to a smaller width.

Add an explicit ratchet: once the popup is open, implicitWidth/Height only grow, never shrink. The old binding loop accidentally provided this behavior; this is a loop-free replacement.

  1. Add _maxImplicitWidth/_maxImplicitHeight ratchet state properties
  2. Bind implicitWidth/Height to Math.max(current value, ratchet)
  3. Reset ratchet on aboutToShow for each open session
  4. Update ratchet on implicitContentWidth/HeightChanged (grow only)

修复 Popup 在 Window popupType 下宽度跳变问题

commit cba9773 移除 background Item 的 implicitWidth 绑定以消除绑定环后, Popup 的 implicitWidth 直接随 contentImplicitWidth 变化。当 popupType 为 Popup.Window 时,QQuickPopupWindow::implicitWidthChanged() 无条件采用 popup->implicitWidth(),搜索过滤导致内容减少时窗口宽度跳变。

添加显式棘轮机制:Popup 打开后 implicitWidth/Height 只增不减。旧的绑定环 意外提供了此行为,本修复是无绑定环的等价替代。

PMS: BUG-373823、BUG-373843

Summary by Sourcery

Keep Window popup dimensions stable while content changes by retaining the largest implicit size throughout each open session.

Bug Fixes:

  • Prevent Window popups from shrinking and jumping when their content becomes smaller during an open session.

Enhancements:

  • Add per-session sticky maximum implicit width and height tracking for Window popups, resetting when each session opens.

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Ivy233

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Aug 25, 2026

Copy link
Copy Markdown

Reviewer's Guide

Prevents Popup.Window from shrinking and visibly jumping when content changes after opening by explicitly retaining the maximum implicit width and height for each open session, without reintroducing the binding loop.

Sequence diagram for popup implicit-size ratchet

sequenceDiagram
    participant Popup
    participant Content
    participant Window

    Popup->>Popup: onAboutToShow
    Popup->>Popup: DS.Style.control.implicitWidth(control)
    Popup->>Popup: DS.Style.control.implicitHeight(control)
    Content-->>Popup: onImplicitContentWidthChanged
    Popup->>Popup: Math.max(_maxImplicitWidth, implicitWidth)
    Content-->>Popup: onImplicitContentHeightChanged
    Popup->>Popup: Math.max(_maxImplicitHeight, implicitHeight)
    Popup->>Window: implicitWidthChanged / implicitHeightChanged
    Window->>Window: Retain maximum size
Loading

File-Level Changes

Change Details Files
Replace implicit-size tracking with an explicit grow-only ratchet for popup dimensions.
  • Add private maximum width and height state.
  • Clamp implicit dimensions to the larger of the style-derived size and ratchet value.
  • Reset ratchet baselines at the start of each popup open session.
  • Update ratchets only when implicit content dimensions change, preserving the largest size during the session.
qt6/src/qml/Popup.qml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="qt6/src/qml/Popup.qml" line_range="29-39" />
<code_context>
+    property real _maxImplicitWidth: 0
+    property real _maxImplicitHeight: 0
+
+    implicitWidth: Math.max(DS.Style.control.implicitWidth(control), control._maxImplicitWidth)
+    implicitHeight: Math.max(DS.Style.control.implicitHeight(control), control._maxImplicitHeight)
+
+    onAboutToShow: {
+        control._maxImplicitWidth = DS.Style.control.implicitWidth(control)
+        control._maxImplicitHeight = DS.Style.control.implicitHeight(control)
+    }
+    onImplicitContentWidthChanged: control._maxImplicitWidth =
+        Math.max(control._maxImplicitWidth, DS.Style.control.implicitWidth(control))
+    onImplicitContentHeightChanged: control._maxImplicitHeight =
+        Math.max(control._maxImplicitHeight, DS.Style.control.implicitHeight(control))

     padding: DS.Style.popup.padding
</code_context>
<issue_to_address>
**issue (broader_impact):** The ratchet is applied unconditionally to every Popup, including Popup.Item, so a non-window popup remains at its largest width and height after its content shrinks during the same open session instead of resizing with the content. The change therefore introduces stale oversized item popups even though the reported regression is specific to Popup.Window.

**Triggers:** When a Popup.Item popup displays content whose implicit size shrinks while it remains open.

**Suggested fix:** Apply the ratchet only when `popupType === Popup.Window`, or keep the existing dynamic sizing for item popups.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread qt6/src/qml/Popup.qml Outdated
@Ivy233
Ivy233 force-pushed the fix/popup-width-jumping-373843 branch from 04344d2 to f90c919 Compare August 25, 2026 09:21
Comment thread qt6/src/qml/Popup.qml Outdated
property real _maxImplicitWidth: 0
property real _maxImplicitHeight: 0

implicitWidth: control.popupType === Popup.Window

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.

implicitWidth赋值,不应该有这样复杂的判断,它默认就是那background和contentItem的implicitWidth,在background里赋值正确应该就可以了,

…pType

After commit cba9773 removed the background Item's implicitWidth binding
to break a binding loop, Popup's implicitWidth started tracking
contentImplicitWidth directly. When popupType is Popup.Window,
QQuickPopupWindow::implicitWidthChanged() unconditionally adopts
popup->implicitWidth(), so search filtering that shrinks the content
causes the popup window to jump to a smaller width.

Add an explicit ratchet: once the popup is open, implicitWidth/Height
only grow, never shrink. The old binding loop accidentally provided
this behavior; this is a loop-free replacement. Instead of overriding
implicitWidth/Height directly, keep the sticky-max via the background's
(windowBlurComponent) implicit size, the natural source of the popup's
default implicit size, and only for Popup.Window so Popup.Item keeps
resizing with its content.

1. Add _maxImplicitWidth/_maxImplicitHeight ratchet state properties
2. Reset ratchet on aboutToShow for each open session
3. Update ratchet on implicitContentWidth/HeightChanged (grow only)
4. Apply the ratchet to the Popup.Window background's implicit size

修复 Popup 在 Window popupType 下宽度跳变问题

commit cba9773 移除 background Item 的 implicitWidth 绑定以消除绑定环后,
Popup 的 implicitWidth 直接随 contentImplicitWidth 变化。当 popupType 为
Popup.Window 时,QQuickPopupWindow::implicitWidthChanged() 无条件采用
popup->implicitWidth(),搜索过滤导致内容减少时窗口宽度跳变。

添加显式棘轮机制:Popup 打开后 implicitWidth/Height 只增不减。旧的绑定环
意外提供了此行为,本修复是无绑定环的等价替代。棘轮不再直接覆盖
implicitWidth/Height,而是通过 background(windowBlurComponent) 的隐式尺寸
(Popup 默认隐式尺寸的自然来源)保持最大值,且仅作用于 Popup.Window,
Popup.Item 仍随内容动态缩放。

PMS: BUG-373823、BUG-373843
@Ivy233
Ivy233 force-pushed the fix/popup-width-jumping-373843 branch from f90c919 to 99ceb8d Compare August 26, 2026 05:04
@Ivy233
Ivy233 requested a review from 18202781743 August 26, 2026 05:09
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