diff --git a/cli.py b/cli.py index da917ae19065d..50966d166b2c0 100644 --- a/cli.py +++ b/cli.py @@ -10068,6 +10068,13 @@ def handle_enter(event): return # --- Normal input routing --- + # Defer during rapid text input (paste without bracketed-paste support). + # When newlines arrive as individual Enter events, _on_text_changed fires + # for each character. If the last text change was < 50 ms ago, text is + # still arriving — skip submission and let the buffer accumulate. + if _last_text_change[0] and (time.monotonic() - _last_text_change[0]) < 0.05: + return + text = event.app.current_buffer.text.strip() has_images = bool(self._attached_images) if text or has_images: @@ -10717,6 +10724,7 @@ def _input_height(): _prev_newline_count = [0] _paste_just_collapsed = [False] self._skip_paste_collapse = False + _last_text_change = [None] def _on_text_changed(buf): """Detect large pastes and collapse them to a file reference. @@ -10733,6 +10741,7 @@ def _on_text_changed(buf): still batch newlines. Alt+Enter only adds 1 newline per event so it never triggers this. """ + _last_text_change[0] = time.monotonic() text = _strip_leaked_bracketed_paste_wrappers(buf.text) text, _had_mouse_reports = _strip_leaked_terminal_responses_with_meta(text) if _had_mouse_reports: