Drag a selected event straight away and keep it selected (#141)

This commit is contained in:
2026-10-09 11:11:23 +02:00
parent 44f91a963a
commit e7f3afe581
3 changed files with 16 additions and 4 deletions
@@ -116,14 +116,18 @@ private fun rememberPickUpSurface(
val currentDrop by rememberUpdatedState(onDrop)
val currentCancel by rememberUpdatedState(onCancel)
val currentRelease by rememberUpdatedState(onRelease)
// Read per gesture rather than keyed on: the pickup itself can change it,
// and a restart would cancel the drag it just began.
val currentImmediate by rememberUpdatedState(immediate)
return Modifier
.onGloballyPositioned { coordinates[0] = it }
.pointerInput(key, immediate) {
.pointerInput(key) {
val slop = viewConfiguration.touchSlop
awaitEachGesture {
val down = awaitFirstDown(requireUnconsumed = false)
val origin = down.position
val immediate = currentImmediate
// Null on the timeout — held still — true once an [immediate]
// block has been moved past slop, false when the press is
// abandoned.
@@ -401,9 +401,9 @@ class TimelineDragController {
pointerInRoot: Offset,
blockInRoot: Offset,
) {
// A pickup ends any selection: a drop moves the event out from under
// it, and a release without moving selects again.
selection = null
// Picking up another event ends the selection; the selected one keeps
// it through the drag, and the screen moves it along with the drop.
if (!isSelected(block)) selection = null
source = block
this.clipOffsetMin = clipOffsetMin
this.titleLines = titleLines
@@ -519,6 +519,14 @@ private fun WeekContent(
val move = LocalEventMove.current
val zone = remember { TimeZone.currentSystemDefault() }
val onDrop: (TimelineDrop) -> Unit = { drop ->
// A selected event stays selected where it landed (#141).
if (dragController.selection?.event?.instanceId == drop.event.instanceId) {
val start = drop.startInstant(zone)
dragController.select(
drop.event.copy(start = start, end = start + (drop.event.end - drop.event.start)),
start.toLocalDateTime(zone).date,
)
}
move?.move(
MoveRequest(
eventId = drop.event.eventId,