Improve message edit with RTE (#1742)

* Improv edit for RTE

* Refine code block style in composer

* Update matrix-wysiwyg-composer-swift to 2.13.0

* Remove workaround

* Update ElementX/Sources/Services/Timeline/TimelineItems/Items/Messages/TextRoomTimelineItemContent.swift

Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>

* Refactor rawFormattedBody -> formattedBodyHTMLString

---------

Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>
This commit is contained in:
Alfonso Grillo
2023-09-21 15:45:43 +02:00
committed by GitHub
parent 4e6fe278db
commit eba3e25373
10 changed files with 30 additions and 11 deletions
+1 -1
View File
@@ -5754,7 +5754,7 @@
repositoryURL = "https://github.com/matrix-org/matrix-wysiwyg-composer-swift"; repositoryURL = "https://github.com/matrix-org/matrix-wysiwyg-composer-swift";
requirement = { requirement = {
kind = exactVersion; kind = exactVersion;
version = 2.12.0; version = 2.13.0;
}; };
}; };
96495DD8554E2F39D3954354 /* XCRemoteSwiftPackageReference "posthog-ios" */ = { 96495DD8554E2F39D3954354 /* XCRemoteSwiftPackageReference "posthog-ios" */ = {
@@ -138,8 +138,8 @@
"kind" : "remoteSourceControl", "kind" : "remoteSourceControl",
"location" : "https://github.com/matrix-org/matrix-wysiwyg-composer-swift", "location" : "https://github.com/matrix-org/matrix-wysiwyg-composer-swift",
"state" : { "state" : {
"revision" : "b6c512d64ef9fd1fba9eb15b247c165377a1c325", "revision" : "b30b7a0f6065907c42c56bd7a87ea4bc9e23a116",
"version" : "2.12.0" "version" : "2.13.0"
} }
}, },
{ {
@@ -149,7 +149,7 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool
} }
private func set(text: String) { private func set(text: String) {
wysiwygViewModel.setMarkdownContent(text) wysiwygViewModel.setHtmlContent(text)
} }
private func createLinkAlert() { private func createLinkAlert() {
@@ -324,13 +324,13 @@ struct HomeScreen_Previews: PreviewProvider, TestablePreview {
HomeScreen(context: loadedViewModel.context) HomeScreen(context: loadedViewModel.context)
} }
.previewDisplayName("Loaded") .previewDisplayName("Loaded")
.snapshot(delay: 2.0) .snapshot(delay: 4.0)
NavigationStack { NavigationStack {
HomeScreen(context: emptyViewModel.context) HomeScreen(context: emptyViewModel.context)
} }
.previewDisplayName("Empty") .previewDisplayName("Empty")
.snapshot(delay: 2.0) .snapshot(delay: 4.0)
} }
static func viewModel(_ state: MockRoomSummaryProviderState) -> HomeScreenViewModel { static func viewModel(_ state: MockRoomSummaryProviderState) -> HomeScreenViewModel {
@@ -141,8 +141,8 @@ private extension HTMLParserStyle {
linkColor: UIColor.link, linkColor: UIColor.link,
codeBlockStyle: BlockStyle(backgroundColor: UIColor(.compound._bgCodeBlock), codeBlockStyle: BlockStyle(backgroundColor: UIColor(.compound._bgCodeBlock),
borderColor: UIColor(.compound.borderInteractiveSecondary), borderColor: UIColor(.compound.borderInteractiveSecondary),
borderWidth: 0.0, borderWidth: 1.0,
cornerRadius: 0.0, cornerRadius: 2.0,
padding: BlockStyle.Padding(horizontal: 10, vertical: 12), padding: BlockStyle.Padding(horizontal: 10, vertical: 12),
type: .background), type: .background),
quoteBlockStyle: BlockStyle(backgroundColor: UIColor(.compound.iconTertiary), quoteBlockStyle: BlockStyle(backgroundColor: UIColor(.compound.iconTertiary),
@@ -578,7 +578,19 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
return return
} }
actionsSubject.send(.composer(action: .setText(text: messageTimelineItem.body))) let text: String
switch messageTimelineItem.contentType {
case .text(let textItem):
if ServiceLocator.shared.settings.richTextEditorEnabled, let formattedBodyHTMLString = textItem.formattedBodyHTMLString {
text = formattedBodyHTMLString
} else {
text = messageTimelineItem.body
}
default:
text = messageTimelineItem.body
}
actionsSubject.send(.composer(action: .setText(text: text)))
actionsSubject.send(.composer(action: .setMode(mode: .edit(originalItemId: messageTimelineItem.id)))) actionsSubject.send(.composer(action: .setMode(mode: .edit(originalItemId: messageTimelineItem.id))))
case .copyPermalink: case .copyPermalink:
do { do {
@@ -19,4 +19,6 @@ import UIKit
struct TextRoomTimelineItemContent: Hashable { struct TextRoomTimelineItemContent: Hashable {
let body: String let body: String
var formattedBody: AttributedString? var formattedBody: AttributedString?
/// The original textual representation of the formatted body directly from the event (usually HTML code)
var formattedBodyHTMLString: String?
} }
@@ -424,7 +424,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
let htmlBody = messageContent.formatted?.format == .html ? messageContent.formatted?.body : nil let htmlBody = messageContent.formatted?.format == .html ? messageContent.formatted?.body : nil
let formattedBody = (htmlBody != nil ? attributedStringBuilder.fromHTML(htmlBody) : attributedStringBuilder.fromPlain(messageContent.body)) let formattedBody = (htmlBody != nil ? attributedStringBuilder.fromHTML(htmlBody) : attributedStringBuilder.fromPlain(messageContent.body))
return .init(body: messageContent.body, formattedBody: formattedBody) return .init(body: messageContent.body, formattedBody: formattedBody, formattedBodyHTMLString: htmlBody)
} }
private func buildAudioTimelineItemContent(_ messageContent: AudioMessageContent) -> AudioRoomTimelineItemContent { private func buildAudioTimelineItemContent(_ messageContent: AudioMessageContent) -> AudioRoomTimelineItemContent {
@@ -18,6 +18,11 @@
import XCTest import XCTest
class LocalizationTests: XCTestCase { class LocalizationTests: XCTestCase {
override func tearDown() {
super.tearDown()
Bundle.overrideLocalizations = nil
}
/// Test ElementL10n considers app language changes /// Test ElementL10n considers app language changes
func testAppLanguage() { func testAppLanguage() {
// set app language to English // set app language to English
+1 -1
View File
@@ -114,4 +114,4 @@ packages:
minorVersion: 2.0.0 minorVersion: 2.0.0
WysiwygComposer: WysiwygComposer:
url: https://github.com/matrix-org/matrix-wysiwyg-composer-swift url: https://github.com/matrix-org/matrix-wysiwyg-composer-swift
exactVersion: 2.12.0 exactVersion: 2.13.0