-
Notifications
You must be signed in to change notification settings - Fork 104
Mentions State Machine
A brief discussion of the Mentions state machine architecture and its implications follows.
The plug-in manages an overall state machine. This state machine in turn manages two subsidiary state machines that govern the plug-in's behavior:
- The start detection state machine is responsible for monitoring the user's actions when the annotation creation process is inactive, and determining when to begin the creation process
- The creation state machine is responsible for supervising the annotation creation process, querying the host app, presenting the UI, and completing or canceling the creation process as necessary
If the user is not creating an annotation, the start detection state machine monitors the number of non-whitespace, non-newline characters typed since the previous whitespace or newline, and starts the search process if enough consecutive characters are typed. The search buffer is reset every time a whitespace or newline is typed. The search process is also started immediately if a control character is typed.
When the plug-in is in the annotation creation process, inserting or deleting characters will cause the plug-in to query its delegate for an updated set of search results. If the user deletes all characters, the creation process is canceled; however, even if the annotation was implicitly started, the user may delete all but the last character without canceling the process. For example, if the implicit start threshold is five characters, the user can still delete characters from (e.g.) "Peter" to search on "Pete", "Pet", "Pe", or "P".
If the user enters or deletes characters to the point where there are no results, and then types a whitespace or newline character, the creation process is immediately canceled. If the user taps within the single line viewport, moves the cursor, or tries to cut or paste test, the creation process is canceled.
If an annotation is created, the creation process is canceled, or the cursor is moved to a location where the preceding character is neither a whitespace or a newline, the plug-in is considered to be stalled. The annotation creation process will not be allowed to start again until the user types a whitespace or newline character, or moves the cursor to precede a whitespace or newline character (or the very beginning of the text).