40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// Authors: Storm Dragon, Angus Kola
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package input
|
|
|
|
import "time"
|
|
|
|
// The router owns this sequence across fully released chords and browse grab
|
|
// updates. Another key/chord, timeout, or the final press retires it. Held-key
|
|
// repeats never reach this helper. Reset only clears held keys, as for time/date.
|
|
func (router *CommandRouter) review_press(command Command, chord CommandChord) Command {
|
|
if command != ReviewCurrentCharacter && command != ReviewCurrentWord {
|
|
router.lastReviewPress = time.Time{}
|
|
return command
|
|
}
|
|
now := router.now()
|
|
if chord == router.lastReviewChord && !router.lastReviewPress.IsZero() &&
|
|
now.Sub(router.lastReviewPress) >= 0 && now.Sub(router.lastReviewPress) <= 500*time.Millisecond {
|
|
router.reviewPresses++
|
|
} else {
|
|
router.reviewPresses = 1
|
|
}
|
|
router.lastReviewChord, router.lastReviewPress = chord, now
|
|
if command == ReviewCurrentCharacter && router.reviewPresses == 2 {
|
|
router.lastReviewPress = time.Time{}
|
|
return ReviewPhoneticCharacter
|
|
}
|
|
if command == ReviewCurrentWord {
|
|
switch router.reviewPresses {
|
|
case 2:
|
|
return ReviewSpellWord
|
|
case 3:
|
|
router.lastReviewPress = time.Time{}
|
|
return ReviewPhoneticWord
|
|
}
|
|
}
|
|
return command
|
|
}
|