Skip to content

Commit

Permalink
List bullet positioning and first line paragraph spacing before
Browse files Browse the repository at this point in the history
Summary: If something is the first line in the document, TextKit doesn't apply a paragraphSpacingBefore value. Our list bullet drawing code compensates for paragraphSpacingBefore. This was causing us to draw incorrectly positioned bullets if paragraphSpacingBefore was used and the list was the first thing in the document.

Differential Revision: D54380971

fbshipit-source-id: 04156ede936686c74c1294ab612430570c55c596
  • Loading branch information
Amy Worrall authored and facebook-github-bot committed Mar 1, 2024
1 parent 46baef0 commit dbf738c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Plugins/LexicalListPlugin/LexicalListPlugin/ListPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ open class ListPlugin: Plugin {
return
}

let isFirstLine = (glyphRange.location == 0)

var attributes = textStorage.attributes(at: characterRange.location, effectiveRange: nil)

var spacingBefore = 0.0
if let paragraphStyle = attributes[.paragraphStyle] as? NSParagraphStyle, let mutableParagraphStyle = paragraphStyle.mutableCopy() as? NSMutableParagraphStyle {
mutableParagraphStyle.headIndent = 0
mutableParagraphStyle.firstLineHeadIndent = 0
mutableParagraphStyle.tailIndent = 0
spacingBefore = paragraphStyle.paragraphSpacingBefore
spacingBefore = isFirstLine ? 0 : paragraphStyle.paragraphSpacingBefore
mutableParagraphStyle.paragraphSpacingBefore = 0
attributes[.paragraphStyle] = mutableParagraphStyle
}
Expand Down

0 comments on commit dbf738c

Please sign in to comment.