Change timing to remove hanging indent cache

This commit is contained in:
1024jp 2020-02-08 15:47:58 +09:00
parent 8bbbbabb39
commit 1380b861a1
3 changed files with 23 additions and 5 deletions

View File

@ -7,9 +7,8 @@ Change Log
### Improvements
- Optimize the performance of the invisible character drawing.
- Optimize the performance of the invisible character drawing, the hanging indent calculation, and the line number view drawing.
- Make space to draw the invisible symbol for ZERO WIDTH SPACE (U+200B) when the “other invisible characters” option is enabled.
- [trivial] Optimize the performance of the hanging indent calculation and the line number view drawing.
### Fixes

View File

@ -1211,8 +1211,6 @@ final class EditorTextView: NSTextView, Themable, CurrentLineHighlighting, Multi
assert(Thread.isMainThread)
(self.textContainer as? TextContainer)?.indentAttributes = self.typingAttributes
guard let textStorage = self.textStorage else { return assertionFailure() }
guard textStorage.length > 0 else { return }

View File

@ -31,19 +31,40 @@ final class TextContainer: NSTextContainer {
var isHangingIndentEnabled = false { didSet { self.invalidateLayout() } }
var hangingIndentWidth = 0 { didSet { self.invalidateLayout() } }
var indentAttributes: [NSAttributedString.Key: Any] = [:] { didSet { self.indentWidthCache = [:] } }
// MARK: Private Properties
private var lastLineStartIndex = 0
private var indentWidthCache: [String: CGFloat] = [:]
private var indentAttributes: [NSAttributedString.Key: Any] = [:]
private var typingAttributesObserver: NSKeyValueObservation?
// MARK: -
// MARK: Text Container Methods
deinit {
self.typingAttributesObserver?.invalidate()
}
override weak var textView: NSTextView? {
willSet {
self.typingAttributesObserver?.invalidate()
}
didSet {
self.typingAttributesObserver = textView?.observe(\.typingAttributes, options: [.initial, .new]) { [weak self] (_, change) in
self?.indentAttributes = change.newValue ?? [:]
self?.indentWidthCache.removeAll()
}
}
}
override var isSimpleRectangularTextContainer: Bool {
return !self.isHangingIndentEnabled