-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
44 changed files
with
1,376 additions
and
647 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import Foundation | ||
|
||
import ChimeKit | ||
import DocumentContent | ||
import Highlighting | ||
import SyntaxService | ||
import TextSystem | ||
import Theme | ||
|
||
@MainActor | ||
public final class DocumentCoordinator<Service: TokenService> { | ||
typealias StorageDispatcher = TextStorageDispatcher<TextViewSystem.Version> | ||
|
||
public let textSystem: TextViewSystem | ||
public let highlighter: Highlighter<Service> | ||
private let syntaxService: SyntaxService | ||
private let layoutBuffer = LayoutInvalidationBuffer() | ||
private let dispatcher: StorageDispatcher | ||
private let sourceViewController = SourceViewController() | ||
public let editorContentController: EditorContentViewController | ||
|
||
public init(statusBarVisible: Bool) { | ||
self.textSystem = TextViewSystem(textView: sourceViewController.textView) | ||
|
||
self.editorContentController = EditorContentViewController( | ||
textSystem: textSystem, | ||
sourceViewController: sourceViewController, | ||
statusBarVisible: statusBarVisible | ||
) | ||
|
||
|
||
self.syntaxService = SyntaxService(textSystem: textSystem, languageDataStore: LanguageDataStore.global) | ||
self.highlighter = Highlighter(textSystem: textSystem, syntaxService: syntaxService) | ||
|
||
self.dispatcher = StorageDispatcher(storage: textSystem.storage, monitors: [ | ||
textSystem.storageMonitor, | ||
syntaxService.storageMonitor, | ||
highlighter.storageMonitor | ||
]) | ||
|
||
let textView = sourceViewController.textView | ||
|
||
sourceViewController.shouldChangeTextHandler = { [dispatcher] in | ||
dispatcher.textView(textView, shouldChangeTextIn: $0, replacementString: $1) | ||
} | ||
|
||
sourceViewController.selectionChangedHandler = { [editorContentController] in | ||
editorContentController.selectedRanges = $0 | ||
} | ||
|
||
sourceViewController.willLayoutHandler = { [layoutBuffer] in layoutBuffer.willLayout() } | ||
sourceViewController.didLayoutHandler = { [layoutBuffer] in layoutBuffer.didLayout() } | ||
|
||
syntaxService.invalidationHandler = { [highlighter] in | ||
highlighter.invalidate(textTarget: $0) | ||
} | ||
|
||
layoutBuffer.handler = { [highlighter] in | ||
highlighter.visibleContentDidChange() | ||
} | ||
|
||
editorContentController.contentVisibleRectChanged = { [layoutBuffer] _ in | ||
layoutBuffer.contentVisibleRectChanged() | ||
} | ||
|
||
LanguageDataStore.global.configurationLoaded = { [weak syntaxService] in | ||
syntaxService?.languageConfigurationChanged(for: $0) | ||
} | ||
} | ||
|
||
public func documentContextChanged(from oldContext: DocumentContext, to newContext: DocumentContext) { | ||
syntaxService.documentContextChanged(from: oldContext, to: newContext) | ||
highlighter.documentContextChanged(from: oldContext, to: newContext) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.