1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Change node linebreak handling to use "\n "

This commit is contained in:
Nick O'Leary 2020-06-22 13:08:35 +01:00
parent e548bf8bc2
commit 581f71911a
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -2220,31 +2220,24 @@ RED.view = (function() {
function convertLineBreakCharacter(str) {
var result = [];
var count = 0;
var result_temp = '';
for (var i = 0;i < str.length;i++) {
if (str.charAt(i) == '\\') {
if (str.charAt(i+1) == '\\') {
result_temp += str.charAt(i);
i++;
} else if (str.charAt(i+1) == 'n') {
result.push(result_temp.trim());
if (i+1 == str.length-1) {
result.push('');
}
result_temp = '';
count = i+2;
var lines = str.split(/\\n /);
if (lines.length > 1) {
var i=0;
for (i=0;i<lines.length - 1;i++) {
if (/\\$/.test(lines[i])) {
result.push(lines[i]+"\\n "+lines[i+1])
i++;
} else {
result_temp += str.charAt(i);
result.push(lines[i])
}
}
if ( i === lines.length - 1) {
result.push(lines[lines.length-1]);
}
} else {
result_temp += str.charAt(i);
}
}
if (count == 0 || count < str.length) {
result.push(result_temp.trim());
result = lines;
}
result = result.map(function(l) { return l.replace(/\\\\n /g,"\\n ").trim() })
return result;
}
@ -2543,10 +2536,10 @@ RED.view = (function() {
.attr("transform","translate("+x+","+y+")")
.attr("class","red-ui-flow-port-tooltip");
// First check for a user-provided newline - "\\n"
var newContent = content.split(/\\n/,1)[0];
if (newContent.length !== content.length) {
content = newContent+"...";
// First check for a user-provided newline - "\\n "
var newlineIndex = content.indexOf("\\n ");
if (newlineIndex > -1 && content[newlineIndex-1] !== '\\') {
content = content.substring(0,newlineIndex)+"...";
}
var lines = content.split("\n");