Skip to content

Commit

Permalink
Stop observing textStorage in SyntaxParser (#1648)
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Jun 26, 2024
1 parent 3b6a179 commit dfbd33d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
### Fixes

- Fix the view layout in the Quick Action bar.
- Fix a potential memory leak.



Expand Down
10 changes: 6 additions & 4 deletions CotEditor/Sources/DocumentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 0 additions & 10 deletions CotEditor/Sources/SyntaxParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
// limitations under the License.
//

import Combine
import Foundation
import AppKit.NSTextStorage
import OSLog
Expand Down Expand Up @@ -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
Expand All @@ -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() }
}


Expand Down

0 comments on commit dfbd33d

Please sign in to comment.