mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-10-26 10:58:05 +03:00
Fix leak in EditorTextView
This commit is contained in:
parent
0e0d3f41fb
commit
e1a026cdcc
@ -14,6 +14,7 @@
|
||||
|
||||
### Fixes
|
||||
|
||||
- [beta] Fix a memory leak.
|
||||
- [beta] Fix an issue on macOS 14 that multiple cursors in editors were not drawn when the editor becomes active again.
|
||||
- [beta] Add missing localization.
|
||||
|
||||
|
@ -134,7 +134,7 @@ class EditorTextView: NSTextView, Themable, CurrentLineHighlighting, MultiCursor
|
||||
private var defaultsObservers: Set<AnyCancellable> = []
|
||||
private var fontObservers: Set<AnyCancellable> = []
|
||||
private var windowOpacityObserver: AnyCancellable?
|
||||
private var keyStateObserver: AnyCancellable?
|
||||
private var keyStateObservers: [any NSObjectProtocol] = []
|
||||
|
||||
|
||||
|
||||
@ -347,14 +347,21 @@ class EditorTextView: NSTextView, Themable, CurrentLineHighlighting, MultiCursor
|
||||
self?.lineHighlightColor = self?.theme?.lineHighlightColor(forOpaqueBackground: $0)
|
||||
}
|
||||
|
||||
|
||||
// observe key window state for insertion points drawing
|
||||
if #available(macOS 14, *), let window {
|
||||
self.keyStateObserver = Publishers.Merge(
|
||||
NotificationCenter.default.publisher(for: NSWindow.didBecomeKeyNotification, object: window),
|
||||
NotificationCenter.default.publisher(for: NSWindow.didResignKeyNotification, object: window)
|
||||
)
|
||||
.sink { [unowned self] _ in self.invalidateInsertionIndicatorDisplayMode() }
|
||||
self.keyStateObservers = [
|
||||
NotificationCenter.default.addObserver(forName: NSWindow.didBecomeKeyNotification, object: window, queue: .main) { [weak self] _ in
|
||||
self?.invalidateInsertionIndicatorDisplayMode()
|
||||
},
|
||||
NotificationCenter.default.addObserver(forName: NSWindow.didResignKeyNotification, object: window, queue: .main) { [weak self] _ in
|
||||
self?.invalidateInsertionIndicatorDisplayMode()
|
||||
},
|
||||
]
|
||||
} else {
|
||||
for observer in self.keyStateObservers {
|
||||
NotificationCenter.default.removeObserver(observer)
|
||||
}
|
||||
self.keyStateObservers.removeAll()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user