efaa0d9fca
A chat dropped onto the middle of another makes a named group (asked at once, "Group N" by default); onto a group it joins, a group dropped onto a chat takes it in, groups merge. The top level shows each group as a small pile with its name and count; a tap opens it in place under a header that leads back (also the scrim, Back and Escape). In a group, dropping a chat on the header leaves the group; a group of one dissolves. The close button ungroups a dropped group with Undo. Rename, Ungroup, Close all (with Undo), Move to group and Remove from group are in the group menu and as semantic actions. Each open-chat entry carries its group name (protocol field "group", omitted when ungrouped; older clients ignore it), stored and pushed by the server like the order; names are trimmed, printable, at most 80 characters. Needs a server restart to keep groups. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
51 lines
1.7 KiB
Dart
51 lines
1.7 KiB
Dart
/// Where a dragged item of the open column would land.
|
|
///
|
|
/// [position] is the dragged item's place in slots (its start index, plus
|
|
/// the slots it moved up; fractional), [from] its start index, [count] the
|
|
/// items, and [slot] the gap it opened so far (never past [lastSlot]). The
|
|
/// others are drawn around that gap. The middle half of each one
|
|
/// [canDropOnto] accepts is a drop on it; its outer quarters (or all of one
|
|
/// that accepts none) move the gap before or after it. The
|
|
/// gap itself holds while the item is within half a slot of it, so the
|
|
/// answer is stable: an item that slides aside never lands back under the
|
|
/// finger.
|
|
({int slot, int? onto}) chatStackDropTarget({
|
|
required double position,
|
|
required int from,
|
|
required int count,
|
|
required int slot,
|
|
bool Function(int index)? canDropOnto,
|
|
int? lastSlot,
|
|
}) {
|
|
final last = lastSlot ?? count - 1;
|
|
if (count < 2 || (position - slot).abs() <= .5) {
|
|
return (slot: slot, onto: null);
|
|
}
|
|
// The neighbour drawn nearest the position: its index and drawn place.
|
|
var nearest = -1;
|
|
var drawn = 0;
|
|
var distance = double.infinity;
|
|
for (var i = 0; i < count; i++) {
|
|
if (i == from) continue;
|
|
final rank = i < from ? i : i - 1;
|
|
final place = rank < slot ? rank : rank + 1;
|
|
final d = (position - place).abs();
|
|
if (d < distance) {
|
|
distance = d;
|
|
nearest = i;
|
|
drawn = place;
|
|
}
|
|
}
|
|
if (distance <= .25 && (canDropOnto?.call(nearest) ?? false)) {
|
|
return (slot: slot, onto: nearest);
|
|
}
|
|
final int next;
|
|
if (position < drawn) {
|
|
// Before it (below, toward the thumb).
|
|
next = drawn > slot ? drawn - 1 : drawn;
|
|
} else {
|
|
next = drawn < slot ? drawn + 1 : drawn;
|
|
}
|
|
return (slot: next.clamp(0, last), onto: null);
|
|
}
|