mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-20 15:47:57 +03:00
Refactor timing to cancel document analysis
This commit is contained in:
parent
66377dffe4
commit
6188aad4ae
@ -132,6 +132,7 @@ final class Document: NSDocument, AdditionalDocumentPreparing, EncodingChanging
|
||||
|
||||
deinit {
|
||||
self.syntaxParser.cancel()
|
||||
self.analyzer.cancel()
|
||||
self.urlDetector.cancel()
|
||||
}
|
||||
|
||||
|
@ -57,14 +57,15 @@ final class DocumentAnalyzer {
|
||||
}
|
||||
|
||||
|
||||
deinit {
|
||||
self.task?.cancel()
|
||||
}
|
||||
|
||||
|
||||
|
||||
// MARK: Public Methods
|
||||
|
||||
/// Cancels all remaining tasks.
|
||||
func cancel() {
|
||||
|
||||
self.task?.cancel()
|
||||
}
|
||||
|
||||
/// Updates editor info (only if really needed).
|
||||
///
|
||||
/// - Parameter onlySelection: `true` to invalidate only the selection.
|
||||
@ -91,7 +92,7 @@ final class DocumentAnalyzer {
|
||||
let delay: Duration = .milliseconds(self.needsCountWholeText ? 10 : 200)
|
||||
|
||||
self.task?.cancel()
|
||||
self.task = Task { [weak self, weak textView] in
|
||||
self.task = Task { [weak textView] in
|
||||
try await Task.sleep(for: delay, tolerance: .milliseconds(10)) // debounce
|
||||
|
||||
guard let textView else { return }
|
||||
@ -104,7 +105,7 @@ final class DocumentAnalyzer {
|
||||
try Task.checkCancellation()
|
||||
|
||||
// selectedRanges can be empty when the document is already closed
|
||||
guard !selectedRanges.isEmpty, let self else { return }
|
||||
guard !selectedRanges.isEmpty else { return }
|
||||
|
||||
let countsWholeText = self.needsCountWholeText
|
||||
let counter = EditorCounter(string: string, selectedRanges: selectedRanges, requiredInfo: self.requiredInfoTypes, countsWholeText: countsWholeText)
|
||||
|
Loading…
Reference in New Issue
Block a user