mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-08-16 14:50:30 +03:00
Stop observing textStorage in SyntaxParser (#1648)
This commit is contained in:
parent
3b6a179768
commit
dfbd33d760
@ -11,6 +11,7 @@
|
||||
### Fixes
|
||||
|
||||
- Fix the view layout in the Quick Action bar.
|
||||
- Fix a potential memory leak.
|
||||
|
||||
|
||||
|
||||
|
@ -383,10 +383,12 @@ final class DocumentViewController: NSSplitViewController, ThemeChanging, NSTool
|
||||
|
||||
let textStorage = notification.object as! NSTextStorage
|
||||
|
||||
guard
|
||||
textStorage.editedMask.contains(.editedCharacters),
|
||||
self.focusedTextView?.hasMarkedText() != true
|
||||
else { return }
|
||||
guard textStorage.editedMask.contains(.editedCharacters) else { return }
|
||||
|
||||
// give up the current parsing
|
||||
self.document.syntaxParser.cancel()
|
||||
|
||||
guard self.focusedTextView?.hasMarkedText() != true else { return }
|
||||
|
||||
self.document.analyzer.invalidateContent()
|
||||
self.outlineParseDebouncer.schedule()
|
||||
|
@ -24,7 +24,6 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import Foundation
|
||||
import AppKit.NSTextStorage
|
||||
import OSLog
|
||||
@ -54,11 +53,8 @@ final class SyntaxParser: @unchecked Sendable {
|
||||
|
||||
private var outlineParseTask: Task<Void, any Error>?
|
||||
private var highlightParseTask: Task<Void, any Error>?
|
||||
private var textEditingObservationTask: Task<Void, any Error>?
|
||||
private var isHighlighting = false
|
||||
|
||||
private var textEditingObserver: AnyCancellable?
|
||||
|
||||
|
||||
|
||||
// MARK: Lifecycle
|
||||
@ -68,12 +64,6 @@ final class SyntaxParser: @unchecked Sendable {
|
||||
self.textStorage = textStorage
|
||||
self.syntax = syntax
|
||||
self.name = name
|
||||
|
||||
// give up if the string is changed while parsing
|
||||
self.textEditingObserver = NotificationCenter.default.publisher(for: NSTextStorage.willProcessEditingNotification, object: textStorage)
|
||||
.map { $0.object as! NSTextStorage }
|
||||
.filter { $0.editedMask.contains(.editedCharacters) }
|
||||
.sink { [weak self] _ in self?.highlightParseTask?.cancel() }
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user