fix: prevent panic on Shift+Tab in shared manage editor#479
Conversation
|
/claude review |
|
Claude finished @avihut's task in 2m 15s —— View job PR Review
SummaryThe fix is correct and the approach is pragmatic. The root cause (edtui's Issues1. Maintenance risk: whitelist is a copy of edtui internals
The comment correctly identifies this as a concern ("Source of truth: Consider adding an inline comment on the 2.
matches!(
code,
Char(_) | Enter | Esc | ... // <-- Esc is already returned before reaching this
)
3. Regression test exercises the filter function, not the call site (low priority)
The three new tests verify Adding a test that calls #[test]
fn handle_key_back_tab_returns_false_and_does_not_panic() {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("f.txt");
std::fs::write(&path, "hello").unwrap();
let mut session = EditSession::new(path, false, "test".into(), "txt".into()).unwrap();
let event = crossterm::event::KeyEvent::new(
crossterm::event::KeyCode::BackTab,
crossterm::event::KeyModifiers::SHIFT,
);
assert!(!session.handle_key(event), "BackTab must not close the editor");
}This would require Pre-existing concerns (not introduced by this PR, not blocking)
What's good
Overall: LGTM with the |
edtui 0.11.x's `From<crossterm::event::KeyCode>` impl ends with `_ => unimplemented!()`, so any key code outside its whitelist crashes the process. crossterm parses Shift+Tab as `KeyCode::BackTab`, which is not in the whitelist — pressing it from the inline editor in `daft shared manage` panicked the process. The visible "editor exits / UI closes" symptom was the panic hook restoring the terminal as the process died. Filter unsupported key codes upstream of edtui's handler with a whitelist mirroring edtui's source. Drops BackTab, F-keys, Insert, media keys, etc. silently rather than forwarding them. Add unit tests covering the regression case (BackTab), other unsupported codes, and the supported codes still passing. Fixes #345 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Remove `Esc` from `is_edtui_supported`'s whitelist: `handle_key` short-circuits on Esc before the filter is reached, so listing it was misleading. Updated the doc and `supported_codes_pass_the_filter` test to match. - Add a `SYNC WITH EDTUI` marker on the `edtui` line in `Cargo.toml` pointing back to `is_edtui_supported`, so the next person bumping the dep audits `events/key/input.rs` for new arms. - Add an end-to-end regression test that drives `handle_key` with a `BackTab+SHIFT` `KeyEvent`, so the filter guard cannot be silently removed from `handle_key` without a test failure. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1aa5001 to
bf4c681
Compare
|
/claude review |
|
Claude finished @avihut's task in 1m 22s —— View job PR Review
SummaryThe second commit ( A few remaining observations, none blocking: Issues1. Test count in PR description is stale (cosmetic only) The body says "3 new regression tests" but the diff now includes 4: 2. Follow-up event is consumed even on
if crossterm::event::poll(Duration::from_millis(20)).unwrap_or(false) {
let _ = crossterm::event::read(); // error silently discarded
return false;
}
3. The function is called on every key event in a TUI hot path. The compiler will almost certainly inline it anyway given its size, but an explicit What's good
Overall: LGTM. All prior nits addressed. Ready to merge. |
The function is called on every key event in the TUI's hot path. The compiler will likely inline it anyway given its size, but an explicit `#[inline]` makes the intent unambiguous to readers and to LTO boundaries. Addresses review nit on #479. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
_ => unimplemented!()arm and crash the process.Root cause
edtui::events::key::input::From<crossterm::event::KeyCode>(e.g. line 146 in 0.11.3) matches a small whitelist and panics on everything else. crossterm emits Shift+Tab asKeyCode::BackTab, which is not in that whitelist, so the first Shift+Tab keypress in the inline editor panicked.Fix
Add
is_edtui_supported(code)mirroring edtui's whitelist (Char,Enter,Esc,Backspace,Delete,Tab,Left,Right,Up,Down,Home,End,PageUp,PageDown) and drop anything else before calling the handler.Test plan
mise run test:unit— 1698 pass (3 new regression tests)mise run clippy— cleanmise run fmt:check— cleandaft shared manage, enter the inline editor, press Shift+Tab → no panic, editor stays openFixes #345
🤖 Generated with Claude Code