History menu improvements
This commit is contained in:
@@ -34,7 +34,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
private func historyMenu() -> UIMenu {
|
||||
let historyItems = BrowserHistory.shared.allHistory(limit: 50).map { item in
|
||||
let title = (item.title.count > 0) ? item.title : item.url.absoluteString
|
||||
let title = ((item.title.count > 0) ? item.title : item.url.absoluteString)
|
||||
.middleTruncatedString(maximumLength: 85)
|
||||
|
||||
return UIAction(title: title) { action in
|
||||
UIApplication.shared.sendAction(#selector(ShortcutResponder.handleOpenURL), to: nil, from: action, for: OpenURLEvent(url: item.url))
|
||||
}
|
||||
|
||||
@@ -84,6 +84,8 @@ class BrowserHistory
|
||||
let nserror = error as NSError
|
||||
fatalError("Failed saving persistent entity to store: \(nserror), \(nserror.userInfo)")
|
||||
}
|
||||
|
||||
UIMenuSystem.main.setNeedsRebuild()
|
||||
}
|
||||
|
||||
public func viewModel(forFilterString filterString: String? = nil, limit: Int = 500) -> ViewModel {
|
||||
|
||||
26
App/Utilities/StringUtilities.swift
Normal file
26
App/Utilities/StringUtilities.swift
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// StringUtilities.swift
|
||||
// App
|
||||
//
|
||||
// Created by James Magahern on 7/31/24.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension String {
|
||||
internal func middleTruncatedString(maximumLength: Int) -> String {
|
||||
if maximumLength > self.count {
|
||||
return self
|
||||
}
|
||||
|
||||
// Compute replacement range
|
||||
let pivot = self.count / 2
|
||||
let truncationLength = self.count - maximumLength
|
||||
|
||||
let pivotIndex = self.index(startIndex, offsetBy: pivot)
|
||||
let startIndex = self.index(pivotIndex, offsetBy: -truncationLength / 2)
|
||||
let endIndex = self.index(pivotIndex, offsetBy: truncationLength / 2)
|
||||
|
||||
return replacingCharacters(in: startIndex..<endIndex, with: "…")
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,7 @@
|
||||
CD936A3D289DB88B0093A1AC /* UIView+Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD936A3C289DB88B0093A1AC /* UIView+Utils.swift */; };
|
||||
CD97CF9225D5BE6F00288FEE /* NavigationControlsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD97CF9125D5BE6F00288FEE /* NavigationControlsView.swift */; };
|
||||
CD9B88C2272201E900DAAB7E /* SBRScriptPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = CD361CF5271A3718006E9CA5 /* SBRScriptPolicy.m */; };
|
||||
CDACE18C2C5B09F00053AB29 /* StringUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDACE18B2C5B09F00053AB29 /* StringUtilities.swift */; };
|
||||
CDAD9CE8263A2DF200FF7199 /* DocumentControlsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDAD9CE7263A2DF200FF7199 /* DocumentControlsView.swift */; };
|
||||
CDAD9CEA263A318F00FF7199 /* ShareableURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDAD9CE9263A318F00FF7199 /* ShareableURL.swift */; };
|
||||
CDB6807D28B446FC007D787E /* ReaderSceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB6807C28B446FC007D787E /* ReaderSceneDelegate.swift */; };
|
||||
@@ -177,6 +178,7 @@
|
||||
CD936A3A289DB3380093A1AC /* TabInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabInfo.swift; sourceTree = "<group>"; };
|
||||
CD936A3C289DB88B0093A1AC /* UIView+Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Utils.swift"; sourceTree = "<group>"; };
|
||||
CD97CF9125D5BE6F00288FEE /* NavigationControlsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationControlsView.swift; sourceTree = "<group>"; };
|
||||
CDACE18B2C5B09F00053AB29 /* StringUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringUtilities.swift; sourceTree = "<group>"; };
|
||||
CDAD9CE7263A2DF200FF7199 /* DocumentControlsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentControlsView.swift; sourceTree = "<group>"; };
|
||||
CDAD9CE9263A318F00FF7199 /* ShareableURL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareableURL.swift; sourceTree = "<group>"; };
|
||||
CDB6807C28B446FC007D787E /* ReaderSceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReaderSceneDelegate.swift; sourceTree = "<group>"; };
|
||||
@@ -399,6 +401,7 @@
|
||||
CDEDD8A925D62ADB00862605 /* UITraitCollection+MacLike.swift */,
|
||||
CD936A3C289DB88B0093A1AC /* UIView+Utils.swift */,
|
||||
CD8DBE7A2A85D892006A0FE0 /* LayoutLatch.swift */,
|
||||
CDACE18B2C5B09F00053AB29 /* StringUtilities.swift */,
|
||||
);
|
||||
path = Utilities;
|
||||
sourceTree = "<group>";
|
||||
@@ -673,6 +676,7 @@
|
||||
CDAD9CE8263A2DF200FF7199 /* DocumentControlsView.swift in Sources */,
|
||||
1ADFF4C924CA793E006DC7AE /* ToolbarViewController.swift in Sources */,
|
||||
CD7A89172519872D0075991E /* KeyboardShortcuts.swift in Sources */,
|
||||
CDACE18C2C5B09F00053AB29 /* StringUtilities.swift in Sources */,
|
||||
1ADFF4CD24CBB0C8006DC7AE /* ScriptOriginPolicyViewController.swift in Sources */,
|
||||
CDE6A30425F023BC00E912A4 /* AmberSettingsViewController.swift in Sources */,
|
||||
1A14FC2824D26749009B3F83 /* Tab.swift in Sources */,
|
||||
|
||||
Reference in New Issue
Block a user