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

Merge pull request #2290 from node-red-hitachi/fix-node-name-breaking

allow word breaking of node name with long word
This commit is contained in:
Nick O'Leary 2019-09-20 13:08:34 +01:00 committed by GitHub
commit 0a3ab996eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -98,18 +98,36 @@ RED.palette = (function() {
var displayLines = [];
var currentLine = words[0];
var currentLineWidth = RED.view.calculateTextWidth(currentLine, "red-ui-palette-label", 0);
for (var i=1;i<words.length;i++) {
var newWidth = RED.view.calculateTextWidth(currentLine+" "+words[i], "red-ui-palette-label", 0);
var currentLine = "";
for (var i=0;i<words.length;i++) {
var word = words[i];
var sep = (i == 0) ? "" : " ";
var newWidth = RED.view.calculateTextWidth(currentLine+sep+word, "red-ui-palette-label", 0);
if (newWidth < nodeWidth) {
currentLine += " "+words[i];
currentLineWidth = newWidth;
currentLine += sep +word;
} else {
displayLines.push(currentLine);
currentLine = words[i];
currentLineWidth = RED.view.calculateTextWidth(currentLine, "red-ui-palette-label", 0);
if (i > 0) {
displayLines.push(currentLine);
}
while (true) {
var wordWidth = RED.view.calculateTextWidth(word, "red-ui-palette-label", 0);
if (wordWidth >= nodeWidth) {
// break word if too wide
for(var j = word.length; j > 0; j--) {
var s = word.substring(0, j);
var width = RED.view.calculateTextWidth(s, "red-ui-palette-label", 0);
if (width < nodeWidth) {
displayLines.push(s);
word = word.substring(j);
break;
}
}
}
else {
currentLine = word;
break;
}
}
}
}
displayLines.push(currentLine);