p9-fb-12 partial (PR #84) 의 deferred 부분 finalize. spec contract 의 \"기존 P9-3 ask 의 e/j/k input-empty heuristic 제거 — mode 로 명확히\" 완료. spec status `in_progress` → `completed`. ## 핵심 변경 - **`search::is_typing_mod`** (CTRL/ALT chord filter) 함수 삭제. search Char dispatch 가 `state.mode` 로 분기: - Normal + plain `j`/`k` → 선택 이동 (Char 이라도 Normal 이면 navigation) - Insert + plain `j`/`k`/Char(c) (chord 제외) → input.push - Insert + CTRL/ALT chord → no-op (예약 — 향후 binding 위해) - Normal + 그 외 Char → no-op (no typing in Normal) - **`search::handle_key_search` 의 `i` (chunk inspect) / `g` (editor jump) pre-pass** 가 `state.mode == Mode::Normal` 일 때만 fire. Insert 모드면 typed char (input 에 push). 기존 SHIFT-aware matches!() 가드는 Normal-mode 진입 가드로 흡수. - **`ask::handle_key_ask`** 의 input-empty heuristic 삭제. e/j/k: - Normal + `e` → toggle explain - Normal + `j` → scroll down (saturating_add) - Normal + `k` → scroll up (saturating_sub) - Insert + 모든 plain Char (chord 제외) → input.push - **테스트 fixture** (`tests/search.rs::fresh_app`, `tests/ask.rs::fresh_app`) 에 `app.mode = Mode::auto_for(focus)` 추가 — run loop 의 auto-flip 동작을 테스트가 mirror. - **기존 nav 테스트** (`j_k_move_selection_within_bounds`, `g_key_enqueues_pending_editor_request`, `e_toggles_explain_in_ normal_mode`) 가 `app.mode = Mode::Normal` 명시. - **신규 4 테스트** mode-authoritative 동작 회귀 방지: - search: `j_in_insert_types_does_not_move_selection`, `arbitrary_char_in_normal_mode_is_noop` - ask: `e_types_in_insert_mode_does_not_toggle_explain`, `jk_scroll_in_normal_mode_type_in_insert` ## 테스트 - 기존 109 + 신규 4 = 113 TUI 테스트 통과 (38 lib + 20 ask + 12 inspect + 10 library + 6 mode + 25 search + 2 chat — search 23→25, ask 18→20) - `cargo test --workspace --no-fail-fast -j 1` exit 0 - `cargo clippy --workspace --all-targets -- -D warnings` clean ## 문서 - README `kebab tui` 행: \"mode-authoritative dispatch — Search 의 j/k/i/g, Ask 의 e/j/k 는 NORMAL 모드에서만 명령으로 동작, INSERT 에서는 입력 문자로 typing\" 명시 - HANDOFF: 2026-05-03 follow-up entry - spec status `in_progress` → `completed` ## HOTFIXES p9-fb-12 partial PR (#84) 의 \"Deferred\" 항목이 본 PR 로 finalized — HOTFIXES 새 entry 불필요 (기존 entry 가 이미 deferral 사유 + 해결 조건 명시). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
79 lines
2.2 KiB
Markdown
79 lines
2.2 KiB
Markdown
---
|
|
phase: P9
|
|
component: kebab-tui
|
|
task_id: p9-fb-12
|
|
title: "TUI mode state machine (NORMAL / INSERT)"
|
|
status: completed
|
|
depends_on: []
|
|
unblocks: [p9-fb-10, p9-fb-13]
|
|
contract_source: ../../docs/superpowers/specs/2026-04-27-kebab-final-form-design.md
|
|
contract_sections: [§10 UX]
|
|
source_feedback: p9-dogfooding-feedback.md item 10
|
|
---
|
|
|
|
# p9-fb-12 — Mode machine
|
|
|
|
## Goal
|
|
|
|
TUI 전체에 vim 식 NORMAL / INSERT 모드 도입. 입력 모호성 (e/j/k 가 typing vs command) 제거.
|
|
|
|
## Allowed dependencies
|
|
|
|
- 기존 kebab-tui deps.
|
|
|
|
## Public surface
|
|
|
|
```rust
|
|
pub enum Mode { Normal, Insert }
|
|
pub(crate) struct App {
|
|
mode: Mode,
|
|
// ... 기존
|
|
}
|
|
```
|
|
|
|
key dispatch 가 mode 따라 분기.
|
|
|
|
## Behavior contract
|
|
|
|
기본 진입 모드: NORMAL (Library 가 starting pane). Search / Ask 는 query 칠 일이 잦으므로 pane 전환 시 자동 INSERT 진입 (configurable, 우선 자동).
|
|
|
|
NORMAL 모드 키 (전역):
|
|
- `i` → INSERT
|
|
- `:` → command line (`:q` quit, `:cite`, `:new` 등)
|
|
- `j/k`, `g/G`, `Ctrl-d/u`, `PageDown/Up` → scroll
|
|
- `Tab/Shift-Tab` → pane 이동
|
|
- `?` → cheatsheet popup (p9-fb-13)
|
|
- pane 별 키 (e=explain, c=cite toggle, r=refresh, …)
|
|
|
|
INSERT 모드 키:
|
|
- 모든 `Char` → input buffer push
|
|
- `Esc` → NORMAL
|
|
- `Enter` → submit (search / ask trigger)
|
|
- `Backspace`, 화살표 키 → buffer 편집 + cursor 이동
|
|
- 기타 navigation 키 (j/k 등) 는 typing 으로만
|
|
|
|
status bar 표시: `-- INSERT --` / `-- NORMAL --` (color: INSERT=green, NORMAL=blue).
|
|
focus 표시: 활성 pane 의 테두리 색 강조.
|
|
|
|
기존 P9-3 ask 의 e/j/k input-empty heuristic 제거 — mode 로 명확히.
|
|
|
|
## Test plan
|
|
|
|
| kind | description |
|
|
|------|-------------|
|
|
| unit | NORMAL 에서 `j` → scroll, INSERT 에서 `j` → buffer 'j' |
|
|
| unit | `i` → INSERT, `Esc` → NORMAL |
|
|
| unit | Search pane 전환 시 자동 INSERT |
|
|
| integration | mode 전환 + key sequence snapshot |
|
|
|
|
## DoD
|
|
|
|
- [ ] `cargo test -p kebab-tui` 통과
|
|
- [ ] 기존 input-empty heuristic 제거 (HOTFIXES P9-3 e/j/k 갱신)
|
|
- [ ] README + cheatsheet (p9-fb-13) 갱신
|
|
|
|
## Out of scope
|
|
|
|
- VISUAL 모드 (P+)
|
|
- mode 별 cursor shape (`Block` vs `Bar`) — 터미널마다 다름, 우선 skip
|