Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for different bullets by UL indentation level #1173

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TextListFormatter: ParagraphAttributeFormatter {
newParagraphStyle.setParagraphStyle(paragraphStyle)
}

let newList = TextList(style: self.listStyle, with: representation)
let newList = TextList(style: self.listStyle, with: representation, level: newParagraphStyle.lists.count)
if newParagraphStyle.lists.isEmpty || increaseDepth {
newParagraphStyle.insertProperty(newList, afterLastOfType: HTMLLi.self)
} else {
Expand Down
2 changes: 1 addition & 1 deletion Aztec/Classes/TextKit/LayoutManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private extension LayoutManager {
let paragraphAttributes = textStorage.attributes(at: location, effectiveRange: nil)
let markerAttributes = markerAttributesBasedOnParagraph(attributes: paragraphAttributes)

let markerPlain = list.style.markerText(forItemNumber: number)
let markerPlain = list.style.markerText(forItemNumber: number, level: list.level)
let markerText = NSAttributedString(string: markerPlain, attributes: markerAttributes)

var yOffset = CGFloat(0)
Expand Down
26 changes: 23 additions & 3 deletions Aztec/Classes/TextKit/ParagraphProperty/TextList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,21 @@ open class TextList: ParagraphProperty {
case ordered
case unordered

func markerText(forItemNumber number: Int) -> String {
func markerText(forItemNumber number: Int, level: Int) -> String {
switch self {
case .ordered: return "\t\(number)."
case .unordered: return "\t\u{2022}"
case .unordered: return unorderedMarker(for: level)
}
}

func unorderedMarker(for level: Int) -> String {
switch level {
case 0:
return "\t\u{2022}"
default:
// Using the same black bullet for now until Android side is able to edit bullets by level too.
// Then this should be updated to "{25E6}"
return "\t\u{2022}"
}
}
}
Expand All @@ -27,9 +38,11 @@ open class TextList: ParagraphProperty {
/// Kind of List: Ordered / Unordered
///
let style: Style
let level: Int

init(style: Style, with representation: HTMLRepresentation? = nil) {
init(style: Style, with representation: HTMLRepresentation? = nil, level: Int = 0) {
self.style = style
self.level = level
super.init(with: representation)
}

Expand All @@ -40,12 +53,19 @@ open class TextList: ParagraphProperty {
} else {
style = .ordered
}
if aDecoder.containsValue(forKey: String(describing: \TextList.level)) {
level = aDecoder.decodeInteger(forKey: String(describing: \TextList.level))
} else {
level = 0
}

super.init(coder: aDecoder)
}

public override func encode(with aCoder: NSCoder) {
super.encode(with: aCoder)
aCoder.encode(style.rawValue, forKey: String(describing: Style.self))
aCoder.encode(level, forKey: String(describing: \TextList.level))
}

public static func ==(lhs: TextList, rhs: TextList) -> Bool {
Expand Down