Mobile Chord System Implementation
Overview
Implemented a chord system that allows mobile users to use Option+Arrow key combinations for word navigation:- Option key acts as a toggle/modifier
- When Option is pressed, it activates and waits for an arrow key
- When an arrow key is pressed while Option is active, it sends the combination
- Visual feedback shows when Option modifier is active
Implementation Details
1. State Management
- Added
activeModifiers
Set to track which modifiers are currently active - Option key toggles its state in the Set rather than sending immediately
2. Chord Detection
- When Option is pressed, it’s added to activeModifiers
- When an arrow key is pressed with Option active:
- Clears the Option modifier
- Sends Option (ESC) first
- Then sends the arrow key
- This creates the Option+Arrow combination
3. Visual Feedback
- Added CSS class
.modifier-key.active
with blue background - Option button shows active state when pressed
- State clears after arrow key press or when pressing non-arrow keys
4. Key Mappings
- Option sends ESC (
\x1b
) - already implemented in direct-keyboard-manager.ts - Arrow keys send their normal codes
- The combination results in ESC+arrow sequences for word navigation:
- Option+Left = ESC+b (word backward)
- Option+Right = ESC+f (word forward)
Testing
Added comprehensive tests interminal-quick-keys.test.ts
covering:
- Toggle behavior of Option key
- Chord detection for all arrow keys
- Clearing of modifier state
- Visual update requests
- Multiple chord sequences
Usage
- Tap Option key (⌥) - it highlights in blue
- Tap any arrow key - sends Option+Arrow combination
- Option automatically deactivates after use
- Can tap Option again to cancel without sending