diff --git a/src/browser/Clipboard.ts b/src/browser/Clipboard.ts index 1f9ea9ec3b..ec85b5836d 100644 --- a/src/browser/Clipboard.ts +++ b/src/browser/Clipboard.ts @@ -4,7 +4,7 @@ */ import { ISelectionService } from 'browser/services/Services'; -import { ICoreService } from 'common/services/Services'; +import { ICoreService, IOptionsService } from 'common/services/Services'; /** * Prepares text to be pasted into the terminal by normalizing the line endings @@ -40,17 +40,17 @@ export function copyHandler(ev: ClipboardEvent, selectionService: ISelectionServ /** * Redirect the clipboard's data to the terminal's input handler. */ -export function handlePasteEvent(ev: ClipboardEvent, textarea: HTMLTextAreaElement, coreService: ICoreService): void { +export function handlePasteEvent(ev: ClipboardEvent, textarea: HTMLTextAreaElement, coreService: ICoreService, optionsService: IOptionsService): void { ev.stopPropagation(); if (ev.clipboardData) { const text = ev.clipboardData.getData('text/plain'); - paste(text, textarea, coreService); + paste(text, textarea, coreService, optionsService); } } -export function paste(text: string, textarea: HTMLTextAreaElement, coreService: ICoreService): void { +export function paste(text: string, textarea: HTMLTextAreaElement, coreService: ICoreService, optionsService: IOptionsService): void { text = prepareTextForTerminal(text); - text = bracketTextForPaste(text, coreService.decPrivateModes.bracketedPasteMode); + text = bracketTextForPaste(text, coreService.decPrivateModes.bracketedPasteMode && optionsService.rawOptions.ignoreBracketedPasteMode !== true); coreService.triggerDataEvent(text, true); textarea.value = ''; } diff --git a/src/browser/Terminal.ts b/src/browser/Terminal.ts index 67ff404594..3f49c82533 100644 --- a/src/browser/Terminal.ts +++ b/src/browser/Terminal.ts @@ -352,7 +352,7 @@ export class Terminal extends CoreTerminal implements ITerminal { } copyHandler(event, this._selectionService!); })); - const pasteHandlerWrapper = (event: ClipboardEvent): void => handlePasteEvent(event, this.textarea!, this.coreService); + const pasteHandlerWrapper = (event: ClipboardEvent): void => handlePasteEvent(event, this.textarea!, this.coreService, this.optionsService); this.register(addDisposableDomListener(this.textarea!, 'paste', pasteHandlerWrapper)); this.register(addDisposableDomListener(this.element!, 'paste', pasteHandlerWrapper)); @@ -878,7 +878,7 @@ export class Terminal extends CoreTerminal implements ITerminal { } public paste(data: string): void { - paste(data, this.textarea!, this.coreService); + paste(data, this.textarea!, this.coreService, this.optionsService); } /** diff --git a/src/common/services/OptionsService.ts b/src/common/services/OptionsService.ts index 63ea2f1cda..cbeb618889 100644 --- a/src/common/services/OptionsService.ts +++ b/src/common/services/OptionsService.ts @@ -23,6 +23,7 @@ export const DEFAULT_OPTIONS: Readonly> = { fontSize: 15, fontWeight: 'normal', fontWeightBold: 'bold', + ignoreBracketedPasteMode: false, lineHeight: 1.0, letterSpacing: 0, linkHandler: null, diff --git a/src/common/services/Services.ts b/src/common/services/Services.ts index 3a1e5d8d8b..09b1108308 100644 --- a/src/common/services/Services.ts +++ b/src/common/services/Services.ts @@ -221,6 +221,7 @@ export interface ITerminalOptions { fontFamily?: string; fontWeight?: FontWeight; fontWeightBold?: FontWeight; + ignoreBracketedPasteMode?: boolean; letterSpacing?: number; lineHeight?: number; linkHandler?: ILinkHandler | null; diff --git a/test/api/Terminal.api.ts b/test/api/Terminal.api.ts index f1edf65c42..0171622313 100644 --- a/test/api/Terminal.api.ts +++ b/test/api/Terminal.api.ts @@ -132,9 +132,12 @@ describe('API Integration Tests', function(): void { window.term.paste('\\r\\nfoo\\nbar\\r'); window.term.write('\\x1b[?2004h', () => { window.term.paste('foo'); + + window.term.options.ignoreBracketedPasteMode = true; + window.term.paste('check_mode'); }); `); - await pollFor(page, `window.calls`, ['foo', '\rfoo\rbar\r', '\x1b[200~foo\x1b[201~']); + await pollFor(page, `window.calls`, ['foo', '\rfoo\rbar\r', '\x1b[200~foo\x1b[201~', 'check_mode']); }); it('clear', async () => { diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 19319c170f..954970dcf5 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -117,6 +117,13 @@ declare module 'xterm' { */ fontWeightBold?: FontWeight; + /** + * Whether to ignore the bracketed paste mode. When true, this will always + * paste without the `\x1b[200~` and `\x1b[201~` sequences, even when the + * shell enables bracketed mode. + */ + ignoreBracketedPasteMode?: boolean; + /** * The spacing in whole pixels between characters. */