diff --git a/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygComposerViewModel.swift b/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygComposerViewModel.swift index b1ba09a..3a55f2d 100644 --- a/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygComposerViewModel.swift +++ b/Sources/WysiwygComposer/Components/WysiwygComposerView/WysiwygComposerViewModel.swift @@ -64,6 +64,10 @@ public class WysiwygComposerViewModel: WysiwygComposerViewModelProtocol, Observa } } + /// Whether the composer should take any keyboard input. + /// When set to `false`, `replaceText(range:replacementText:)` returns `false` as well. + public var shouldReplaceText = true + /// Published value for the composer plain text mode. @Published public var plainTextMode = false { didSet { @@ -289,6 +293,10 @@ public extension WysiwygComposerViewModel { } func replaceText(range: NSRange, replacementText: String) -> Bool { + guard shouldReplaceText else { + return false + } + guard !plainTextMode else { return true } diff --git a/Tests/WysiwygComposerTests/Components/WysiwygComposerView/WysiwygComposerViewModelTests.swift b/Tests/WysiwygComposerTests/Components/WysiwygComposerView/WysiwygComposerViewModelTests.swift index e61b54b..4aee4e9 100644 --- a/Tests/WysiwygComposerTests/Components/WysiwygComposerView/WysiwygComposerViewModelTests.swift +++ b/Tests/WysiwygComposerTests/Components/WysiwygComposerView/WysiwygComposerViewModelTests.swift @@ -19,16 +19,13 @@ import Combine import XCTest final class WysiwygComposerViewModelTests: XCTestCase { - let viewModel = WysiwygComposerViewModel() + var viewModel: WysiwygComposerViewModel! override func setUpWithError() throws { + viewModel = WysiwygComposerViewModel() viewModel.clearContent() } - override func tearDownWithError() throws { - viewModel.plainTextMode = false - } - func testIsContentEmpty() throws { XCTAssertTrue(viewModel.isContentEmpty) @@ -51,6 +48,13 @@ final class WysiwygComposerViewModelTests: XCTestCase { XCTAssertTrue(shouldChange) } + func testSimpleTextInputIsNotAccepted() throws { + viewModel.shouldReplaceText = false + let shouldChange = viewModel.replaceText(range: .zero, + replacementText: "A") + XCTAssertFalse(shouldChange) + } + func testNewlineIsNotAccepted() throws { let shouldChange = viewModel.replaceText(range: .zero, replacementText: "\n") diff --git a/WysiwygComposerFFI.xcframework/ios-arm64/WysiwygComposerFFI.framework/WysiwygComposerFFI b/WysiwygComposerFFI.xcframework/ios-arm64/WysiwygComposerFFI.framework/WysiwygComposerFFI index 618dc11..9224a54 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 bce3b06..9ea27f2 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