feat(qt): Excel-style multi-select — Shift ranges across every surface

Selection existed but had no keyboard: every click was a single toggle,
so picking 40 tracks meant 40 clicks. Slint and Tauri have had ranges
since 2026-06; this is that port.

NINE surfaces, not the five the track views suggested: Album, Artist,
Playlist, Label, Local Album, plus Library's tracks and albums and Local
Library's tracks and albums. Each carried its own hand-copied `selected`
map and its own `toggleSelected`, so the rule went into
controls/SelectionModel.qml and the maps stayed where they were — the
smallest change that stops it being copied a tenth time.

The rules are Tauri's `applyShiftRange`, unchanged: a plain click
toggles one row without clearing the rest, Shift fills the range from
the anchor ADDITIVELY (so re-dragging a range cannot eat the set) and
leaves the anchor where it is, and Ctrl/Cmd is the same as a plain click
— not a shortcut, but the behaviour both references already have,
because an accumulating click is what "add without disturbing" means.

Qt makes this CHEAPER than Slint, and the difference is worth recording:
Slint had no modifiers at click time and had to read a thread-local set
from a ModifiersChanged handler, with a documented stale-read edge case
when the window lost focus mid-chord. A QML MouseArea delivers
`mouse.modifiers` on the event itself, so the modifier and the click can
never disagree and no such seam exists here.

Three judgement calls, stated because they are not forced:

  - Library gets TWO models, one per kind. Its rows are mixed, and one
    anchor would let a Shift-click on a track sweep up the albums drawn
    between it and the anchor.
  - Ranges run over the VISIBLE rows. Local Library's search box is a
    view filter, and a range over rows the user cannot see is not the
    range they asked for — the same call `select-all` already made.
  - The Local Library tree rail keeps plain toggles. Its selection lives
    in Rust (QbzLocal.treeToggle*Select), so there is no QML map to hang
    an anchor off; teaching the Rust side about an anchor is its own
    change, and the file says so where a reader would expect otherwise.

The anchor is an ID, not an index, because every one of these views can
re-sort or filter under a live selection — an index anchor silently
points at a different track the moment the order changes. Slint's
selection.rs made the same call for the same reason.

Verified by driving the app: in Abbey Road, click row 1 then Shift-click
row 5 selects exactly rows 1-5 and leaves 6-8 untouched, with the bar
reading "5 selected"; the same in a playlist, additively over a row that
was already selected.

cc
This commit is contained in:
vicrodh committed 2026-08-22 02:03:10 -06:00
1 parent 7fc7605887
commit 750c59034b
19 files changed
+231 -94

No files matched your search

+24 -13
View File
@@ -596,17 +596,28 @@ Rectangle {
// A rebind needs a NEW object reference — mutating the map in place
// notifies nothing (the same rule artMap and every row's `favorite`
// property follow).
function toggleTrackSelected(id) {
var m = root.tracksSelected
if (m[id] === true) delete m[id]
else m[id] = true
root.tracksSelected = Object.assign({}, m)
/// Excel-style selection — controls/SelectionModel.qml holds the anchor
/// and the Shift-range rule; this view keeps owning its two maps.
///
/// TWO models, because tracks and albums are two independent selections
/// with two independent anchors, and the rows here are MIXED: `visibleRows`
/// carries both kinds, so each range is taken over the visible rows OF ITS
/// OWN KIND. Ranging over the mixed list would let a shift-click on a
/// track sweep up the albums drawn between it and the anchor.
SelectionModel { id: trackSel }
SelectionModel { id: albumSel }
function _rowsOfKind(kind) {
return root.visibleRows.filter(function (r) { return r.kind === kind })
}
function toggleAlbumSelected(id) {
var m = root.albumsSelected
if (m[id] === true) delete m[id]
else m[id] = true
root.albumsSelected = Object.assign({}, m)
function toggleTrackSelected(id, mods) {
root.tracksSelected = trackSel.next(root.tracksSelected, id,
root._rowsOfKind("track"),
mods === undefined ? Qt.NoModifier : mods)
}
function toggleAlbumSelected(id, mods) {
root.albumsSelected = albumSel.next(root.albumsSelected, id,
root._rowsOfKind("album"),
mods === undefined ? Qt.NoModifier : mods)
}
/// Selected ids in VISIBLE order — never `Object.keys(map)`. Qobuz ids are
@@ -630,7 +641,7 @@ Rectangle {
root.tracksSelected = m
return
}
if (action === "clear") { root.tracksSelected = ({}); return }
if (action === "clear") { root.tracksSelected = ({}); trackSel.anchorId = ""; return }
var ids = root.selectedIdsInOrder("track", root.tracksSelected)
if (ids.length === 0) return
QbzLibrary.libraryBulkAction("track", JSON.stringify(ids), action)
@@ -649,7 +660,7 @@ Rectangle {
root.albumsSelected = m
return
}
if (action === "clear") { root.albumsSelected = ({}); return }
if (action === "clear") { root.albumsSelected = ({}); albumSel.anchorId = ""; return }
var ids = root.selectedIdsInOrder("album", root.albumsSelected)
if (ids.length === 0) return
QbzLibrary.libraryBulkAction("album", JSON.stringify(ids), action)
@@ -1158,7 +1169,7 @@ Rectangle {
number: modelData._no || (index + 1)
selectMode: root.tracksMultiSelect
checked: root.tracksSelected[modelData.id] === true
onToggleSelect: root.toggleTrackSelected(modelData.id)
onToggleSelect: function (mods) { root.toggleTrackSelected(modelData.id, mods) }
onPlayRequested: root.playTrackInContext(item.id)
onEnqueueRequested: function (m) { QbzPlayer.enqueueTrack(item.id, m) }
// MyQBZ "Add to mixtape" — the HOST builds the