mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Merge pull request #659 from jdanyow/paste
Normalize line endings on paste
This commit is contained in:
@@ -16,3 +16,14 @@ describe('evaluateCopiedTextProcessing', function () {
|
||||
assert.equal(processedText.indexOf(nonBreakingSpace), -1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('evaluatePastedTextProcessing', function () {
|
||||
it('should replace carriage return + line feed with line feed on windows', function () {
|
||||
const pastedText = 'foo\r\nbar\r\n',
|
||||
processedText = Clipboard.prepareTextForTerminal(pastedText, false),
|
||||
windowsProcessedText = Clipboard.prepareTextForTerminal(pastedText, true);
|
||||
|
||||
assert.equal(processedText, 'foo\r\nbar\r\n');
|
||||
assert.equal(windowsProcessedText, 'foo\nbar\n');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -38,6 +38,17 @@ export function prepareTextForClipboard(text: string): string {
|
||||
return processedText;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
export function prepareTextForTerminal(text: string, isMSWindows: boolean): string {
|
||||
if (isMSWindows) {
|
||||
return text.replace(/\r?\n/g, '\n');
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds copy functionality to the given terminal.
|
||||
* @param {ClipboardEvent} ev The original copy event to be handled
|
||||
@@ -68,6 +79,7 @@ export function pasteHandler(ev: ClipboardEvent, term: ITerminal) {
|
||||
let text: string;
|
||||
|
||||
let dispatchPaste = function(text) {
|
||||
text = prepareTextForTerminal(text, term.browser.isMSWindows);
|
||||
term.handler(text);
|
||||
term.textarea.value = '';
|
||||
return term.cancel(ev);
|
||||
|
||||
Reference in New Issue
Block a user