From 94454eed5d03434c3ed532a3ba8e0ed4fcad21b7 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Tue, 21 Jul 2026 14:15:05 +0000 Subject: [PATCH 02/13] fix: paste scrolls to bottom sendPaste() now calls scrollToBottomOnInput(), matching sendKeyEvent()/ sendCharEvent(), so pasting while scrolled up snaps the viewport back to the bottom like typed input. This commit originally also added an iTerm2 inline-image handler (OSC 1337 File=, engine half of patches_new/frontend's PNG-decoder-injection commit), squashed from the pre-split history. Dropped during the rebase onto upstream/master (704d2286): upstream independently shipped its own, more complete OSC 1337 implementation in that range (commit 05067134 "vtbackend: implement iTerm2 OSC 1337 capabilities and inline images" -- inline images AND Capabilities reporting, the same ITERM2FILE/1337 OSC number our ITERM2FILE registration collided with, causing a `duplicate case value` build error). Removed our ITERM2FILE entirely (Functions.h registration, Screen::iTerm2File, its switch case) in favor of upstream's ITERM2 / processITerm2 / reportITerm2Capabilities / renderITerm2InlineImage, same call as the earlier kitty graphics drop (see [[vendor-frontend-branch-split]] memory). Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01LzTmVgP2ruMz987VJ78k77 (cherry picked from commit 723b17f7d1b9ac9a260680ef04c33c20b61247e6) --- src/vtbackend/Screen.cpp | 1 + src/vtbackend/Sequence.hpp | 12 ++++++++---- src/vtbackend/Terminal.cpp | 5 +++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/vtbackend/Screen.cpp b/src/vtbackend/Screen.cpp index 824cbe1d..cb7cd777 100644 --- a/src/vtbackend/Screen.cpp +++ b/src/vtbackend/Screen.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include diff --git a/src/vtbackend/Sequence.hpp b/src/vtbackend/Sequence.hpp index a08da95b..dadd87c4 100644 --- a/src/vtbackend/Sequence.hpp +++ b/src/vtbackend/Sequence.hpp @@ -253,10 +253,14 @@ class SequenceParameterBuilder class Sequence { public: - // Make maximum size 50 kB since we need to support adding to the clipboard - // and the clipboard can contain large amounts of text. - size_t constexpr static MaxOscLength = - static_cast(1024 * 50); // NOLINT(readability-identifier-naming) + // The OSC payload buffer must hold not only clipboard text (OSC 52) but also inline images + // transmitted as a single OSC string (iTerm2 OSC 1337 File=). A base64-encoded image is ~4/3 of + // the raw size; a full RGBA image at the default maxImageSize (800x600 = ~1.9 MB) encodes to + // ~2.6 MB, so a clipboard-sized cap truncates every real image (base64 cut mid-stream -> decode + // fails). Raise the cap to 8 MB — enough for reasonable inline images while still bounding a + // runaway OSC stream. (Larger images should use a streaming protocol such as sixel, which does + // not buffer here.) + size_t constexpr static MaxOscLength = 1024 * 1024 * 8; // NOLINT(readability-identifier-naming) using Parameter = uint16_t; using Intermediaries = std::string; diff --git a/src/vtbackend/Terminal.cpp b/src/vtbackend/Terminal.cpp index 6e593b60..52091fe5 100644 --- a/src/vtbackend/Terminal.cpp +++ b/src/vtbackend/Terminal.cpp @@ -1489,6 +1489,11 @@ void Terminal::sendPaste(string_view text) _inputGenerator.generatePaste(text); flushInput(); + + // A paste is user input: snap the viewport back to the bottom so the pasted text lands in view, + // matching what sendKeyEvent() does for typed input (and what terminals conventionally do). The + // call is a no-op on the alt-screen via scrollToBottom()'s own guard. + scrollToBottomOnInput(); } void Terminal::sendRawInput(string_view text)