Skip to content

Use bracketed paste for multiline executed terminal text#302526

Draft
jcansdale wants to merge 1 commit intomicrosoft:mainfrom
jcansdale:jcansdale/terminal-multiline-bracketed-paste
Draft

Use bracketed paste for multiline executed terminal text#302526
jcansdale wants to merge 1 commit intomicrosoft:mainfrom
jcansdale:jcansdale/terminal-multiline-bracketed-paste

Conversation

@jcansdale
Copy link
Contributor

@jcansdale jcansdale commented Mar 17, 2026

Summary

  • apply bracketed paste automatically when sending multiline terminal text and the terminal supports it
  • keep existing explicit bracketed-paste behavior intact for callers that already request it
  • add a terminal instance unit test that covers multiline executed text

Why This Is Required

Executed multiline text currently goes through sendText(..., true) without bracketed paste unless a caller explicitly opts in. That means the terminal receives the payload as raw typed input instead of a pasted block.

For single-line text that is fine, but for multiline commands it changes shell behavior. Embedded newlines are handled like Enter presses, readline and keybindings can interfere, and quoting can break before the final execute is sent. Shell integration and chat terminal execution both rely on this path, so the bug shows up in real command execution.

Repro

  1. Run the following in the terminal verbatim
echo 'L01 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
L02 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
L03 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
L04 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
L05 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
L06 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
L07 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
L08 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
L09 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
L10 aaaaaaaaaaaaaaaaaa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aaa
quote> L09 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
quote> L10 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
quote> L11 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
quote> L12 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
quote> L13 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
quote> L14 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
quote> L15 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
quote> L16 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
quote> L17 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
quote> L18 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
quote> L19 aaaaaL02 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
quote>

Expected result

1064
1064

Before this change, repeated runs of the same multiline payload in a live terminal session could behave inconsistently. During debugging this showed up as wrong counts, replayed stale fragments, or a continuation prompt instead of a clean result.

Copilot AI review requested due to automatic review settings March 17, 2026 18:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates TerminalInstance.sendText to automatically wrap multiline text in bracketed paste sequences when the terminal has bracketed paste mode enabled, and adds a unit test to cover the multiline executed-text behavior.

Changes:

  • Automatically enable bracketed paste wrapping when sendText receives multiline text and xterm reports bracketed paste mode is enabled.
  • Preserve existing behavior for callers explicitly requesting bracketed paste mode.
  • Add a unit test validating multiline executed text is sent wrapped in bracketed paste sequences.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/vs/workbench/contrib/terminal/browser/terminalInstance.ts Adjusts sendText to auto-apply bracketed paste for multiline text when supported/enabled.
src/vs/workbench/contrib/terminal/test/browser/terminalInstance.test.ts Adds a regression/unit test for multiline executed text using bracketed paste, and refactors instance creation into a helper.

terminalInstance = store.add(instantiationService.createInstance(TerminalInstance, terminalShellTypeContextKey, {}));
// //Wait for the teminalInstance._xtermReadyPromise to resolve
const instance = store.add(instantiationService.createInstance(TerminalInstance, terminalShellTypeContextKey, {}));
await new Promise(resolve => setTimeout(resolve, 100));
@jcansdale jcansdale marked this pull request as draft March 17, 2026 19:06
@microsoft microsoft deleted a comment Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants