Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ internal static async Task<SimulateMouseInputResponse> ExecuteClick(
}
finally
{
waitOutcome = await FinishHeldButton(mouse, button, waitOutcome, pressWasApplied)
// The release must still run when the command itself was cancelled, or the button stays held.
waitOutcome = await FinishHeldButton(
mouse, button, waitOutcome, pressWasApplied, CancellationToken.None)
.ConfigureAwait(false);
}

Expand Down Expand Up @@ -179,7 +181,9 @@ internal static async Task<SimulateMouseInputResponse> ExecuteLongPress(
}
finally
{
waitOutcome = await FinishHeldButton(mouse, button, waitOutcome, pressWasApplied)
// The release must still run when the command itself was cancelled, or the button stays held.
waitOutcome = await FinishHeldButton(
mouse, button, waitOutcome, pressWasApplied, CancellationToken.None)
.ConfigureAwait(false);
}

Expand Down Expand Up @@ -216,7 +220,8 @@ private static async Task<InputSimulationWaitOutcome> FinishHeldButton(
Mouse mouse,
RuntimeMouseButton button,
InputSimulationWaitOutcome waitOutcome,
bool pressWasApplied)
bool pressWasApplied,
CancellationToken ct)
{
if (waitOutcome == InputSimulationWaitOutcome.TimedOut)
{
Expand All @@ -226,7 +231,7 @@ private static async Task<InputSimulationWaitOutcome> FinishHeldButton(

if (waitOutcome == InputSimulationWaitOutcome.Paused && pressWasApplied)
{
return await ReleaseHeldButtonAfterPause(mouse, button).ConfigureAwait(false);
return await ReleaseHeldButtonAfterPause(mouse, button, ct).ConfigureAwait(false);
}

if (pressWasApplied)
Expand All @@ -235,7 +240,7 @@ private static async Task<InputSimulationWaitOutcome> FinishHeldButton(
await MouseInputMainThreadCleanup.ReleaseButtonIfPossible(
mouse,
button,
CancellationToken.None).ConfigureAwait(false);
ct).ConfigureAwait(false);
if (releaseOutcome == InputSimulationWaitOutcome.TimedOut)
{
MouseInputMainThreadCleanup.ScheduleTimedOutButtonCleanup(mouse, button, false);
Expand All @@ -245,11 +250,11 @@ await MouseInputMainThreadCleanup.ReleaseButtonIfPossible(
// The pause can also arrive while this release is queued, which discards it the same way.
if (releaseOutcome == InputSimulationWaitOutcome.Paused)
{
return await ReleaseHeldButtonAfterPause(mouse, button).ConfigureAwait(false);
return await ReleaseHeldButtonAfterPause(mouse, button, ct).ConfigureAwait(false);
}
}

await InputSystemUpdateHelper.SwitchToMainThreadIfNeeded(CancellationToken.None);
await InputSystemUpdateHelper.SwitchToMainThreadIfNeeded(ct);
MouseInputState.SetButtonUp(button);
if (waitOutcome == InputSimulationWaitOutcome.Paused)
{
Expand All @@ -269,13 +274,14 @@ await MouseInputMainThreadCleanup.ReleaseButtonIfPossible(
/// </summary>
private static async Task<InputSimulationWaitOutcome> ReleaseHeldButtonAfterPause(
Mouse mouse,
RuntimeMouseButton button)
RuntimeMouseButton button,
CancellationToken ct)
{
// Why: ApplyOnNextConfiguredUpdate already disposed the pending apply subscription when it
// returned Paused, so a release routed through it again is discarded and the button stays
// held until the next command. Writing after that dispose also keeps a queued edge from
// re-applying the press once the Editor resumes.
await InputSystemUpdateHelper.SwitchToMainThreadIfNeeded(CancellationToken.None);
await InputSystemUpdateHelper.SwitchToMainThreadIfNeeded(ct);
MouseInputMainThreadCleanup.ReleaseButtonImmediatelyAfterPauseInterruption(mouse, button);
MouseInputState.SetButtonUp(button);
SimulateMouseInputOverlayState.Clear();
Expand Down
Loading