Skip to content

Commit 97113d1

Browse files
authored
Merge pull request #341 from loopandlearn/line-wrap-bug
Fix crash for long lines without spaces
2 parents 5693828 + ab67a2f commit 97113d1

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

LoopFollow/Controllers/Graphs.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1803,8 +1803,26 @@ extension MainViewController {
18031803
if word.count > maxLineLength {
18041804
var wordToProcess = word
18051805
while !wordToProcess.isEmpty {
1806-
let availableSpace = maxLineLength - (currentLine.isEmpty ? 0 : currentLine.count + 1)
1806+
let spaceCount = currentLine.isEmpty ? 0 : 1
1807+
let availableSpace = maxLineLength - (currentLine.count + spaceCount)
1808+
1809+
if availableSpace <= 0 {
1810+
if !currentLine.isEmpty {
1811+
lines.append(currentLine)
1812+
currentLine = ""
1813+
}
1814+
continue
1815+
}
1816+
18071817
let takeCount = min(wordToProcess.count, availableSpace)
1818+
if takeCount <= 0 {
1819+
if !currentLine.isEmpty {
1820+
lines.append(currentLine)
1821+
currentLine = ""
1822+
}
1823+
continue
1824+
}
1825+
18081826
let index = wordToProcess.index(wordToProcess.startIndex, offsetBy: takeCount)
18091827
let substring = wordToProcess[..<index]
18101828

0 commit comments

Comments
 (0)