mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 15:22:39 +00:00
Labs: Rich text editor: enable list items indentation
This commit is contained in:
parent
b741d3526d
commit
166ec54ac2
16 changed files with 79 additions and 132 deletions
2
Podfile
2
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
|
||||
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -25,7 +25,6 @@
|
|||
#import "MXDecryptionResult.h"
|
||||
#import "DecryptionFailureTracker.h"
|
||||
|
||||
#import "EventFormatter+DTCoreTextFix.h"
|
||||
#import <MatrixSDK/MatrixSDK.h>
|
||||
|
||||
#pragma mark - Constants definitions
|
||||
|
@ -50,11 +49,6 @@ static NSString *const kEventFormatterTimeFormat = @"HH:mm";
|
|||
|
||||
@implementation EventFormatter
|
||||
|
||||
+ (void)load
|
||||
{
|
||||
[self fixDTCoreTextFont];
|
||||
}
|
||||
|
||||
- (void)initDateTimeFormatters
|
||||
{
|
||||
[super initDateTimeFormatters];
|
||||
|
|
|
@ -44,6 +44,7 @@ targets:
|
|||
- package: SwiftOGG
|
||||
- package: WysiwygComposer
|
||||
- package: DeviceKit
|
||||
- package: DTCoreText
|
||||
|
||||
configFiles:
|
||||
Debug: Debug.xcconfig
|
||||
|
|
|
@ -33,6 +33,7 @@ targets:
|
|||
|
||||
dependencies:
|
||||
- package: DeviceKit
|
||||
- package: DTCoreText
|
||||
|
||||
configFiles:
|
||||
Debug: Debug.xcconfig
|
||||
|
|
|
@ -33,6 +33,7 @@ targets:
|
|||
|
||||
dependencies:
|
||||
- package: DeviceKit
|
||||
- package: DTCoreText
|
||||
|
||||
configFiles:
|
||||
Debug: Debug.xcconfig
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -34,6 +34,7 @@ targets:
|
|||
dependencies:
|
||||
- sdk: Intents.framework
|
||||
- package: DeviceKit
|
||||
- package: DTCoreText
|
||||
|
||||
configFiles:
|
||||
Debug: Debug.xcconfig
|
||||
|
|
1
changelog.d/7316.change
Normal file
1
changelog.d/7316.change
Normal file
|
@ -0,0 +1 @@
|
|||
Labs: Rich text editor: enable list items indentation
|
|
@ -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
|
Loading…
Reference in a new issue