Paste newlines as \r
Fix issue where non-windows OS terminals don't paste newlines correctly into misbehaving programs. As noted in JetBrains/jediterm#136, the most practical solution is for terminals to handle this in their paste logic. In a perfect world, all terminal programs would implement bracketed paste mode properly, but that's a lot to ask. - translate newlines to \r which is what terminal programs expect
This commit is contained in:
@@ -8,13 +8,19 @@ import * as Terminal from '../Terminal';
|
|||||||
import * as Clipboard from './Clipboard';
|
import * as Clipboard from './Clipboard';
|
||||||
|
|
||||||
describe('evaluatePastedTextProcessing', () => {
|
describe('evaluatePastedTextProcessing', () => {
|
||||||
it('should replace carriage return + line feed with line feed on windows', () => {
|
it('should replace carriage return and/or line feed with carriage return', () => {
|
||||||
const pastedText = 'foo\r\nbar\r\n';
|
const pastedText = {
|
||||||
const processedText = Clipboard.prepareTextForTerminal(pastedText, false);
|
unix: 'foo\nbar\n',
|
||||||
const windowsProcessedText = Clipboard.prepareTextForTerminal(pastedText, true);
|
windows: 'foo\r\nbar\r\n'
|
||||||
|
};
|
||||||
|
|
||||||
assert.equal(processedText, 'foo\r\nbar\r\n');
|
const processedText = {
|
||||||
assert.equal(windowsProcessedText, 'foo\rbar\r');
|
unix: Clipboard.prepareTextForTerminal(pastedText.unix),
|
||||||
|
windows: Clipboard.prepareTextForTerminal(pastedText.windows)
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.equal(processedText.unix, 'foo\rbar\r');
|
||||||
|
assert.equal(processedText.windows, 'foo\rbar\r');
|
||||||
});
|
});
|
||||||
it('should bracket pasted text in bracketedPasteMode', () => {
|
it('should bracket pasted text in bracketedPasteMode', () => {
|
||||||
const pastedText = 'foo bar';
|
const pastedText = 'foo bar';
|
||||||
|
|||||||
@@ -18,11 +18,8 @@ declare var window: IWindow;
|
|||||||
* Prepares text to be pasted into the terminal by normalizing the line endings
|
* Prepares text to be pasted into the terminal by normalizing the line endings
|
||||||
* @param text The pasted text that needs processing before inserting into the terminal
|
* @param text The pasted text that needs processing before inserting into the terminal
|
||||||
*/
|
*/
|
||||||
export function prepareTextForTerminal(text: string, isMSWindows: boolean): string {
|
export function prepareTextForTerminal(text: string): string {
|
||||||
if (isMSWindows) {
|
return text.replace(/\r?\n/g, '\r');
|
||||||
return text.replace(/\r?\n/g, '\r');
|
|
||||||
}
|
|
||||||
return text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,7 +59,7 @@ export function pasteHandler(ev: ClipboardEvent, term: ITerminal): void {
|
|||||||
let text: string;
|
let text: string;
|
||||||
|
|
||||||
let dispatchPaste = function(text: string): void {
|
let dispatchPaste = function(text: string): void {
|
||||||
text = prepareTextForTerminal(text, term.browser.isMSWindows);
|
text = prepareTextForTerminal(text);
|
||||||
text = bracketTextForPaste(text, term.bracketedPasteMode);
|
text = bracketTextForPaste(text, term.bracketedPasteMode);
|
||||||
term.handler(text);
|
term.handler(text);
|
||||||
term.textarea.value = '';
|
term.textarea.value = '';
|
||||||
|
|||||||
Reference in New Issue
Block a user