LongPressState enum tracks state of long presses#3113
LongPressState enum tracks state of long presses#3113raineorshine merged 5 commits intocybersemics:mainfrom
Conversation
|
Thank you!
That sounds fine, but let's |
|
OK, I think I have fully replaced the functionality present in #3107 and fixed #3074 entirely. Should we discuss the possibility of replacing I think that I could expand the |
| export enum LongPressState { | ||
| Inactive = 'Inactive', | ||
| DragHold = 'DragHold', | ||
| DragInProgress = 'DragInProgress', | ||
| DragCancelled = 'DragCancelled', | ||
| } |
There was a problem hiding this comment.
I like to heavily document enums and types, since developers often go to them first in order to understand parts of the code.
Types are also declarative, so if a developer can understand the types enough to use them without having to understand the related algorithms or implementation details, that's a win.
diff --git a/src/@types/State.ts b/src/@types/State.ts
index 8278e02af8..68884214a6 100644
--- a/src/@types/State.ts
+++ b/src/@types/State.ts
@@ -121,7 +121,7 @@ interface State {
/** The last undoable action that was executed. Usually this is the same as undoPatches.at(-1).actions[0]. However, on undo this will equal redoPatches.at(-1).actions[0]. This is important for special case animatons, like swapParent, that should be enabled not just when the action is originally executed, but also when it is reversed via undo. */
lastUndoableActionType?: ActionType
latestCommands: Command[]
- /** A discrete state machine that limits available actions during long press. */
+ /** Tracks the state of long press and drag-and-drop. */
longPress: LongPressState
/** When a context is sorted, the manual sort order is saved so that it can be recovered when they cycle back through the sort options. If new thoughts have been added, their order relative to the original thoughts will be indeterminate, but both the old thoughts and the new thoughts will be sorted relative to themselves. The outer Index is keyed by parent ThoughtId, and the inner Index stores the manual ranks of each child at the time the context is sorted. This is stored in memory only and is lost when the app refreshes. */
manualSortMap: Index<Index<number>>
diff --git a/src/constants.ts b/src/constants.ts
index 57aa05806b..5676bcb8ba 100644
--- a/src/constants.ts
+++ b/src/constants.ts
@@ -461,10 +461,15 @@ export enum AlertType {
Undo = 'Undo',
}
+/** A discrete state machine that tracks the state of long press and drag-and-drop. See the longPress reducer for valid transitions. */
export enum LongPressState {
+ /** No long press or drag-and-drop action is in progress. */
Inactive = 'Inactive',
+ /** The user has pressed a thought for longer than TIMEOUT_LONG_PRESS_THOUGHT without moving more than SCROLL_THRESHOLD px in order to activate the long press state. */
DragHold = 'DragHold',
+ /** The user is currently dragging a thought. */
DragInProgress = 'DragInProgress',
+ /** The drag has been cancelled, but the user has not released their finger from the screen. */
DragCancelled = 'DragCancelled',
}| if (!canceled && toggleMulticursorOnLongPress) { | ||
| dispatch(toggleMulticursor({ path: simplePath })) | ||
| if (!canceled) { | ||
| dispatch(longPress({ value: LongPressState.Inactive })) |
There was a problem hiding this comment.
I'm wondering if this should be moved outside the conditional. Shouldn't state.longPress be set to inactive when the long press ends, regardless of whether the long press completed successfully or was canceled?
There was a problem hiding this comment.
The onLongPressEnd function also runs when the pointer moves far enough to cancel a multicursor long press (DragHold becomes DragInProgress).
Line 107 in 7b4474e
There was a problem hiding this comment.
In that case, it does not run again when the long press actually ends.
There was a problem hiding this comment.
I see! Thanks for the clarification.
Yes, but separate PR once this is merged! Thanks! |
Co-authored-by: Raine Revere <raine@cybersemics.org>
Partial fix for #3072, #3073 and #3074
Add a
longPressvariable to the Redux store and aLongPressStateenum to track the state of a long press. We need to keepshouldCancelGesturefrom allowing gestures in a variety of circumstances:react-dndhas initiated a dragI tried to set it up as a proper state machine, which should provide some protection against state transitions coming in out of order. I haven't tested it at all yet.