Skip to content

Commit 8fad4d5

Browse files
committed
Merge branch 'main' into develop
2 parents 648fb0f + 686a1d4 commit 8fad4d5

File tree

4 files changed

+48
-24
lines changed

4 files changed

+48
-24
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ All notable changes to this project will be documented in this file. Take a look
5454
* `Publication.localizedTitle` is now optional, as we cannot guarantee a publication will always have a title.
5555

5656

57+
## [2.7.2]
58+
59+
### Fixed
60+
61+
#### Shared
62+
63+
* [#444](https://github.com/readium/swift-toolkit/issues/444) Fixed resolving titles of search results when the table of contents items contain fragment identifiers.
64+
65+
#### Navigator
66+
67+
* [#428](https://github.com/readium/swift-toolkit/issues/428) Fixed crash with the `share` editing action on iOS 17.
68+
* [#428](https://github.com/readium/swift-toolkit/issues/428) Fixed showing look up and translate editing actions on iOS 17.
69+
70+
5771
## [2.7.1]
5872

5973
### Added
@@ -720,4 +734,5 @@ progression. Now if no reading progression is set, the `effectiveReadingProgress
720734
[2.6.1]: https://github.com/readium/swift-toolkit/compare/2.6.0...2.6.1
721735
[2.7.0]: https://github.com/readium/swift-toolkit/compare/2.6.1...2.7.0
722736
[2.7.1]: https://github.com/readium/swift-toolkit/compare/2.7.0...2.7.1
737+
[2.7.2]: https://github.com/readium/swift-toolkit/compare/2.7.1...2.7.2
723738
[3.0.0-alpha.1]: https://github.com/readium/swift-toolkit/compare/2.7.1...3.0.0-alpha.1

Sources/Internal/Extensions/String.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public extension String {
6767
guard let range = range(of: delimiter, options: [.backwards, .literal]) else {
6868
return self
6969
}
70-
return String(self[...range.lowerBound])
70+
return String(self[..<range.lowerBound])
7171
}
7272

7373
/// Replaces multiple whitespaces by a single space.

Sources/Navigator/EditingAction.swift

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,26 @@ import UIKit
1919
public struct EditingAction: Hashable {
2020
/// Default editing actions enabled in the navigator.
2121
public static var defaultActions: [EditingAction] {
22-
[copy, share, define, lookup, translate]
22+
[copy, share, lookup, translate]
2323
}
2424

2525
/// Copy the text selection.
26-
public static let copy = EditingAction(kind: .native("copy:"))
26+
public static let copy = EditingAction(kind: .native(["copy:"]))
2727

2828
/// Look up the text selection in the dictionary and other sources.
2929
///
30-
/// Not available on iOS 16+
31-
public static let lookup = EditingAction(kind: .native("_lookup:"))
32-
33-
/// Look up the text selection in the dictionary (and other sources on
34-
/// iOS 16+).
35-
///
3630
/// On iOS 16+, enabling this action will show two items: Look Up and
3731
/// Search Web.
38-
public static let define = EditingAction(kind: .native("_define:"))
32+
public static let lookup = EditingAction(kind: .native(["lookup", "_lookup:", "define:", "_define:"]))
33+
34+
@available(*, deprecated, message: "lookup and define were merged", renamed: "lookup")
35+
public static let define = lookup
3936

4037
/// Translate the text selection.
41-
public static let translate = EditingAction(kind: .native("_translate:"))
38+
public static let translate = EditingAction(kind: .native(["translate:", "_translate:"]))
4239

4340
/// Share the text selection.
44-
public static let share = EditingAction(kind: .native("_share:"))
41+
public static let share = EditingAction(kind: .native(["share:", "_share:"]))
4542

4643
/// Create a custom editing action.
4744
///
@@ -53,7 +50,7 @@ public struct EditingAction: Hashable {
5350
}
5451

5552
enum Kind: Hashable {
56-
case native(String)
53+
case native([String])
5754
case custom(UIMenuItem)
5855
}
5956

@@ -63,12 +60,12 @@ public struct EditingAction: Hashable {
6360
self.kind = kind
6461
}
6562

66-
var action: Selector {
63+
var actions: [Selector] {
6764
switch kind {
68-
case let .native(action):
69-
return Selector(action)
65+
case let .native(actions):
66+
return actions.map { Selector($0) }
7067
case let .custom(item):
71-
return item.action
68+
return [item.action]
7269
}
7370
}
7471

@@ -119,14 +116,14 @@ final class EditingActionsController {
119116
}
120117

121118
func canPerformAction(_ action: EditingAction) -> Bool {
122-
canPerformAction(action.action)
119+
action.actions.contains { canPerformAction($0) }
123120
}
124121

125122
func canPerformAction(_ selector: Selector) -> Bool {
126123
guard
127124
isEnabled,
128125
let selection = selection,
129-
let action = actions.first(where: { $0.action == selector }),
126+
let action = actions.first(where: { $0.actions.contains(selector) }),
130127
isActionAllowed(action)
131128
else {
132129
return false
@@ -147,11 +144,6 @@ final class EditingActionsController {
147144

148145
@available(iOS 13.0, *)
149146
func buildMenu(with builder: UIMenuBuilder) {
150-
// On iOS 16, there's a new "Search Web" menu item which is required
151-
// to enable the define action.
152-
if #available(iOS 16.0, *), !canPerformAction(.define) {
153-
builder.remove(menu: .lookup)
154-
}
155147
if !canPerformAction(.lookup) {
156148
builder.remove(menu: .lookup)
157149
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// Copyright 2024 Readium Foundation. All rights reserved.
3+
// Use of this source code is governed by the BSD-style license
4+
// available in the top-level LICENSE file of the project.
5+
//
6+
7+
import Foundation
8+
@testable import ReadiumInternal
9+
import XCTest
10+
11+
class StringTests: XCTestCase {
12+
func testSubstringBeforeLast() {
13+
XCTAssertEqual("href".substringBeforeLast("#"), "href")
14+
XCTAssertEqual("href#anchor".substringBeforeLast("#"), "href")
15+
XCTAssertEqual("href#anchor#test".substringBeforeLast("#"), "href#anchor")
16+
}
17+
}

0 commit comments

Comments
 (0)