From 4d97922933a10b8d1049ee046132119ec755d8d2 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Thu, 24 Aug 2023 12:12:09 -0600 Subject: [PATCH] Better gathering of lines; don't add extra line terms --- core/multi_line_edit_text_view.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/core/multi_line_edit_text_view.js b/core/multi_line_edit_text_view.js index c5a508d4..d24ad1c3 100644 --- a/core/multi_line_edit_text_view.js +++ b/core/multi_line_edit_text_view.js @@ -288,18 +288,20 @@ function MultiLineEditTextView(options) { this.getOutputText = function (startIndex, endIndex, eolMarker, options) { const lines = self.getTextLines(startIndex, endIndex); - let text = ''; const re = new RegExp('\\t{1,' + self.tabWidth + '}', 'g'); - lines.forEach(line => { - text += line.text.replace(re, '\t'); - - if (options.forceLineTerms || (eolMarker && line.eol)) { - text += eolMarker; - } - }); - - return text; + return lines + .map((line, lineIndex) => { + let text = line.text.replace(re, '\t'); + if ( + options.forceLineTerms || + (eolMarker && line.eol && lineIndex < lines.length - 1) + ) { + text += eolMarker; + } + return text; + }) + .join(); }; this.getContiguousText = function (startIndex, endIndex, includeEol) {