Compare commits

...

4 Commits

6 changed files with 28 additions and 12 deletions

View File

@ -67,7 +67,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
override func buildMenu(with builder: UIMenuBuilder) {
super.buildMenu(with: builder)
if builder.system == .main {
MenuController.buildMainMenu(builder: builder)
@ -107,4 +106,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return "compose"
}
}
@objc func closeWindow() {
guard let scene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) else {
return
}
UIApplication.shared.requestSceneSessionDestruction(scene.session, options: nil)
}
}

View File

@ -52,20 +52,21 @@ struct MenuController {
static let prevSubTabCommand = UIKeyCommand(title: "Previous Sub Tab", action: #selector(TabbedPageViewController.selectPrevPage), input: "[", modifierFlags: [.command, .shift])
static func buildMainMenu(builder: UIMenuBuilder) {
builder.insertChild(buildFileMenu(), atStartOfMenu: .file)
builder.replace(menu: .file, with: buildFileMenu())
builder.insertChild(buildSubTabMenu(), atStartOfMenu: .view)
builder.insertChild(buildSidebarShortcuts(), atStartOfMenu: .view)
}
private static func buildFileMenu() -> UIMenu {
return UIMenu(
title: "",
title: "File",
image: nil,
identifier: nil,
options: .displayInline,
options: [],
children: [
composeCommand,
refreshCommand(discoverabilityTitle: nil),
UIKeyCommand(title: "Close", action: #selector(AppDelegate.closeWindow), input: "w", modifierFlags: .command),
]
)
}

View File

@ -226,6 +226,8 @@ extension MastodonController {
draft.visibility = visibility
draft.contentWarning = contentWarning
draft.contentWarningEnabled = !contentWarning.isEmpty
DraftsManager.shared.add(draft)
return draft
}

View File

@ -198,7 +198,7 @@ class ExploreViewController: UIViewController, UICollectionViewDelegate {
@MainActor
private func fetchSavedHashtags() -> [SavedHashtag] {
let req = SavedHashtag.fetchRequest()
req.sortDescriptors = [NSSortDescriptor(key: "name", ascending: true)]
req.sortDescriptors = [NSSortDescriptor(key: "name", ascending: true, selector: #selector(NSString.localizedCompare(_:)))]
do {
return try mastodonController.persistentContainer.viewContext.fetch(req)
} catch {

View File

@ -228,7 +228,7 @@ class MainSidebarViewController: UIViewController {
@MainActor
private func fetchSavedHashtags() -> [SavedHashtag] {
let req = SavedHashtag.fetchRequest()
req.sortDescriptors = [NSSortDescriptor(key: "name", ascending: true)]
req.sortDescriptors = [NSSortDescriptor(key: "name", ascending: true, selector: #selector(NSString.localizedCompare(_:)))]
do {
return try mastodonController.persistentContainer.viewContext.fetch(req)
} catch {

View File

@ -78,6 +78,11 @@ class ContentTextView: LinkTextView, BaseEmojiLabel {
mutAttrString.trimTrailingCharactersInSet(.whitespacesAndNewlines)
mutAttrString.collapseWhitespace()
let style = NSMutableParagraphStyle()
// 2 points is enough that it doesn't make things look weirdly spaced out, but leaves a slight gap when there are multiple lines of emojis
style.lineSpacing = 2
mutAttrString.addAttribute(.paragraphStyle, value: style, range: mutAttrString.fullRange)
self.attributedText = mutAttrString
}
@ -99,7 +104,9 @@ class ContentTextView: LinkTextView, BaseEmojiLabel {
switch node.tagName() {
case "br":
attributed.append(NSAttributedString(string: "\n"))
// need to specify defaultFont here b/c otherwise it uses the default 12pt Helvetica which
// screws up its determination of the line height making multiple lines of emojis squash together
attributed.append(NSAttributedString(string: "\n", attributes: [.font: defaultFont]))
case "a":
if let link = try? node.attr("href"),
let webURL = WebURL(link),
@ -107,7 +114,7 @@ class ContentTextView: LinkTextView, BaseEmojiLabel {
attributed.addAttribute(.link, value: url, range: attributed.fullRange)
}
case "p":
attributed.append(NSAttributedString(string: "\n\n"))
attributed.append(NSAttributedString(string: "\n\n", attributes: [.font: defaultFont]))
case "em", "i":
let currentFont: UIFont
if attributed.length == 0 {
@ -129,11 +136,11 @@ class ContentTextView: LinkTextView, BaseEmojiLabel {
case "code":
attributed.addAttribute(.font, value: UIFont.monospacedSystemFont(ofSize: defaultFont.pointSize, weight: .regular), range: attributed.fullRange)
case "pre":
attributed.append(NSAttributedString(string: "\n\n"))
attributed.addAttribute(.font, value: UIFont.monospacedSystemFont(ofSize: defaultFont.pointSize, weight: .regular), range: attributed.fullRange)
attributed.append(NSAttributedString(string: "\n\n"))
case "ol", "ul":
attributed.trimLeadingCharactersInSet(.whitespacesAndNewlines)
attributed.append(NSAttributedString(string: "\n\n"))
attributed.trimLeadingCharactersInSet(.whitespacesAndNewlines)
case "li":
let parentEl = node.parent()!
let parentTag = parentEl.tagName()
@ -143,12 +150,12 @@ class ContentTextView: LinkTextView, BaseEmojiLabel {
// we use the monospace digit font so that the periods of all the list items line up
bullet = NSAttributedString(string: "\(index + 1).\t", attributes: [.font: UIFont.monospacedDigitSystemFont(ofSize: defaultFont.pointSize, weight: .regular)])
} else if parentTag == "ul" {
bullet = NSAttributedString(string: "\u{2022}\t")
bullet = NSAttributedString(string: "\u{2022}\t", attributes: [.font: defaultFont])
} else {
bullet = NSAttributedString()
}
attributed.insert(bullet, at: 0)
attributed.append(NSAttributedString(string: "\n"))
attributed.append(NSAttributedString(string: "\n", attributes: [.font: defaultFont]))
default:
break
}