diff --git a/Podfile b/Podfile index 35ba935b2..420a69dd5 100644 --- a/Podfile +++ b/Podfile @@ -53,8 +53,6 @@ end def import_MatrixKit_pods pod 'libPhoneNumber-iOS', '~> 0.9.13' - pod 'DTCoreText', '~> 1.6.25' - #pod 'DTCoreText/Extension', '~> 1.6.25' pod 'Down', '~> 0.11.0' end diff --git a/Riot.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Riot.xcworkspace/xcshareddata/swiftpm/Package.resolved index 34484b0a7..1e8132370 100644 --- a/Riot.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Riot.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -9,6 +9,24 @@ "version" : "4.7.0" } }, + { + "identity" : "dtcoretext", + "kind" : "remoteSourceControl", + "location" : "https://github.com/Cocoanetics/DTCoreText", + "state" : { + "revision" : "9d2d4d2296e5d2d852a7d3c592b817d913a5d020", + "version" : "1.6.27" + } + }, + { + "identity" : "dtfoundation", + "kind" : "remoteSourceControl", + "location" : "https://github.com/Cocoanetics/DTFoundation.git", + "state" : { + "revision" : "76062513434421cb6c8a1ae1d4f8368a7ebc2da3", + "version" : "1.7.18" + } + }, { "identity" : "maplibre-gl-native-distribution", "kind" : "remoteSourceControl", @@ -23,8 +41,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/matrix-org/matrix-wysiwyg-composer-swift", "state" : { - "revision" : "6927cb878376136c4a03d919b689af8dfbdad080", - "version" : "0.19.0" + "revision" : "3f72aeab7d7e04b52ff3f735ab79a75993f97ef2", + "version" : "0.22.0" } }, { diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index bff7b6ac3..03ab2ca29 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -2579,8 +2579,8 @@ To enable access, tap Settings> Location and select Always"; "wysiwyg_composer_format_action_ordered_list" = "Toggle numbered list"; "wysiwyg_composer_format_action_code_block" = "Toggle code block"; "wysiwyg_composer_format_action_quote" = "Toggle quote"; - - +"wysiwyg_composer_format_action_indent" = "Increase indentation"; +"wysiwyg_composer_format_action_un_indent" = "Decrease indentation"; // Links "wysiwyg_composer_link_action_text" = "Text"; diff --git a/Riot/Generated/Strings.swift b/Riot/Generated/Strings.swift index 0327090c1..550732246 100644 --- a/Riot/Generated/Strings.swift +++ b/Riot/Generated/Strings.swift @@ -9403,6 +9403,10 @@ public class VectorL10n: NSObject { public static var wysiwygComposerFormatActionCodeBlock: String { return VectorL10n.tr("Vector", "wysiwyg_composer_format_action_code_block") } + /// Increase indentation + public static var wysiwygComposerFormatActionIndent: String { + return VectorL10n.tr("Vector", "wysiwyg_composer_format_action_indent") + } /// Apply inline code format public static var wysiwygComposerFormatActionInlineCode: String { return VectorL10n.tr("Vector", "wysiwyg_composer_format_action_inline_code") @@ -9427,6 +9431,10 @@ public class VectorL10n: NSObject { public static var wysiwygComposerFormatActionStrikethrough: String { return VectorL10n.tr("Vector", "wysiwyg_composer_format_action_strikethrough") } + /// Decrease indentation + public static var wysiwygComposerFormatActionUnIndent: String { + return VectorL10n.tr("Vector", "wysiwyg_composer_format_action_un_indent") + } /// Apply strikethrough format public static var wysiwygComposerFormatActionUnderline: String { return VectorL10n.tr("Vector", "wysiwyg_composer_format_action_underline") diff --git a/Riot/Modules/MatrixKit/Utils/EventFormatter/HTMLFormatter.swift b/Riot/Modules/MatrixKit/Utils/EventFormatter/HTMLFormatter.swift index 6c7e43a90..819eb632f 100644 --- a/Riot/Modules/MatrixKit/Utils/EventFormatter/HTMLFormatter.swift +++ b/Riot/Modules/MatrixKit/Utils/EventFormatter/HTMLFormatter.swift @@ -47,9 +47,7 @@ class HTMLFormatter: NSObject { var options: [AnyHashable: Any] = [ DTUseiOS6Attributes: true, - DTDefaultFontFamily: font.familyName, - DTDefaultFontName: font.fontName, - DTDefaultFontSize: font.pointSize, + DTDefaultFontDescriptor: font.fontDescriptor, DTDefaultLinkDecoration: false, DTDefaultLinkColor: ThemeService.shared().theme.colors.links, DTWillFlushBlockCallBack: sanitizeCallback diff --git a/Riot/Modules/Room/Views/WYSIWYGInputToolbar/WysiwygInputToolbarView.swift b/Riot/Modules/Room/Views/WYSIWYGInputToolbar/WysiwygInputToolbarView.swift index 013602843..d611fb06a 100644 --- a/Riot/Modules/Room/Views/WYSIWYGInputToolbar/WysiwygInputToolbarView.swift +++ b/Riot/Modules/Room/Views/WYSIWYGInputToolbar/WysiwygInputToolbarView.swift @@ -17,6 +17,7 @@ import Foundation import Reusable import WysiwygComposer +import HTMLParser import SwiftUI import Combine import UIKit @@ -43,9 +44,14 @@ class WysiwygInputToolbarView: MXKRoomInputToolbarView, NibLoadable, HtmlRoomInp private var voiceMessageBottomConstraint: NSLayoutConstraint? private var hostingViewController: VectorHostingController! private var wysiwygViewModel = WysiwygComposerViewModel( - textColor: ThemeService.shared().theme.colors.primaryContent, - linkColor: ThemeService.shared().theme.colors.links, - codeBackgroundColor: ThemeService.shared().theme.selectedBackgroundColor + parserStyle: HTMLParserStyle(textColor: ThemeService.shared().theme.colors.primaryContent, + linkColor: ThemeService.shared().theme.colors.links, + codeBackgroundColor: ThemeService.shared().theme.selectedBackgroundColor, + codeBorderColor: ThemeService.shared().theme.textQuinaryColor, + quoteBackgroundColor: ThemeService.shared().theme.selectedBackgroundColor, + quoteBorderColor: ThemeService.shared().theme.textQuinaryColor, + borderWidth: 1.0, + cornerRadius: 4.0) ) private var viewModel: ComposerViewModelProtocol! @@ -298,9 +304,14 @@ class WysiwygInputToolbarView: MXKRoomInputToolbarView, NibLoadable, HtmlRoomInp private func update(theme: Theme) { hostingViewController.view.backgroundColor = theme.colors.background - wysiwygViewModel.textColor = theme.colors.primaryContent - wysiwygViewModel.linkColor = theme.colors.links - wysiwygViewModel.codeBackgroundColor = theme.selectedBackgroundColor + wysiwygViewModel.parserStyle = HTMLParserStyle(textColor: ThemeService.shared().theme.colors.primaryContent, + linkColor: ThemeService.shared().theme.colors.links, + codeBackgroundColor: ThemeService.shared().theme.selectedBackgroundColor, + codeBorderColor: ThemeService.shared().theme.textQuinaryColor, + quoteBackgroundColor: ThemeService.shared().theme.selectedBackgroundColor, + quoteBorderColor: ThemeService.shared().theme.textQuinaryColor, + borderWidth: 1.0, + cornerRadius: 4.0) } private func updateTextViewHeight() { diff --git a/Riot/Utils/EventFormatter+DTCoreTextFix.h b/Riot/Utils/EventFormatter+DTCoreTextFix.h deleted file mode 100644 index 90be432c4..000000000 --- a/Riot/Utils/EventFormatter+DTCoreTextFix.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -Copyright 2020 New Vector Ltd - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -@import Foundation; - -#import "EventFormatter.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface EventFormatter(DTCoreTextFix) - -// Fix DTCoreText iOS 13 issue (https://github.com/Cocoanetics/DTCoreText/issues/1168) -+ (void)fixDTCoreTextFont; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Riot/Utils/EventFormatter+DTCoreTextFix.m b/Riot/Utils/EventFormatter+DTCoreTextFix.m deleted file mode 100644 index 110d036fc..000000000 --- a/Riot/Utils/EventFormatter+DTCoreTextFix.m +++ /dev/null @@ -1,80 +0,0 @@ -/* -Copyright 2020 New Vector Ltd - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#import "EventFormatter+DTCoreTextFix.h" - -@import UIKit; -@import CoreText; -@import ObjectiveC; - -#pragma mark - UIFont DTCoreText fix - -@interface UIFont (vc_DTCoreTextFix) - -+ (UIFont *)vc_fixedFontWithCTFont:(CTFontRef)ctFont; - -@end - -@implementation UIFont (vc_DTCoreTextFix) - -+ (UIFont *)vc_fixedFontWithCTFont:(CTFontRef)ctFont { - NSString *fontName = (__bridge_transfer NSString *)CTFontCopyName(ctFont, kCTFontPostScriptNameKey); - - CGFloat fontSize = CTFontGetSize(ctFont); - UIFont *font = [UIFont fontWithName:fontName size:fontSize]; - - // On iOS 13+ "TimesNewRomanPSMT" will be used instead of "SFUI" - // In case of "Times New Roman" fallback, use system font and reuse UIFontDescriptorSymbolicTraits. - if ([font.familyName.lowercaseString containsString:@"times"]) - { - UIFontDescriptorSymbolicTraits symbolicTraits = (UIFontDescriptorSymbolicTraits)CTFontGetSymbolicTraits(ctFont); - - UIFontDescriptor *systemFontDescriptor = [UIFont systemFontOfSize:fontSize].fontDescriptor; - - UIFontDescriptor *finalFontDescriptor = [systemFontDescriptor fontDescriptorWithSymbolicTraits:symbolicTraits]; - font = [UIFont fontWithDescriptor:finalFontDescriptor size:fontSize]; - } - - return font; -} - -@end - -#pragma mark - Implementation - -@implementation EventFormatter(DTCoreTextFix) - -// DTCoreText iOS 13 fix. See issue and comment here: https://github.com/Cocoanetics/DTCoreText/issues/1168#issuecomment-583541514 -+ (void)fixDTCoreTextFont -{ - static dispatch_once_t onceToken; - - dispatch_once(&onceToken, ^{ - Class originalClass = object_getClass([UIFont class]); -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wundeclared-selector" - SEL originalSelector = @selector(fontWithCTFont:); // DTCoreText method we're overriding - SEL ourSelector = @selector(vc_fixedFontWithCTFont:); // Use custom implementation -#pragma clang diagnostic pop - - Method originalMethod = class_getClassMethod(originalClass, originalSelector); - Method swizzledMethod = class_getClassMethod(originalClass, ourSelector); - - method_exchangeImplementations(originalMethod, swizzledMethod); - }); -} - -@end diff --git a/Riot/Utils/EventFormatter.m b/Riot/Utils/EventFormatter.m index db526607a..5ea1d5f2d 100644 --- a/Riot/Utils/EventFormatter.m +++ b/Riot/Utils/EventFormatter.m @@ -25,7 +25,6 @@ #import "MXDecryptionResult.h" #import "DecryptionFailureTracker.h" -#import "EventFormatter+DTCoreTextFix.h" #import #pragma mark - Constants definitions @@ -50,11 +49,6 @@ static NSString *const kEventFormatterTimeFormat = @"HH:mm"; @implementation EventFormatter -+ (void)load -{ - [self fixDTCoreTextFont]; -} - - (void)initDateTimeFormatters { [super initDateTimeFormatters]; diff --git a/Riot/target.yml b/Riot/target.yml index 5813e2617..b0fc131fb 100644 --- a/Riot/target.yml +++ b/Riot/target.yml @@ -44,6 +44,7 @@ targets: - package: SwiftOGG - package: WysiwygComposer - package: DeviceKit + - package: DTCoreText configFiles: Debug: Debug.xcconfig diff --git a/RiotNSE/target.yml b/RiotNSE/target.yml index ae27022c3..21c5f2864 100644 --- a/RiotNSE/target.yml +++ b/RiotNSE/target.yml @@ -33,6 +33,7 @@ targets: dependencies: - package: DeviceKit + - package: DTCoreText configFiles: Debug: Debug.xcconfig diff --git a/RiotShareExtension/target.yml b/RiotShareExtension/target.yml index 2d398950a..8601ce85f 100644 --- a/RiotShareExtension/target.yml +++ b/RiotShareExtension/target.yml @@ -33,6 +33,7 @@ targets: dependencies: - package: DeviceKit + - package: DTCoreText configFiles: Debug: Debug.xcconfig diff --git a/RiotSwiftUI/Modules/Room/Composer/Model/ComposerModels.swift b/RiotSwiftUI/Modules/Room/Composer/Model/ComposerModels.swift index 5525e9940..800494c5d 100644 --- a/RiotSwiftUI/Modules/Room/Composer/Model/ComposerModels.swift +++ b/RiotSwiftUI/Modules/Room/Composer/Model/ComposerModels.swift @@ -36,6 +36,8 @@ enum FormatType { case strikethrough case unorderedList case orderedList + case indent + case unIndent case inlineCode case codeBlock case quote @@ -66,6 +68,10 @@ extension FormatItem { return Asset.Images.bulletList.name case .orderedList: return Asset.Images.numberedList.name + case .indent: + return Asset.Images.indentIncrease.name + case .unIndent: + return Asset.Images.indentDecrease.name case .inlineCode: return Asset.Images.code.name case .codeBlock: @@ -91,6 +97,10 @@ extension FormatItem { return "unorderedListButton" case .orderedList: return "orderedListButton" + case .indent: + return "indentListButton" + case .unIndent: + return "unIndentButton" case .inlineCode: return "inlineCodeButton" case .codeBlock: @@ -116,6 +126,10 @@ extension FormatItem { return VectorL10n.wysiwygComposerFormatActionUnorderedList case .orderedList: return VectorL10n.wysiwygComposerFormatActionOrderedList + case .indent: + return VectorL10n.wysiwygComposerFormatActionIndent + case .unIndent: + return VectorL10n.wysiwygComposerFormatActionUnIndent case .inlineCode: return VectorL10n.wysiwygComposerFormatActionInlineCode case .codeBlock: @@ -144,6 +158,10 @@ extension FormatType { return .unorderedList case .orderedList: return .orderedList + case .indent: + return .indent + case .unIndent: + return .unIndent case .inlineCode: return .inlineCode case .codeBlock: @@ -171,6 +189,10 @@ extension FormatType { return .unorderedList case .orderedList: return .orderedList + case .indent: + return .indent + case .unIndent: + return .unIndent case .inlineCode: return .inlineCode case .codeBlock: diff --git a/SiriIntents/target.yml b/SiriIntents/target.yml index 324497cf3..82f7a89da 100644 --- a/SiriIntents/target.yml +++ b/SiriIntents/target.yml @@ -34,6 +34,7 @@ targets: dependencies: - sdk: Intents.framework - package: DeviceKit + - package: DTCoreText configFiles: Debug: Debug.xcconfig diff --git a/changelog.d/7316.change b/changelog.d/7316.change new file mode 100644 index 000000000..4ef97e1bd --- /dev/null +++ b/changelog.d/7316.change @@ -0,0 +1 @@ +Labs: Rich text editor: enable list items indentation diff --git a/project.yml b/project.yml index fe9af33a8..de099a507 100644 --- a/project.yml +++ b/project.yml @@ -53,7 +53,10 @@ packages: branch: main WysiwygComposer: url: https://github.com/matrix-org/matrix-wysiwyg-composer-swift - version: 0.19.0 + version: 0.22.0 DeviceKit: url: https://github.com/devicekit/DeviceKit majorVersion: 4.7.0 + DTCoreText: + url: https://github.com/Cocoanetics/DTCoreText + version: 1.6.27 \ No newline at end of file