Skip to content

Commit

Permalink
minor refactor. use default paragraph
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyzanowskim committed Aug 21, 2024
1 parent 153665b commit 6cb3374
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions Sources/STTextViewAppKit/STTextLayoutFragment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import AppKit
import STObjCLandShim

final class STTextLayoutFragment: NSTextLayoutFragment {
private let paragraphStyle: NSParagraphStyle
private let defaultParagraphStyle: NSParagraphStyle
var showsInvisibleCharacters: Bool = false

init(textElement: NSTextElement, range rangeInElement: NSTextRange?, paragraphStyle: NSParagraphStyle) {
self.paragraphStyle = paragraphStyle
self.defaultParagraphStyle = paragraphStyle
super.init(textElement: textElement, range: rangeInElement)
}

required init?(coder: NSCoder) {
self.paragraphStyle = NSParagraphStyle.default
self.defaultParagraphStyle = NSParagraphStyle.default
self.showsInvisibleCharacters = false
super.init(coder: coder)
}
Expand Down Expand Up @@ -63,7 +63,7 @@ final class STTextLayoutFragment: NSTextLayoutFragment {
{
paragraphStyle = lineParagraphStyle
} else {
paragraphStyle = self.paragraphStyle
paragraphStyle = self.defaultParagraphStyle
}

if !paragraphStyle.lineHeightMultiple.isAlmostZero() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extension STTextView: NSTextLayoutManagerDelegate {
let textLayoutFragment = STTextLayoutFragment(
textElement: textElement,
range: textElement.elementRange,
paragraphStyle: typingAttributes[.paragraphStyle] as? NSParagraphStyle ?? .default
paragraphStyle: _defaultTypingAttributes[.paragraphStyle] as? NSParagraphStyle ?? .default
)
return textLayoutFragment
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/STTextViewAppKit/STTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ import AVFoundation
}

/// Default typing attributes used in place of missing attributes of font, color and paragraph
private var _defaultTypingAttributes: [NSAttributedString.Key: Any]
internal var _defaultTypingAttributes: [NSAttributedString.Key: Any]

/// The attributes to apply to new text that the user enters.
///
Expand Down
8 changes: 4 additions & 4 deletions Sources/STTextViewUIKit/STTextLayoutFragment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import UIKit
import STObjCLandShim

final class STTextLayoutFragment: NSTextLayoutFragment {
private let paragraphStyle: NSParagraphStyle
private let defaultParagraphStyle: NSParagraphStyle
var showsInvisibleCharacters: Bool = false

init(textElement: NSTextElement, range rangeInElement: NSTextRange?, paragraphStyle: NSParagraphStyle) {
self.paragraphStyle = paragraphStyle
self.defaultParagraphStyle = paragraphStyle
super.init(textElement: textElement, range: rangeInElement)
}

required init?(coder: NSCoder) {
self.paragraphStyle = NSParagraphStyle.default
self.defaultParagraphStyle = NSParagraphStyle.default
self.showsInvisibleCharacters = false
super.init(coder: coder)
}
Expand Down Expand Up @@ -64,7 +64,7 @@ final class STTextLayoutFragment: NSTextLayoutFragment {
{
paragraphStyle = lineParagraphStyle
} else {
paragraphStyle = self.paragraphStyle
paragraphStyle = self.defaultParagraphStyle
}

if !paragraphStyle.lineHeightMultiple.isAlmostZero() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extension STTextView: NSTextLayoutManagerDelegate {
STTextLayoutFragment(
textElement: textElement,
range: textElement.elementRange,
paragraphStyle: typingAttributes[.paragraphStyle] as? NSParagraphStyle ?? .default
paragraphStyle: _defaultTypingAttributes[.paragraphStyle] as? NSParagraphStyle ?? .default
)
}
}
2 changes: 1 addition & 1 deletion Sources/STTextViewUIKit/STTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ import STTextViewCommon
}

/// Default typing attributes used in place of missing attributes of font, color and paragraph
private var _defaultTypingAttributes: [NSAttributedString.Key: Any]
internal var _defaultTypingAttributes: [NSAttributedString.Key: Any]

/// The attributes to apply to new text that the user enters.
///
Expand Down

0 comments on commit 6cb3374

Please sign in to comment.