mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 11:25:57 +03:00
Change timing to remove hanging indent cache
This commit is contained in:
parent
8bbbbabb39
commit
1380b861a1
@ -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
|
||||
|
@ -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 }
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user