Skip to content

tui: expand paste placeholder when the same text is pasted again #916

Closed

Description

@plakunov

Problem

When pasting 5+ lines of text into the input line, jcode collapses the paste into a [pasted N lines] placeholder (existing, intended behavior — avoids flooding the input line with a huge block of text).

Once collapsed, there's no way to review or edit that content from the input line. The only way to get the text back is to clear the input and re-paste from your clipboard/paste buffer, which is awkward mid-message (e.g. you collapsed a big block, then want to tweak one line of it before sending).

Other paste-collapsing composers solve this with a "paste to collapse, paste the same content again to expand" gesture: paste once and it collapses to a placeholder, paste that exact same content again while the placeholder is still there and it expands back into the full text in place.

Proposed fix

I implemented this for jcode:

  • Pasting text with 5+ lines still collapses into [pasted N lines] and stores the content in pasted_contents, as today.
  • If you paste that exact same text again while its placeholder is still present, unedited, in the input, the placeholder is replaced with the full text in place (cursor moves to the end of the expanded text), and the entry is removed from pasted_contents.
  • Pasting different text still collapses into a new placeholder, as before — no accidental expansion of an unrelated placeholder.

Reproduction / test case

Added as unit tests in crates/jcode-tui/src/tui/app/tests/remote_startup_input_03/part_01.rs:

#[test]
fn test_paste_again_expands_the_placeholder_in_place() {
    let mut app = create_test_app();
    let big = "a\nb\nc\nd\ne".to_string();

    // First paste collapses to a placeholder and remembers the content.
    app.handle_paste(big.clone());
    assert_eq!(app.input(), "[pasted 5 lines]");
    assert_eq!(app.pasted_contents.len(), 1);

    // Pasting the exact same text again expands the existing placeholder
    // instead of appending a second one.
    app.handle_paste(big.clone());
    assert_eq!(app.input(), big);
    assert!(app.pasted_contents.is_empty());
    assert_eq!(app.cursor_pos, big.len());
}

#[test]
fn test_paste_again_with_different_text_still_collapses() {
    let mut app = create_test_app();
    app.handle_paste("a\nb\nc\nd\ne".to_string());
    assert_eq!(app.input(), "[pasted 5 lines]");

    // A different large paste does not match the stored content, so it
    // collapses into its own placeholder rather than expanding the first one.
    app.handle_paste("f\ng\nh\ni\nj".to_string());
    assert_eq!(app.input(), "[pasted 5 lines][pasted 5 lines]");
    assert_eq!(app.pasted_contents.len(), 2);
}

Ran locally on Windows:

cargo test -p jcode-tui paste_again
running 2 tests
test tui::app::tests::test_paste_again_with_different_text_still_collapses ... ok
test tui::app::tests::test_paste_again_expands_the_placeholder_in_place ... ok
test result: ok. 2 passed; 0 failed

Full existing handle_text_paste test suite (test_handle_paste_large, test_paste_expansion_on_submit, test_multiple_pastes, etc.) also passes unchanged.

Implementation reference

I have a small, focused diff (crates/jcode-tui/src/tui/app/input.rs + the test file above, 57 insertions / 8 deletions) on my fork, in case it's useful as a reference per CONTRIBUTING.md:

plakunov/jcode@master...plakunov:jcode:feature/paste-again-to-expand

(Repository interaction settings currently limit opening PRs to collaborators, so I'm filing this as an issue with the branch linked instead, per the "issues vs pull requests" guidance in CONTRIBUTING.md.)

Edge cases / tradeoffs considered

  • Match is on exact text equality against the most recently pushed matching entry in pasted_contents (rposition), and requires the placeholder to still be found verbatim in the current input (rfind) — so if the user edited the input around the placeholder text itself, or the placeholder is no longer present, it just collapses normally instead of expanding.
  • Only the closest/most recent matching stored content is removed from pasted_contents, not all occurrences, to avoid clobbering an unrelated earlier paste of identical content.
  • Didn't touch the <5-line short-paste path, which inserts text directly and was already correct.

Activity

  1. added
    enhancement
    priority: low
    autonomous: clear
    ux
    on Aug 13, 2026
  2. 1jehuang commented on Aug 13, 2026

    @1jehuang
    Owner

    I implemented repeat-paste expansion in place, including duplicate and same-sized placeholder edge cases. Focused and broader paste tests pass. Fix: #918.

    --- — Jcode agent (automated triage), on behalf of @1jehuang

  3. added
    triage: fixed-pending-release
    on Aug 13, 2026
  4. added a commit that references this issue on Aug 13, 2026
    2c2f4f2
  5. added a commit that references this issue on Aug 15, 2026
    a8e0afd
  6. added a commit that references this issue on Aug 28, 2026
    877e57f
  7. added 5 commits that reference this issue on Aug 30, 2026
    31f4b5e
    aa1f3a9
    58804d5
    019db41
    b675afa
  8. added a commit that references this issue on Sep 18, 2026
    7e3b23a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    autonomous: clearenhancementpriority: lowtriage: fixed-pending-releaseux

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions