diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/EventDrag.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/EventDrag.kt index 8c31288f..1e1efa8d 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/EventDrag.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/EventDrag.kt @@ -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. diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/TimelineDrag.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/TimelineDrag.kt index 0b80c38d..d4fde98b 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/TimelineDrag.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/TimelineDrag.kt @@ -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 diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt index 326d7b72..0f0e511a 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt @@ -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,