Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdeep committed Oct 1, 2024
1 parent 486b674 commit 4a25206
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 18 deletions.
36 changes: 18 additions & 18 deletions Proton/Sources/Swift/Core/LayoutManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,24 @@ class LayoutManager: NSLayoutManager {
}

var levelToSet = 0
textStorage.enumerateAttribute(.paragraphStyle, in: listRange, options: []) { value, range, _ in
levelToSet = 0
if let paraStyle = (value as? NSParagraphStyle)?.mutableParagraphStyle {
let previousLevel = Int(prevStyle?.firstLineHeadIndent ?? 0)/Int(listIndent)
let currentLevel = Int(paraStyle.firstLineHeadIndent)/Int(listIndent)

if currentLevel - previousLevel > 1 {
levelToSet = previousLevel + 1
let indentation = CGFloat(levelToSet) * listIndent
paraStyle.firstLineHeadIndent = indentation
paraStyle.headIndent = indentation
textStorage.addAttribute(.paragraphStyle, value: paraStyle, range: range)
prevStyle = paraStyle
} else {
prevStyle = value as? NSParagraphStyle
}
}
}
// textStorage.enumerateAttribute(.paragraphStyle, in: listRange, options: []) { value, range, _ in
// levelToSet = 0
// if let paraStyle = (value as? NSParagraphStyle)?.mutableParagraphStyle {
// let previousLevel = Int(prevStyle?.firstLineHeadIndent ?? 0)/Int(listIndent)
// let currentLevel = Int(paraStyle.firstLineHeadIndent)/Int(listIndent)
//
// if currentLevel - previousLevel > 1 {
// levelToSet = previousLevel + 1
// let indentation = CGFloat(levelToSet) * listIndent
// paraStyle.firstLineHeadIndent = indentation
// paraStyle.headIndent = indentation
// textStorage.addAttribute(.paragraphStyle, value: paraStyle, range: range)
// prevStyle = paraStyle
// } else {
// prevStyle = value as? NSParagraphStyle
// }
// }
// }

let listGlyphRange = glyphRange(forCharacterRange: listRange, actualCharacterRange: nil)
previousLevel = 0
Expand Down
24 changes: 24 additions & 0 deletions Proton/Sources/Swift/Helpers/NSAttributedString+Range.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,28 @@ public extension NSAttributedString {
let range = NSRange(location: searchTextRange.location, length: searchText.count)
return range
}

func attributedSubstringOrClamped(from range: NSRange) -> NSAttributedString {
let clamped = range.clamped(upperBound: length)
return attributedSubstring(from: clamped)
}

func substringOrClamped(from range: NSRange) -> String {
let clamped = range.clamped(upperBound: length)
return (string as NSString).substring(with: clamped)
}

func attributeOrNil(_ key: NSAttributedString.Key, at location: Int) -> Any? {
return attributesOrEmpty(at: location)[key]
}

func attributesOrEmpty(at location: Int) -> [NSAttributedString.Key: Any] {
guard self.length != 0, location >= 0, location < length else { return [:] }
return attributes(at: location, effectiveRange: nil)
}

func containsAttribute(_ key: NSAttributedString.Key, at location: Int) -> Bool {
attributesOrEmpty(at: location).keys.contains(key)
}

}

0 comments on commit 4a25206

Please sign in to comment.