diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index 0c150b9b3..02285668c 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -6791,7 +6791,7 @@ repositoryURL = "https://github.com/matrix-org/matrix-wysiwyg-composer-swift"; requirement = { kind = exactVersion; - version = 2.28.0; + version = 2.29.0; }; }; 96495DD8554E2F39D3954354 /* XCRemoteSwiftPackageReference "posthog-ios" */ = { diff --git a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 77e24057c..af774a8fd 100644 --- a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -138,8 +138,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/matrix-org/matrix-wysiwyg-composer-swift", "state" : { - "revision" : "7b341602195b6527eb34c61cc6bd479f7631409d", - "version" : "2.28.0" + "revision" : "f788fe2482c0b89019f679a1f43dccf9c25a0782", + "version" : "2.29.0" } }, { diff --git a/ElementX/Sources/Screens/ComposerToolbar/ComposerToolbarViewModel.swift b/ElementX/Sources/Screens/ComposerToolbar/ComposerToolbarViewModel.swift index 8244d583c..f68f92dda 100644 --- a/ElementX/Sources/Screens/ComposerToolbar/ComposerToolbarViewModel.swift +++ b/ElementX/Sources/Screens/ComposerToolbar/ComposerToolbarViewModel.swift @@ -26,7 +26,6 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool private let wysiwygViewModel: WysiwygComposerViewModel private let completionSuggestionService: CompletionSuggestionServiceProtocol private let appSettings: AppSettings - private let mentionDisplayHelper: MentionDisplayHelper private var hasAppeard = false private let actionsSubject: PassthroughSubject = .init() @@ -47,7 +46,6 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool self.wysiwygViewModel = wysiwygViewModel self.completionSuggestionService = completionSuggestionService self.appSettings = appSettings - self.mentionDisplayHelper = mentionDisplayHelper super.init(initialViewState: ComposerToolbarViewState(audioPlayerState: .init(id: .recorderPreview, duration: 0), audioRecorderState: .init(), @@ -102,7 +100,8 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool } .weakAssign(to: \.state.suggestions, on: self) .store(in: &cancellables) - + + setupMentionsHandling(mentionDisplayHelper: mentionDisplayHelper) focusComposerIfHardwareKeyboardConnected() } @@ -111,7 +110,6 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool override func process(viewAction: ComposerToolbarViewAction) { switch viewAction { case .composerAppeared: - setupMentionsHandlingIfNecessary() if !hasAppeard { hasAppeard = true wysiwygViewModel.setup() @@ -205,12 +203,8 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool } } - private func setupMentionsHandlingIfNecessary() { - guard let textView = wysiwygViewModel.textView, - textView.mentionDisplayHelper == nil else { - return - } - textView.mentionDisplayHelper = mentionDisplayHelper + private func setupMentionsHandling(mentionDisplayHelper: MentionDisplayHelper) { + wysiwygViewModel.mentionDisplayHelper = mentionDisplayHelper let attributedStringBuilder = AttributedStringBuilder(cacheKey: "Composer", permalinkBaseURL: appSettings.permalinkBaseURL, mentionBuilder: MentionBuilder()) @@ -261,7 +255,7 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool } private func set(text: String) { - wysiwygViewModel.textView?.flushPills() + wysiwygViewModel.textView.flushPills() if appSettings.richTextEditorEnabled { wysiwygViewModel.setHtmlContent(text) diff --git a/UnitTests/Sources/ComposerToolbarViewModelTests.swift b/UnitTests/Sources/ComposerToolbarViewModelTests.swift index 5f40024e7..6bc2b1938 100644 --- a/UnitTests/Sources/ComposerToolbarViewModelTests.swift +++ b/UnitTests/Sources/ComposerToolbarViewModelTests.swift @@ -33,7 +33,6 @@ class ComposerToolbarViewModelTests: XCTestCase { appSettings.richTextEditorEnabled = true ServiceLocator.shared.register(appSettings: appSettings) wysiwygViewModel = WysiwygComposerViewModel() - wysiwygViewModel.textView = WysiwygTextView() completionSuggestionServiceMock = CompletionSuggestionServiceMock(configuration: .init()) viewModel = ComposerToolbarViewModel(wysiwygViewModel: wysiwygViewModel, completionSuggestionService: completionSuggestionServiceMock, @@ -150,7 +149,7 @@ class ComposerToolbarViewModelTests: XCTestCase { let suggestion = SuggestionItem.user(item: .init(id: userID, displayName: "Test", avatarURL: nil)) viewModel.context.send(viewAction: .selectedSuggestion(suggestion)) - let attachment = wysiwygViewModel.textView?.attributedText.attribute(.attachment, at: 0, effectiveRange: nil) as? PillTextAttachment + let attachment = wysiwygViewModel.textView.attributedText.attribute(.attachment, at: 0, effectiveRange: nil) as? PillTextAttachment XCTAssertEqual(attachment?.pillData?.type, .user(userID: userID)) } @@ -160,7 +159,7 @@ class ComposerToolbarViewModelTests: XCTestCase { let suggestion = SuggestionItem.allUsers(item: .allUsersMention(roomAvatar: nil)) viewModel.context.send(viewAction: .selectedSuggestion(suggestion)) - let attachment = wysiwygViewModel.textView?.attributedText.attribute(.attachment, at: 0, effectiveRange: nil) as? PillTextAttachment + let attachment = wysiwygViewModel.textView.attributedText.attribute(.attachment, at: 0, effectiveRange: nil) as? PillTextAttachment XCTAssertEqual(attachment?.pillData?.type, .allUsers) } diff --git a/project.yml b/project.yml index 3719e76df..1bd11baf7 100644 --- a/project.yml +++ b/project.yml @@ -66,7 +66,7 @@ packages: # path: ../swift-ogg WysiwygComposer: url: https://github.com/matrix-org/matrix-wysiwyg-composer-swift - exactVersion: 2.28.0 + exactVersion: 2.29.0 # path: ../matrix-wysiwyg/platforms/ios/lib/WysiwygComposer # External dependencies