Skip to content

Commit

Permalink
Refactor EditorCounter cancellation
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Aug 24, 2024
1 parent 8ca26cd commit f1945e7
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 19 deletions.
5 changes: 3 additions & 2 deletions CotEditor/Sources/EditorCounter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ struct EditorCount: Equatable {
func cancel() {

self.contentTask?.cancel()
self.contentTask = nil
self.selectionTask?.cancel()
self.selectionTask = nil
}


Expand Down Expand Up @@ -215,8 +217,7 @@ struct EditorCount: Equatable {
self.types = self.updatesAll ? .all : self.statusBarRequirements

if self.types.isEmpty {
self.contentTask?.cancel()
self.selectionTask?.cancel()
self.cancel()
return
}

Expand Down
1 change: 1 addition & 0 deletions CotEditor/Sources/EditorTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ final class EditorTextView: NSTextView, CurrentLineHighlighting, MultiCursorEdit
}
self.keyStateObservers.removeAll()
self.instanceHighlightTask?.cancel()
self.instanceHighlightTask = nil
}
}

Expand Down
4 changes: 2 additions & 2 deletions CotEditor/Sources/FindPanelContentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ final class FindPanelContentViewController: NSSplitViewController {

self.splitViewItems = [fieldViewItem, resultViewItem, buttonViewItem]

self.resultObservationTask = Task {
self.resultObservationTask = Task { [weak self] in
for await textFinder in NotificationCenter.default.notifications(named: TextFinder.didFindAllNotification).map({ $0.object as! TextFinder }) {
self.didFinishFindAll(in: textFinder)
self?.didFinishFindAll(in: textFinder)
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions CotEditor/Sources/NSTouchBar+Validation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ extension NSTouchBar {
private init() { }


deinit {
self.applicationObservationTask?.cancel()
}



// MARK: Private Methods

Expand Down
1 change: 0 additions & 1 deletion CotEditor/Sources/ScriptManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ final class ScriptManager: NSObject, NSFilePresenter, @unchecked Sendable {


deinit {
self.menuUpdateTask?.cancel()
if self.presentedItemURL != nil {
NSFileCoordinator.removeFilePresenter(self)
}
Expand Down
1 change: 1 addition & 0 deletions CotEditor/Sources/ShortcutField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ final class ShortcutTextField: NSTextField, NSTextViewDelegate {

if newWindow == nil {
self.windowObservationTask?.cancel()
self.windowObservationTask = nil
}
}

Expand Down
2 changes: 2 additions & 0 deletions CotEditor/Sources/SyntaxParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ extension NSAttributedString.Key {
func cancel() {

self.outlineParseTask?.cancel()
self.outlineParseTask = nil
self.highlightParseTask?.cancel()
self.highlightParseTask = nil
}


Expand Down
9 changes: 0 additions & 9 deletions CotEditor/Sources/TextFinder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,6 @@ struct TextFindAllResult {



// MARK: Lifecycle

deinit {
self.findTask?.cancel()
self.highlightObservationTask?.cancel()
}



// MARK: Public Methods

/// Schedules an incremental search.
Expand Down
3 changes: 3 additions & 0 deletions CotEditor/Sources/WindowContentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ final class WindowContentViewController: NSSplitViewController, NSToolbarItemVal
super.viewDidDisappear()

self.versionBrowserEnterObservationTask?.cancel()
self.versionBrowserEnterObservationTask = nil
self.versionBrowserExitObservationTask?.cancel()
self.versionBrowserExitObservationTask = nil

if let sidebarStateCache {
self.sidebarViewItem?.isCollapsed = sidebarStateCache
self.sidebarStateCache = nil
Expand Down

0 comments on commit f1945e7

Please sign in to comment.