fix: Handle exceptions when hovering over up/down arrows#334
fix: Handle exceptions when hovering over up/down arrows#334JWWTSL wants to merge 1 commit intolinuxdeepin:masterfrom
Conversation
log: Modify arrow scrolling logic to adjust only contentY (scroll by step size in pixels), completely bypassing currentIndex. Also add single-step scrolling when clicking arrows. pms: bug-335545
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts ArrowListView arrow button scrolling to operate directly on contentY with a pixel step size and adds single-step scrolling on click, while wiring the step size from ArrowListView into the button component. Sequence diagram for ArrowListViewButton hover and click scrollingsequenceDiagram
actor User
participant ArrowListViewButton
participant ActionButton
participant ListView as view
User->>ArrowListViewButton: hover over up/down arrow
ArrowListViewButton->>ActionButton: hovered = true
ActionButton->>ActionButton: shouldAutoScroll = hovered && enabled
ActionButton->>ActionButton: start initialDelayTimer (300ms)
ActionButton->>ActionButton: delayCompleted = true on trigger
ActionButton->>ActionButton: hoverScrollTimer running = shouldAutoScroll && delayCompleted
loop while hovered and enabled
ActionButton->>ActionButton: performScroll()
ActionButton->>ListView: read contentHeight, height, contentY
ActionButton->>ActionButton: compute maxY = max(0, contentHeight - height)
ActionButton->>ActionButton: step = max(1, stepSize)
ActionButton->>ActionButton: nextY = contentY ± step (by direction)
ActionButton->>ListView: set contentY = clamp(0, maxY, nextY)
end
User-->>ArrowListViewButton: stop hover
ArrowListViewButton->>ActionButton: shouldAutoScroll = false
ActionButton->>ActionButton: delayCompleted = false
User->>ArrowListViewButton: click up/down arrow
ArrowListViewButton->>ActionButton: onClicked
ActionButton->>ActionButton: performScroll() (single step)
ActionButton->>ListView: update contentY by ±stepSize pixels
Class diagram for ArrowListView and ArrowListViewButton scrolling changesclassDiagram
class ArrowListViewButton {
+Item view
+int direction
+int stepSize
}
class ActionButton {
+bool hovered
+bool enabled
+bool shouldAutoScroll
+bool delayCompleted
+performScroll()
+onShouldAutoScrollChanged()
+onClicked()
}
class InitialDelayTimer {
+int interval
+bool running
+onTriggered()
}
class HoverScrollTimer {
+int interval
+bool repeat
+bool running
+onTriggered()
}
class ArrowListView {
+Item itemsView
+int itemHeight
}
ArrowListView o-- ArrowListViewButton : creates_buttons
ArrowListViewButton o-- ActionButton : loads
ActionButton o-- InitialDelayTimer : uses
ActionButton o-- HoverScrollTimer : uses
ActionButton --> ArrowListView : modifies_contentY_via_view
note for ActionButton "performScroll reads view.contentHeight, view.height, view.contentY and sets view.contentY using stepSize"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: JWWTSL The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
deepin pr auto reviewGit Diff 代码审查总体评价这段代码修改了 Qt6 QML 中的 语法逻辑分析
代码质量建议
代码性能建议
代码安全建议
改进建议代码// ArrowListViewButton.qml 中的改进版本
Loader {
required property Item view
property int direction
property int stepSize: DS.Style.arrowListView.itemHeight
// 添加最大步长限制
readonly property int maxStepSize: 100
readonly property int effectiveStepSize: Math.min(stepSize, maxStepSize)
active: view.interactive
sourceComponent: ActionButton {
// ... 其他属性保持不变 ...
function performScroll() {
if (!view || !view.hasOwnProperty("contentY"))
return
// 验证方向是否有效
if (direction !== ArrowListViewButton.UpButton &&
direction !== ArrowListViewButton.DownButton)
return
var maxContentY = Math.max(0, view.contentHeight - view.height)
if (maxContentY <= 0)
return
var step = Math.max(1, effectiveStepSize)
var newContentY = direction === ArrowListViewButton.UpButton
? (view.contentY - step)
: (view.contentY + step)
view.contentY = Math.max(0, Math.min(maxContentY, newContentY))
}
property bool shouldAutoScroll: hovered && enabled
property bool delayCompleted: false
Timer {
id: initialDelayTimer
interval: 300
running: shouldAutoScroll
onTriggered: delayCompleted = true
}
Timer {
id: hoverScrollTimer
// 根据内容大小动态调整间隔
interval: view.contentHeight > 1000 ? 150 : 100
repeat: true
running: shouldAutoScroll && delayCompleted
onTriggered: performScroll()
}
onShouldAutoScrollChanged: {
if (!shouldAutoScroll) {
delayCompleted = false
}
}
onClicked: performScroll()
}
}总结这段代码修改了滚动行为,从基于索引的滚动改为基于像素的滚动,提供了更精细的滚动控制。总体上代码质量良好,但可以进一步改进注释、变量命名和性能优化。添加了一些安全检查,但还可以进一步完善边界条件和属性验证。 |
log: Modify arrow scrolling logic to adjust only contentY (scroll by step size in pixels), completely bypassing currentIndex. Also add single-step scrolling when clicking arrows.
pms: bug-335545
Summary by Sourcery
Adjust arrow list view buttons to scroll by pixel-based content offsets instead of index changes and support single-step scrolling on click.
Bug Fixes:
Enhancements: