mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-26 01:14:09 +02:00
Fix flowchart failure
This commit is contained in:
@@ -53,6 +53,8 @@ describe('split lines', () => {
|
|||||||
{ str: 'hello 12 world', width: 4, split: ['hell', 'o 12', 'worl', 'd'] },
|
{ str: 'hello 12 world', width: 4, split: ['hell', 'o 12', 'worl', 'd'] },
|
||||||
{ str: 'hello 1 2 world', width: 4, split: ['hell', 'o 1', '2', 'worl', 'd'] },
|
{ str: 'hello 1 2 world', width: 4, split: ['hell', 'o 1', '2', 'worl', 'd'] },
|
||||||
{ str: 'hello 1 2 world', width: 6, split: ['hello', ' 1 2', 'world'] },
|
{ str: 'hello 1 2 world', width: 6, split: ['hello', ' 1 2', 'world'] },
|
||||||
|
// width = 0, impossible, so split into individual characters
|
||||||
|
{ str: '🏳️⚧️🏳️🌈👩🏾❤️👨🏻', width: 0, split: ['🏳️⚧️', '🏳️🌈', '👩🏾❤️👨🏻'] },
|
||||||
{ str: '🏳️⚧️🏳️🌈👩🏾❤️👨🏻', width: 1, split: ['🏳️⚧️', '🏳️🌈', '👩🏾❤️👨🏻'] },
|
{ str: '🏳️⚧️🏳️🌈👩🏾❤️👨🏻', width: 1, split: ['🏳️⚧️', '🏳️🌈', '👩🏾❤️👨🏻'] },
|
||||||
{ str: '🏳️⚧️🏳️🌈👩🏾❤️👨🏻', width: 2, split: ['🏳️⚧️🏳️🌈', '👩🏾❤️👨🏻'] },
|
{ str: '🏳️⚧️🏳️🌈👩🏾❤️👨🏻', width: 2, split: ['🏳️⚧️🏳️🌈', '👩🏾❤️👨🏻'] },
|
||||||
{ str: '🏳️⚧️🏳️🌈👩🏾❤️👨🏻', width: 3, split: ['🏳️⚧️🏳️🌈👩🏾❤️👨🏻'] },
|
{ str: '🏳️⚧️🏳️🌈👩🏾❤️👨🏻', width: 3, split: ['🏳️⚧️🏳️🌈👩🏾❤️👨🏻'] },
|
||||||
|
|||||||
@@ -67,6 +67,11 @@ function splitWordToFitWidthRecursion(
|
|||||||
if (checkFit([{ content: newWord.join(''), type }])) {
|
if (checkFit([{ content: newWord.join(''), type }])) {
|
||||||
return splitWordToFitWidthRecursion(checkFit, newWord, rest, type);
|
return splitWordToFitWidthRecursion(checkFit, newWord, rest, type);
|
||||||
}
|
}
|
||||||
|
if (usedChars.length === 0 && nextChar) {
|
||||||
|
// If the first character does not fit, split it anyway
|
||||||
|
usedChars.push(nextChar);
|
||||||
|
remainingChars.shift();
|
||||||
|
}
|
||||||
return [
|
return [
|
||||||
{ content: usedChars.join(''), type },
|
{ content: usedChars.join(''), type },
|
||||||
{ content: remainingChars.join(''), type },
|
{ content: remainingChars.join(''), type },
|
||||||
@@ -127,7 +132,9 @@ function splitLineToFitWidthRecursion(
|
|||||||
// There was no text in newLine, so we need to split nextWord
|
// There was no text in newLine, so we need to split nextWord
|
||||||
const [line, rest] = splitWordToFitWidth(checkFit, nextWord);
|
const [line, rest] = splitWordToFitWidth(checkFit, nextWord);
|
||||||
lines.push([line]);
|
lines.push([line]);
|
||||||
|
if (rest.content) {
|
||||||
words.unshift(rest);
|
words.unshift(rest);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return splitLineToFitWidthRecursion(words, checkFit, lines);
|
return splitLineToFitWidthRecursion(words, checkFit, lines);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user