Files
codex/codex-rs/tui/src/bottom_pane/chat_composer/paste_input.rs
T
Eric Traut 7a48b95c6c Preserve tabs in non-bracketed paste bursts (#45454)
## Why

When terminals deliver pasted text as individual key events, tabs can trigger completion, submission, or queuing instead of preserving indentation in the draft.

## What changed

Capture unmodified `Tab` events during paste bursts before shortcut dispatch, including after short Unicode prefixes. Refresh the burst idle timeout when appending tabs or newlines, and flush expired bursts before handling manual `Tab` shortcuts.

## Testing

Add regression tests for multiline tab preservation, ASCII and Unicode prefixes, idle timeout refresh, completion suppression, and normal submission and queue shortcuts. Add a snapshot for pasted indentation.

GitOrigin-RevId: ba404cfe66c23f37da5a0db7cccfdd3d4c4af331
2026-09-14 16:05:17 +00:00

42 lines
1.1 KiB
Rust

//! Capture raw paste tabs before completion and submission shortcuts see them.
use super::*;
impl ChatComposer {
pub(super) fn handle_paste_tab(&mut self, key: KeyEvent, now: Instant) -> bool {
if key.code != KeyCode::Tab
|| !key.modifiers.is_empty()
|| self.draft.disable_paste_burst
|| !self.draft.textarea.allows_paste_burst()
{
return false;
}
self.handle_paste_burst_flush(now);
if self
.draft
.paste_burst
.append_control_char_if_active('\t', now)
{
return true;
}
// Short non-ASCII prefixes are inserted directly, without a held first character.
if self
.draft
.paste_burst
.direct_insert_newline_should_insert(now)
{
self.draft
.paste_burst
.begin_with_retro_grabbed(String::new(), now);
return self
.draft
.paste_burst
.append_control_char_if_active('\t', now);
}
false
}
}