fix: choose the insertion route on the main actor (crash on background thread)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,16 +14,16 @@ public enum InsertionRoute: Equatable, Sendable {
|
||||
public struct RoutingInserter: TextInserting {
|
||||
private let system: TextInserting
|
||||
private let editor: TextInserting
|
||||
private let route: () -> InsertionRoute
|
||||
private let route: () async -> InsertionRoute
|
||||
|
||||
public init(system: TextInserting, editor: TextInserting, route: @escaping () -> InsertionRoute) {
|
||||
public init(system: TextInserting, editor: TextInserting, route: @escaping () async -> InsertionRoute) {
|
||||
self.system = system
|
||||
self.editor = editor
|
||||
self.route = route
|
||||
}
|
||||
|
||||
public func insert(_ text: String) async throws {
|
||||
switch route() {
|
||||
switch await route() {
|
||||
case .system: try await system.insert(text)
|
||||
case .editor: try await editor.insert(text)
|
||||
case .none: break
|
||||
|
||||
Reference in New Issue
Block a user