fix(qt): cortinilla robustness - scroll latch, hover, hasTop, index guard
Six defects, plus one owner-requested behaviour change.
- The document is now applied imperatively instead of bound. cortinillaJson
is republished wholesale when the artwork pass lands, about 1.5s after
the rows, and a bound Repeater model made that a full model reset: every
delegate destroyed and rebuilt, contentHeight momentarily 0, and
StopAtBounds clamping contentY to 0. The user was yanked back to the top
mid-read. The offset is latched and restored via Qt.callLater - NOT
forceLayout(), which is a QQuickItemView method and does not exist on a
plain Flickable; calling it threw a TypeError and clamped against a stale
contentHeight.
- panelHovered could latch true forever: if the panel went invisible while
the pointer was over it, the hover source never reported false again.
- Hover detection moved from a MouseArea to a HoverHandler. The MouseArea
was declared first, so the Flickable and every row's MouseArea sat on top
of it and took the hover events - containsMouse stayed false across most
of the panel, which is why hovering did not hold the dropdown open. A
plain MouseArea stays behind it purely to swallow background clicks.
- hasTop tested the top row's id for emptiness. Local ARTIST rows carry an
intentionally empty id - routing is by name - so the top-result block
would have vanished for them once the local sections land. It now trusts
the Option the payload already models.
- The row click passed flatIndex raw across the i32 boundary, where
undefined coerces to 0 - the top result's index - so a malformed row
would activate the wrong thing rather than nothing. The highlight already
guarded; the action now does too.
- The nested Repeaters both used an unqualified modelData. It resolves
correctly today, but one added `required` on the inner delegate would
silently flip every row to render its section. Both are named now.
- LAST_CORT's locks no longer unwrap(). row_clicked and move_selection are
invokable bodies, i.e. Qt GUI thread, so a poisoned lock there would take
the UI down over a snapshot that is stale at worst.
OWNER DIVERGENCE (2026-08-03, unplanned): hovering the panel no longer
pauses the idle timer indefinitely - it stretches it to 30s. The reference
pauses outright, which means a cursor left over the panel by accident holds
it open forever. 30s satisfies both halves of the owner's ask: reading is
never interrupted at 4.5s, and a forgotten cursor still lets it go.
Contract: qbz-nix-docs/qt-frontend/2026-08-03-cortinilla-parity, commit C5
(D-BUG-6/9/10/11/12/13).
Gate: build clean, 258/258 tests, both QML audits OK, offscreen smoke
0 complaints + home published.
cc
This commit is contained in:
2 files changed
+96
-17
No files matched your search
@@ -32,7 +32,18 @@ Item {
|
||||
|
||||
QbzTheme { id: theme }
|
||||
|
||||
readonly property var doc: parseDoc()
|
||||
// The document is applied IMPERATIVELY, not bound, so the scroll offset
|
||||
// survives a republish. `cortinillaJson` is republished wholesale when
|
||||
// the artwork pass lands (~1.5s after the rows), and a bound Repeater
|
||||
// model would be a full model reset: every delegate destroyed and
|
||||
// rebuilt, contentHeight momentarily 0, and StopAtBounds clamping
|
||||
// contentY to 0 — the user is yanked back to the top mid-read. This is
|
||||
// the port's own documented cure (MyQbzGridView.applyItems).
|
||||
property var doc: ({})
|
||||
property var sections: []
|
||||
readonly property bool hasTop: doc.top !== undefined && doc.top !== null
|
||||
readonly property bool empty: !hasTop && sections.length === 0 && !QbzSearch.cortinillaLoading
|
||||
|
||||
function parseDoc() {
|
||||
try {
|
||||
return JSON.parse(QbzSearch.cortinillaJson)
|
||||
@@ -40,9 +51,26 @@ Item {
|
||||
return ({})
|
||||
}
|
||||
}
|
||||
readonly property var sections: doc.sections || []
|
||||
readonly property bool hasTop: doc.top !== undefined && doc.top !== null && (doc.top.id || "") !== ""
|
||||
readonly property bool empty: !hasTop && sections.length === 0 && !QbzSearch.cortinillaLoading
|
||||
|
||||
property real _restoreY: 0
|
||||
function applyDoc() {
|
||||
root._restoreY = bodyFlick.contentY
|
||||
root.doc = parseDoc()
|
||||
root.sections = root.doc.sections || []
|
||||
// NOT forceLayout(): that is a QQuickItemView method (ListView /
|
||||
// GridView), and this is a plain Flickable + Column. The Column
|
||||
// re-layouts on the polish pass, so contentHeight is still the OLD
|
||||
// value here and clamping against it would be wrong. Restore once
|
||||
// layout has settled instead; Qt.callLater coalesces, so a burst of
|
||||
// republishes costs one restore.
|
||||
Qt.callLater(root._restoreScroll)
|
||||
}
|
||||
function _restoreScroll() {
|
||||
var maxY = Math.max(0, bodyFlick.contentHeight - bodyFlick.height)
|
||||
bodyFlick.contentY = Math.max(0, Math.min(root._restoreY, maxY))
|
||||
}
|
||||
|
||||
Component.onCompleted: root.applyDoc()
|
||||
|
||||
// The centered header search box width (HeaderBar's responsive rule) —
|
||||
// the click-through gaps below leave it free.
|
||||
@@ -66,12 +94,26 @@ Item {
|
||||
root.height - theme.headerHeight - 6 - root.npbHeight - 16 - 12
|
||||
|
||||
// --- Idle auto-close (4.5s without hover/activity, Cortinilla.slint) --
|
||||
// panelHovered can LATCH: if the panel goes invisible while the pointer
|
||||
// is over it, the MouseArea never reports containsMouse=false, so the
|
||||
// idle timer stays paused forever on the next open. The reference resets
|
||||
// it on every open/close for exactly this reason.
|
||||
property bool panelHovered: false
|
||||
onVisibleChanged: root.panelHovered = false
|
||||
// OWNER DIVERGENCE from the reference (2026-08-03): hovering the panel
|
||||
// must not let it close under the cursor, but a cursor left there BY
|
||||
// ACCIDENT must not hold it open forever either. So hover does not stop
|
||||
// the countdown, it stretches it to 30s. The reference pauses the timer
|
||||
// outright, which fails the second half.
|
||||
//
|
||||
// Assigning `interval` on a running Timer restarts it, so entering the
|
||||
// panel gives a full 30s and leaving it gives a full 4.5s — which is
|
||||
// exactly the wanted behaviour, not an accident.
|
||||
Timer {
|
||||
id: idleClose
|
||||
interval: 4500
|
||||
interval: root.panelHovered ? 30000 : 4500
|
||||
repeat: false
|
||||
running: root.visible && !root.panelHovered
|
||||
running: root.visible
|
||||
onTriggered: QbzSearch.cortinillaDismiss()
|
||||
}
|
||||
Connections {
|
||||
@@ -80,6 +122,7 @@ Item {
|
||||
// keystroke probe is the QUERY, not the payload: the reference
|
||||
// restarts per keystroke, and now that the debounce lives in Rust a
|
||||
// burst of typing publishes one payload but many queries.
|
||||
function onCortinillaJsonChanged() { root.applyDoc() }
|
||||
function onCortinillaQueryChanged() { if (root.visible && !root.panelHovered) idleClose.restart() }
|
||||
function onCortinillaSelectedIndexChanged() { if (root.visible && !root.panelHovered) idleClose.restart() }
|
||||
// Keyboard scroll-into-view: the controller publishes the selected
|
||||
@@ -169,11 +212,23 @@ Item {
|
||||
border.color: theme.borderMuted
|
||||
clip: true
|
||||
|
||||
// Hover detection for the idle stretch. A HoverHandler, NOT the
|
||||
// MouseArea this replaces: that MouseArea was declared first, so the
|
||||
// Flickable and every row's own MouseArea sat ON TOP of it and took
|
||||
// the hover events, and `containsMouse` stayed false for most of the
|
||||
// panel's surface — which is why hovering did not hold the dropdown
|
||||
// open. A HoverHandler reports for its item's whole area regardless
|
||||
// of what is stacked above it.
|
||||
HoverHandler {
|
||||
id: panelHover
|
||||
onHoveredChanged: root.panelHovered = hovered
|
||||
}
|
||||
// Swallow clicks that land on the panel background so they do not
|
||||
// fall through to the dismiss scrims underneath.
|
||||
MouseArea {
|
||||
// Hover surface for the idle-close pause; clicks stay inside.
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
onContainsMouseChanged: root.panelHovered = containsMouse
|
||||
acceptedButtons: Qt.AllButtons
|
||||
onClicked: {}
|
||||
}
|
||||
|
||||
Flickable {
|
||||
@@ -299,7 +354,16 @@ Item {
|
||||
Repeater {
|
||||
model: root.sections
|
||||
delegate: Column {
|
||||
id: sectionCol
|
||||
required property var modelData
|
||||
// Named alias: the inner Repeater below also has
|
||||
// a `modelData`, and which one an unqualified
|
||||
// reference resolves to depends on whether the
|
||||
// inner delegate declares required properties.
|
||||
// It happens to work today; one added `required`
|
||||
// would silently flip every row to render its
|
||||
// SECTION instead. Both are named explicitly now.
|
||||
readonly property var section: modelData
|
||||
width: bodyColumn.width
|
||||
leftPadding: 6
|
||||
rightPadding: 6
|
||||
@@ -339,8 +403,11 @@ Item {
|
||||
}
|
||||
}
|
||||
Repeater {
|
||||
model: modelData.rows
|
||||
delegate: CortRow { row: modelData }
|
||||
model: sectionCol.section.rows
|
||||
delegate: CortRow {
|
||||
required property var modelData
|
||||
row: modelData
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -424,8 +491,15 @@ Item {
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
// Guard the i32 boundary: an undefined flatIndex coerces to
|
||||
// 0 on the way into Rust, which is the TOP RESULT's index —
|
||||
// a malformed row would activate the wrong thing instead of
|
||||
// doing nothing. The highlight above already guards with
|
||||
// `?? -2`; this is the same guard on the action.
|
||||
var fi = row.flatIndex
|
||||
if (fi === undefined || fi === null) return
|
||||
if (root.headerBar) root.headerBar.clearSearch()
|
||||
QbzSearch.cortinillaRowClicked(row.flatIndex)
|
||||
QbzSearch.cortinillaRowClicked(fi)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -663,6 +663,11 @@ fn assign_flat_indices(data: &mut CortinillaData) {
|
||||
// Cortinilla controller state
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// Every lock on this takes `unwrap_or_else(|e| e.into_inner())`, not
|
||||
/// `unwrap()`: `row_clicked` and `move_selection` run on the Qt GUI thread
|
||||
/// (they are invokable bodies), so a poisoned lock there would take the whole
|
||||
/// UI down. The guarded value is a plain snapshot — a panic mid-write leaves
|
||||
/// it stale at worst, never inconsistent.
|
||||
static LAST_CORT: Mutex<Option<CortinillaData>> = Mutex::new(None);
|
||||
static CORT_VERSION: AtomicU64 = AtomicU64::new(0);
|
||||
/// The keyboard-selected flat index mirrored from the bridge property (so
|
||||
@@ -790,7 +795,7 @@ pub async fn live(runtime: &Arc<AppRuntime<LoggingAdapter>>, query: &str) {
|
||||
}
|
||||
}
|
||||
let missing = attach_urls(urls);
|
||||
*LAST_CORT.lock().unwrap() = Some(data.clone());
|
||||
*LAST_CORT.lock().unwrap_or_else(|e| e.into_inner()) = Some(data.clone());
|
||||
crate::search_bridge::ui(move |mut b| {
|
||||
if is_current_cort_version(version) {
|
||||
let json = serde_json::to_string(&data).unwrap_or_else(|_| "{}".into());
|
||||
@@ -804,7 +809,7 @@ pub async fn live(runtime: &Arc<AppRuntime<LoggingAdapter>>, query: &str) {
|
||||
if !is_current_cort_version(version) {
|
||||
return;
|
||||
}
|
||||
let mut data = LAST_CORT.lock().unwrap().clone();
|
||||
let mut data = LAST_CORT.lock().unwrap_or_else(|e| e.into_inner()).clone();
|
||||
if let Some(data) = &mut data {
|
||||
let mut urls: Vec<(String, &mut String)> = Vec::new();
|
||||
if let Some(top) = &mut data.top {
|
||||
@@ -817,7 +822,7 @@ pub async fn live(runtime: &Arc<AppRuntime<LoggingAdapter>>, query: &str) {
|
||||
}
|
||||
let _ = attach_urls(urls);
|
||||
let data = data.clone();
|
||||
*LAST_CORT.lock().unwrap() = Some(data.clone());
|
||||
*LAST_CORT.lock().unwrap_or_else(|e| e.into_inner()) = Some(data.clone());
|
||||
crate::search_bridge::ui(move |mut b| {
|
||||
let json = serde_json::to_string(&data).unwrap_or_else(|_| "{}".into());
|
||||
b.as_mut().set_cortinilla_json(QString::from(json.as_str()));
|
||||
@@ -841,7 +846,7 @@ pub fn dismiss() {
|
||||
/// semantics: Down from -1 -> first, Up from first -> -1, clamp both ends).
|
||||
pub fn move_selection(delta: i32) {
|
||||
let current = CURRENT_SEL.load(Ordering::SeqCst);
|
||||
let snap = LAST_CORT.lock().unwrap().clone();
|
||||
let snap = LAST_CORT.lock().unwrap_or_else(|e| e.into_inner()).clone();
|
||||
let Some(data) = snap else { return };
|
||||
let mut order: Vec<i32> = Vec::new();
|
||||
if let Some(top) = &data.top {
|
||||
@@ -908,7 +913,7 @@ fn flat_index_content_y(data: &CortinillaData, flat_index: i32) -> f64 {
|
||||
/// kind (album -> album view, artist -> artist view, track -> play,
|
||||
/// playlist -> inert POC-NOTE). The QML clears the input + closes itself.
|
||||
pub fn row_clicked(flat_index: i32) {
|
||||
let snap = LAST_CORT.lock().unwrap().clone();
|
||||
let snap = LAST_CORT.lock().unwrap_or_else(|e| e.into_inner()).clone();
|
||||
let Some(data) = snap else { return };
|
||||
let row = data
|
||||
.top
|
||||
|
||||
Reference in new issue
Block a user