mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
## 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
77 lines
2.9 KiB
Rust
77 lines
2.9 KiB
Rust
//! Offline editing retains the draft in place.
|
|
//! Paste Enter handling is shared with normal submission so buffered newlines survive both paths.
|
|
|
|
use super::*;
|
|
|
|
impl ChatComposer {
|
|
/// Preserve Enter inside a paste burst without attempting submission.
|
|
pub(crate) fn handle_paste_enter(&mut self, now: Instant) -> bool {
|
|
let in_slash_context = self.slash_commands_enabled()
|
|
&& !self.draft.is_bash_mode
|
|
&& (matches!(self.popups.active, ActivePopup::Command(_))
|
|
|| self
|
|
.draft
|
|
.textarea
|
|
.text()
|
|
.lines()
|
|
.next()
|
|
.unwrap_or("")
|
|
.starts_with('/'));
|
|
if !self.draft.disable_paste_burst
|
|
&& self.draft.paste_burst.is_active()
|
|
&& !in_slash_context
|
|
&& self
|
|
.draft
|
|
.paste_burst
|
|
.append_control_char_if_active('\n', now)
|
|
{
|
|
return true;
|
|
}
|
|
if !in_slash_context
|
|
&& !self.draft.disable_paste_burst
|
|
&& self
|
|
.draft
|
|
.paste_burst
|
|
.newline_should_insert_instead_of_submit(now)
|
|
{
|
|
self.draft.textarea.insert_str("\n");
|
|
self.draft.paste_burst.extend_window(now);
|
|
return true;
|
|
}
|
|
|
|
false
|
|
}
|
|
|
|
pub(crate) fn handle_disconnected_key(&mut self, key: KeyEvent) {
|
|
self.cancel_history_search();
|
|
self.attachments.clear_remote_image_selection();
|
|
self.popups.active = ActivePopup::None;
|
|
self.set_disable_paste_burst(/*disabled*/ true);
|
|
// Expand in reverse order so remaining ranges stay valid. Textarea replacement
|
|
// preserves the cursor and other elements, including images and mentions.
|
|
let pending_pastes = std::mem::take(&mut self.draft.pending_pastes);
|
|
if !pending_pastes.is_empty() {
|
|
for element in self.draft.textarea.text_elements().into_iter().rev() {
|
|
if let Some((_, text)) = pending_pastes.iter().find(|(placeholder, _)| {
|
|
element.placeholder(self.draft.textarea.text()) == Some(placeholder.as_str())
|
|
}) {
|
|
self.draft
|
|
.textarea
|
|
.replace_range(element.byte_range.start..element.byte_range.end, text);
|
|
}
|
|
}
|
|
}
|
|
// Enter/Tab and configured submit bindings must never consume the draft offline.
|
|
// The basic editor reconciles attachments without invoking composer-level shortcuts.
|
|
if !matches!(key.code, KeyCode::Enter | KeyCode::Tab)
|
|
&& matches!(key.kind, KeyEventKind::Press | KeyEventKind::Repeat)
|
|
{
|
|
self.handle_input_basic(key);
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "reconnect_tests.rs"]
|
|
mod tests;
|