diff --git a/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygComposerView.swift b/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygComposerView.swift index 65c0999..1af9090 100644 --- a/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygComposerView.swift +++ b/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygComposerView.swift @@ -88,7 +88,7 @@ public struct WysiwygComposerView: View { @ViewBuilder private var placeholderView: some View { - if viewModel.isContentEmpty { + if viewModel.isContentEmpty, !viewModel.textView.isDictationRunning { Text(placeholder) .font(Font(UIFont.preferredFont(forTextStyle: .body))) .foregroundColor(placeholderColor) diff --git a/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygComposerViewModel.swift b/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygComposerViewModel.swift index 3a55f2d..de9c667 100644 --- a/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygComposerViewModel.swift +++ b/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygComposerViewModel.swift @@ -556,7 +556,8 @@ private extension WysiwygComposerViewModel { /// Reconciliate the content of the model with the content of the text view. func reconciliateIfNeeded() { do { - guard let replacement = try StringDiffer.replacement(from: attributedContent.text.htmlChars, + guard !textView.isDictationRunning, + let replacement = try StringDiffer.replacement(from: attributedContent.text.htmlChars, to: textView.attributedText.htmlChars) else { return } diff --git a/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygTextView.swift b/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygTextView.swift index c6a532a..3120228 100644 --- a/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygTextView.swift +++ b/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygTextView.swift @@ -44,6 +44,8 @@ protocol WysiwygTextViewDelegate: AnyObject { public protocol MentionDisplayHelper { } public class WysiwygTextView: UITextView { + private(set) var isDictationRunning = false + /// Internal delegate for the text view. weak var wysiwygDelegate: WysiwygTextViewDelegate? @@ -53,12 +55,42 @@ public class WysiwygTextView: UITextView { override public init(frame: CGRect, textContainer: NSTextContainer?) { super.init(frame: frame, textContainer: textContainer) - contentMode = .redraw + commonInit() } required init?(coder: NSCoder) { super.init(coder: coder) + commonInit() + } + + private func commonInit() { contentMode = .redraw + NotificationCenter.default.addObserver(self, + selector: #selector(textInputCurrentInputModeDidChange), + name: UITextInputMode.currentInputModeDidChangeNotification, + object: nil) + } + + @objc private func textInputCurrentInputModeDidChange(notification: Notification) { + // We don't care about the input mode if this is not the first responder + guard isFirstResponder else { + return + } + + guard let inputMode = textInputMode?.primaryLanguage, + inputMode == "dictation" else { + isDictationRunning = false + return + } + isDictationRunning = true + } + + override public func dictationRecordingDidEnd() { + isDictationRunning = false + } + + override public func dictationRecognitionFailed() { + isDictationRunning = false } /// Register a pill view that has been added through `NSTextAttachmentViewProvider`. diff --git a/WysiwygComposerFFI.xcframework/ios-arm64/WysiwygComposerFFI.framework/WysiwygComposerFFI b/WysiwygComposerFFI.xcframework/ios-arm64/WysiwygComposerFFI.framework/WysiwygComposerFFI index 67bb14c..420af26 100644 Binary files a/WysiwygComposerFFI.xcframework/ios-arm64/WysiwygComposerFFI.framework/WysiwygComposerFFI and b/WysiwygComposerFFI.xcframework/ios-arm64/WysiwygComposerFFI.framework/WysiwygComposerFFI differ diff --git a/WysiwygComposerFFI.xcframework/ios-arm64_x86_64-simulator/WysiwygComposerFFI.framework/WysiwygComposerFFI b/WysiwygComposerFFI.xcframework/ios-arm64_x86_64-simulator/WysiwygComposerFFI.framework/WysiwygComposerFFI index 9ff9c7a..a541d5b 100644 Binary files a/WysiwygComposerFFI.xcframework/ios-arm64_x86_64-simulator/WysiwygComposerFFI.framework/WysiwygComposerFFI and b/WysiwygComposerFFI.xcframework/ios-arm64_x86_64-simulator/WysiwygComposerFFI.framework/WysiwygComposerFFI differ