When rendering a TextBlock with maxLines, I sometimes get too many text lines and extra empty lines added to the end of the block.
It occurs rarely, and seems to be related to long word wrapping mixed with line breaks (\n
) in the text. I can fix by replacing all line breaks with spaces. But we are rendering dynamic user input, and they like to use line breaks to format their text.
import * as go from 'gojs';
const myDiagram = new go.Diagram('myDiagramDiv');
const longWordsSpaces = `longwordlongwordlongwordlongwordlongwordlongword longwordlongwordlongwordlongwordlongwordlongword longwordlongwordlongwordlongwordlongwordlongword longwordlongwordlongwordlongwordlongwordlongword`;
const longWordsLineBreaks = `longwordlongwordlongwordlongwordlongwordlongword
longwordlongwordlongwordlongwordlongwordlongword
longwordlongwordlongwordlongwordlongwordlongword
longwordlongwordlongwordlongwordlongwordlongword`;
const textBlockOptions = {
background: 'lightgreen',
margin: 10,
width: 200,
maxLines: 3,
};
myDiagram.add(
new go.Part('Horizontal').add(
new go.TextBlock({
text: longWordsSpaces,
...textBlockOptions,
}),
new go.TextBlock({
text: longWordsLineBreaks,
...textBlockOptions,
})
)
);