Skip to content

Commit 9e8b4f8

Browse files
committed
Platform protect the text change callbacks
`textDidChange` on macOS `textViewDidChange` on iOS
1 parent 15045a9 commit 9e8b4f8

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

Sources/CodeEditor/UXCodeTextViewRepresentable.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,20 @@ struct UXCodeTextViewRepresentable : UXViewRepresentable {
8686
self.parent = parent
8787
}
8888

89-
public func textDidChange(_ notification: Notification) {
90-
guard let textView = notification.object as? UXTextView else {
91-
assertionFailure("unexpected notification object")
92-
return
89+
#if os(macOS)
90+
public func textDidChange(_ notification: Notification) {
91+
guard let textView = notification.object as? UXTextView else {
92+
assertionFailure("unexpected notification object")
93+
return
94+
}
95+
parent.source.wrappedValue = textView.string
96+
}
97+
#elseif os(iOS)
98+
public func textViewDidChange(_ textView: UITextView) {
99+
parnt.source.wrappedValue = textView.string
93100
}
94-
parent.source.wrappedValue = textView.string
95-
}
96-
97-
#if os(iOS)
98-
public func textViewDidChange(_ textView: UITextView) {
99-
parent.source.wrappedValue = textView.string
100-
}
101+
#else
102+
#error("Unsupported OS")
101103
#endif
102104

103105
var allowCopy: Bool {

0 commit comments

Comments
 (0)