From fa1cd89aa9feae2e5dfb5aa669ed6964dbf8db48 Mon Sep 17 00:00:00 2001 From: Paris Date: Fri, 10 Jun 2016 16:17:14 +0300 Subject: [PATCH] Fix copying of non-breaking spaces --- src/xterm.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/xterm.js b/src/xterm.js index a806a03d..5984e7db 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -551,13 +551,22 @@ /** - * Bind copy event. Stript trailing whitespaces from selection. + * Bind copy event. */ Terminal.bindCopy = function(term) { on(term.element, 'copy', function(ev) { - var selectedText = window.getSelection().toString(), + var space = String.fromCharCode(32), + nonBreakingSpace = String.fromCharCode(160), + allNonBreakingSpaces = new RegExp(nonBreakingSpace, 'g'), + selectedText = window.getSelection().toString(), copiedText = selectedText.split('\n').map(function (element) { - return element.replace(/\s+$/g, ''); + /** + * Strip all trailing white spaces and convert all non-breaking spaces to regular + * spaces. + */ + var line = element.replace(/\s+$/g, '').replace(allNonBreakingSpaces, space); + + return line; }).join('\n'); ev.clipboardData.setData('text/plain', copiedText); ev.preventDefault();