mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-17 14:17:13 +03:00
Refactor TextContainer
This commit is contained in:
parent
1f160ae717
commit
58ff98f56b
@ -858,6 +858,17 @@ final class EditorTextView: NSTextView, Themable, CurrentLineHighlighting, Multi
|
||||
}
|
||||
|
||||
|
||||
override var typingAttributes: [NSAttributedString.Key: Any] {
|
||||
|
||||
didSet {
|
||||
// -> The font can differ from the specified text font while typing marked text.
|
||||
guard self.hasMarkedText() != true else { return }
|
||||
|
||||
(self.textContainer as? TextContainer)?.indentAttributes = typingAttributes
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override var font: NSFont? {
|
||||
|
||||
get {
|
||||
|
@ -32,33 +32,17 @@ final class TextContainer: NSTextContainer {
|
||||
var isHangingIndentEnabled = false { didSet { self.invalidateLayout() } }
|
||||
var hangingIndentWidth = 0 { didSet { self.invalidateLayout() } }
|
||||
|
||||
var indentAttributes: [NSAttributedString.Key: Any] = [:] { didSet { self.indentWidthCache.removeAll() } }
|
||||
|
||||
|
||||
// MARK: Private Properties
|
||||
|
||||
private var indentWidthCache: [String: CGFloat] = [:]
|
||||
private var indentAttributes: [NSAttributedString.Key: Any] = [:]
|
||||
private var typingAttributesObservation: NSKeyValueObservation?
|
||||
private var indentWidthCache: [String: Double] = [:]
|
||||
|
||||
|
||||
|
||||
// MARK: Text Container Methods
|
||||
|
||||
override weak var textView: NSTextView? {
|
||||
|
||||
didSet {
|
||||
self.typingAttributesObservation = textView?.observe(\.typingAttributes, options: [.initial, .new]) { [weak self] (textView, change) in
|
||||
guard let typingAttributes = change.newValue else { return }
|
||||
|
||||
// -> The font can differ from the specified text font while typing marked text.
|
||||
guard textView.hasMarkedText() != true else { return }
|
||||
|
||||
self?.indentAttributes = typingAttributes
|
||||
self?.indentWidthCache.removeAll()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override var isSimpleRectangularTextContainer: Bool {
|
||||
|
||||
// -> According to the reference, this property should return `false` when `.isHangingIndentEnabled`
|
||||
|
Loading…
Reference in New Issue
Block a user