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:
commit
0a3ab996eb
@ -98,18 +98,36 @@ RED.palette = (function() {
|
|||||||
|
|
||||||
var displayLines = [];
|
var displayLines = [];
|
||||||
|
|
||||||
var currentLine = words[0];
|
var currentLine = "";
|
||||||
var currentLineWidth = RED.view.calculateTextWidth(currentLine, "red-ui-palette-label", 0);
|
for (var i=0;i<words.length;i++) {
|
||||||
|
var word = words[i];
|
||||||
for (var i=1;i<words.length;i++) {
|
var sep = (i == 0) ? "" : " ";
|
||||||
var newWidth = RED.view.calculateTextWidth(currentLine+" "+words[i], "red-ui-palette-label", 0);
|
var newWidth = RED.view.calculateTextWidth(currentLine+sep+word, "red-ui-palette-label", 0);
|
||||||
if (newWidth < nodeWidth) {
|
if (newWidth < nodeWidth) {
|
||||||
currentLine += " "+words[i];
|
currentLine += sep +word;
|
||||||
currentLineWidth = newWidth;
|
|
||||||
} else {
|
} else {
|
||||||
displayLines.push(currentLine);
|
if (i > 0) {
|
||||||
currentLine = words[i];
|
displayLines.push(currentLine);
|
||||||
currentLineWidth = RED.view.calculateTextWidth(currentLine, "red-ui-palette-label", 0);
|
}
|
||||||
|
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);
|
displayLines.push(currentLine);
|
||||||
|
Loading…
Reference in New Issue
Block a user