mirror of
https://github.com/openai/codex.git
synced 2026-05-04 13:21:54 +03:00
Keep agent-switch word-motion keys out of draft editing (#14376)
## Summary - only trigger multi-agent fast-switch shortcuts when the composer is empty - keep the Option+b/f fallback for terminals that encode Option+arrow that way - document why the empty-composer gate preserves expected word-wise editing behavior ## Testing - just fmt - cargo test -p codex-tui Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -121,8 +121,10 @@ fn previous_agent_word_motion_fallback(
|
||||
key_event: KeyEvent,
|
||||
allow_word_motion_fallback: bool,
|
||||
) -> bool {
|
||||
// macOS terminals often send Option+b/f as word-motion keys instead of Option+arrow events
|
||||
// unless enhanced keyboard reporting is enabled.
|
||||
// Some terminals, especially on macOS, send Option+b/f as word-motion keys instead of
|
||||
// Option+arrow events unless enhanced keyboard reporting is enabled. Callers should only
|
||||
// enable this fallback when the composer is empty so draft editing retains the expected
|
||||
// word-wise motion behavior.
|
||||
allow_word_motion_fallback
|
||||
&& matches!(
|
||||
key_event,
|
||||
@@ -145,8 +147,10 @@ fn previous_agent_word_motion_fallback(
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn next_agent_word_motion_fallback(key_event: KeyEvent, allow_word_motion_fallback: bool) -> bool {
|
||||
// macOS terminals often send Option+b/f as word-motion keys instead of Option+arrow events
|
||||
// unless enhanced keyboard reporting is enabled.
|
||||
// Some terminals, especially on macOS, send Option+b/f as word-motion keys instead of
|
||||
// Option+arrow events unless enhanced keyboard reporting is enabled. Callers should only
|
||||
// enable this fallback when the composer is empty so draft editing retains the expected
|
||||
// word-wise motion behavior.
|
||||
allow_word_motion_fallback
|
||||
&& matches!(
|
||||
key_event,
|
||||
@@ -671,7 +675,15 @@ mod tests {
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[test]
|
||||
fn agent_shortcut_matches_option_arrow_word_motion_fallbacks() {
|
||||
fn agent_shortcut_matches_option_arrow_word_motion_fallbacks_only_when_allowed() {
|
||||
assert!(previous_agent_shortcut_matches(
|
||||
KeyEvent::new(KeyCode::Left, KeyModifiers::ALT),
|
||||
false,
|
||||
));
|
||||
assert!(next_agent_shortcut_matches(
|
||||
KeyEvent::new(KeyCode::Right, KeyModifiers::ALT),
|
||||
false,
|
||||
));
|
||||
assert!(previous_agent_shortcut_matches(
|
||||
KeyEvent::new(KeyCode::Char('b'), KeyModifiers::ALT),
|
||||
true,
|
||||
@@ -690,6 +702,27 @@ mod tests {
|
||||
));
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
#[test]
|
||||
fn agent_shortcut_matches_option_arrows_only() {
|
||||
assert!(previous_agent_shortcut_matches(
|
||||
KeyEvent::new(KeyCode::Left, crossterm::event::KeyModifiers::ALT,),
|
||||
false
|
||||
));
|
||||
assert!(next_agent_shortcut_matches(
|
||||
KeyEvent::new(KeyCode::Right, crossterm::event::KeyModifiers::ALT,),
|
||||
false
|
||||
));
|
||||
assert!(!previous_agent_shortcut_matches(
|
||||
KeyEvent::new(KeyCode::Char('b'), crossterm::event::KeyModifiers::ALT,),
|
||||
false
|
||||
));
|
||||
assert!(!next_agent_shortcut_matches(
|
||||
KeyEvent::new(KeyCode::Char('f'), crossterm::event::KeyModifiers::ALT,),
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn title_styles_nickname_and_role() {
|
||||
let sender_thread_id = ThreadId::from_string("00000000-0000-0000-0000-000000000001")
|
||||
|
||||
Reference in New Issue
Block a user