Closed cdoky closed 5 years ago
+1
@mdilaveroglu if you have not solution,you can use mine
@philCc could you include your solution?
@ngocholo
...
// Truncation.swift:48
for (index, tokenLine) in tokenLines.enumerated() {
let originalIndex = self.numberOfLines - tokenLines.count + index
// We want to replace every other line besides the first truncated line completely with the lines from the truncation token
if originalIndex < 0 {
continue
}
guard index == 0 else {
lines[originalIndex] = tokenLine
continue
}
...
@philCc @mdilaveroglu do either of you have an example of how to get this to happen? I see we can band-aid it by skipping any elements that are outside the index and we should probably add some defense there, but I'd like to understand how we get into this case better, since it points that something else with the truncation code is wrong.
@chansen22 init with label.lineBreakMode = .byTruncatingTail,but then setAttributedText with paragraphStyle.lineBreakMode = .byWordWrapping
@guyueming I tried with just creating the label, setting its lineBreak mode and then setting the attributedString with a paragraph style that was just .byWordWrapping, but had no luck. The code I pasted is a combo of the info inside @philCc's debugger output, but I can't get it to crash. Can you share a direct example of how you get this to occur? The setup + the string used?
let label: NantesLabel = .init(frame: CGRect(x: 5, y: 40, width: 5, height: 20))
label.kern = 1.0
label.lineBreakMode = .byTruncatingTail
let paragraph = NSMutableParagraphStyle()
paragraph.lineBreakMode = .byWordWrapping
paragraph.paragraphSpacing = 0
paragraph.alignment = NSTextAlignment(rawValue: 4)!
paragraph.lineSpacing = 1
paragraph.paragraphSpacingBefore = 0
paragraph.headIndent = 0
paragraph.tailIndent = 0
paragraph.firstLineHeadIndent = 0
paragraph.lineHeightMultiple = 0
paragraph.baseWritingDirection = NSWritingDirection(rawValue: -1)!
let attributedText = NSAttributedString(string: "\u{2026}", attributes: [NSAttributedString.Key.paragraphStyle: paragraph])
label.attributedText = attributedText
view.addSubview(label)
@chansen22
let label: NantesLabel = .init(frame: CGRect(x: 5, y: 40, width: 5, height: 20))
label.numberOfLines = 0
label.kern = 1.0
label.lineBreakMode = .byTruncatingTail
let paragraph = NSMutableParagraphStyle()
paragraph.lineBreakMode = .byWordWrapping
paragraph.paragraphSpacing = 0
paragraph.alignment = NSTextAlignment(rawValue: 4)!
paragraph.lineSpacing = 1
paragraph.paragraphSpacingBefore = 0
paragraph.headIndent = 0
paragraph.tailIndent = 0
paragraph.firstLineHeadIndent = 0
paragraph.lineHeightMultiple = 0
paragraph.baseWritingDirection = NSWritingDirection(rawValue: -1)!
let attributedText = NSAttributedString(string: "The text is long enough to be wrapped", attributes: [NSAttributedString.Key.paragraphStyle: paragraph])
label.attributedText = attributedText
view.addSubview(label)
// numberOfLines = 0 // tokenLines.count = 1 // index = 0 // originalIndex = -1 Truncation.swift:49 let originalIndex = self.numberOfLines - tokenLines.count + index
crash on Truncation.swift:57 let originalLine = lines[originalIndex]