From c32181818aa8da4a6e6bef2e35dda2ca9a02a593 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 15 Apr 2024 00:12:20 -0400 Subject: [PATCH] Use image for code formatting option --- .../ComposeUI/Controllers/ToolbarController.swift | 9 ++------- .../Sources/ComposeUI/Model/StatusFormat.swift | 14 +++----------- .../Sources/ComposeUI/Views/MainTextView.swift | 6 +----- 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/Packages/ComposeUI/Sources/ComposeUI/Controllers/ToolbarController.swift b/Packages/ComposeUI/Sources/ComposeUI/Controllers/ToolbarController.swift index 719765208c..bcef0cf0ac 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/Controllers/ToolbarController.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/Controllers/ToolbarController.swift @@ -181,13 +181,8 @@ class ToolbarController: ViewController { private var formatButtons: some View { ForEach(StatusFormat.allCases, id: \.rawValue) { format in Button(action: controller.formatAction(format)) { - if let imageName = format.imageName { - Image(systemName: imageName) - .font(.system(size: imageSize)) - } else if let (str, attrs) = format.title { - let container = try! AttributeContainer(attrs, including: \.uiKit) - Text(AttributedString(str, attributes: container)) - } + Image(systemName: format.imageName) + .font(.system(size: imageSize)) } .accessibilityLabel(format.accessibilityLabel) .padding(5) diff --git a/Packages/ComposeUI/Sources/ComposeUI/Model/StatusFormat.swift b/Packages/ComposeUI/Sources/ComposeUI/Model/StatusFormat.swift index 2357b01915..af57c88dab 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/Model/StatusFormat.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/Model/StatusFormat.swift @@ -23,7 +23,7 @@ enum StatusFormat: Int, CaseIterable { } } - var imageName: String? { + var imageName: String { switch self { case .italics: return "italic" @@ -31,16 +31,8 @@ enum StatusFormat: Int, CaseIterable { return "bold" case .strikethrough: return "strikethrough" - default: - return nil - } - } - - var title: (String, [NSAttributedString.Key: Any])? { - if self == .code { - return ("", [.font: UIFont(name: "Menlo", size: 17)!]) - } else { - return nil + case .code: + return "chevron.left.forwardslash.chevron.right" } } diff --git a/Packages/ComposeUI/Sources/ComposeUI/Views/MainTextView.swift b/Packages/ComposeUI/Sources/ComposeUI/Views/MainTextView.swift index 23fe44e31d..0d6c52650c 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/Views/MainTextView.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/Views/MainTextView.swift @@ -259,11 +259,7 @@ fileprivate struct MainWrappedTextViewRepresentable: UIViewRepresentable { if range.length > 0 { let formatMenu = suggestedActions[index] as! UIMenu let newFormatMenu = formatMenu.replacingChildren(StatusFormat.allCases.map { fmt in - var image: UIImage? - if let imageName = fmt.imageName { - image = UIImage(systemName: imageName) - } - return UIAction(title: fmt.accessibilityLabel, image: image) { [weak self] _ in + return UIAction(title: fmt.accessibilityLabel, image: UIImage(systemName: fmt.imageName)) { [weak self] _ in self?.applyFormat(fmt) } })