Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

[iOS] Fix for dictation not working properly #875

Merged
merged 4 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ protocol WysiwygTextViewDelegate: AnyObject {
public protocol MentionDisplayHelper { }

public class WysiwygTextView: UITextView {
private(set) var isDictationRunning = false
Velin92 marked this conversation as resolved.
Show resolved Hide resolved

/// Internal delegate for the text view.
weak var wysiwygDelegate: WysiwygTextViewDelegate?

Expand All @@ -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,
Velin92 marked this conversation as resolved.
Show resolved Hide resolved
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`.
Expand Down
Loading