From d2a6221c2368e73da454cace4ccf8907807ba96f Mon Sep 17 00:00:00 2001 From: Grant Nestor Date: Fri, 14 Oct 2016 15:24:53 -0700 Subject: [PATCH] Fix: Carriage symbol should behave like in console --- notebook/static/base/js/utils.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/notebook/static/base/js/utils.js b/notebook/static/base/js/utils.js index f693056ea..66c1db918 100644 --- a/notebook/static/base/js/utils.js +++ b/notebook/static/base/js/utils.js @@ -444,12 +444,13 @@ define([ // Remove chunks that should be overridden by the effect of // carriage return characters function fixCarriageReturn(txt) { - var tmp = txt; - do { - txt = tmp; - tmp = txt.replace(/\r+\n/gm, '\n'); // \r followed by \n --> newline - tmp = tmp.replace(/^.*\r+/gm, ''); // Other \r --> clear line - } while (tmp.length < txt.length); + txt = txt.replace(/\r+\n/gm, '\n'); // \r followed by \n --> newline + while (txt.search(/\r/g) > -1) { + var base = txt.match(/^.*\r+/m)[0].replace(/\r/, ''); + var insert = txt.match(/\r+.*$/m)[0].replace(/\r/, ''); + insert = insert + base.slice(insert.length, base.length); + txt = txt.replace(/\r+.*$/m, '\r').replace(/^.*\r+/m, insert); + } return txt; }