Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-menu committed Jun 4, 2024
2 parents 648fb0f + 686a1d4 commit 8fad4d5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 24 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ All notable changes to this project will be documented in this file. Take a look
* `Publication.localizedTitle` is now optional, as we cannot guarantee a publication will always have a title.


## [2.7.2]

### Fixed

#### Shared

* [#444](https://github.com/readium/swift-toolkit/issues/444) Fixed resolving titles of search results when the table of contents items contain fragment identifiers.

#### Navigator

* [#428](https://github.com/readium/swift-toolkit/issues/428) Fixed crash with the `share` editing action on iOS 17.
* [#428](https://github.com/readium/swift-toolkit/issues/428) Fixed showing look up and translate editing actions on iOS 17.


## [2.7.1]

### Added
Expand Down Expand Up @@ -720,4 +734,5 @@ progression. Now if no reading progression is set, the `effectiveReadingProgress
[2.6.1]: https://github.com/readium/swift-toolkit/compare/2.6.0...2.6.1
[2.7.0]: https://github.com/readium/swift-toolkit/compare/2.6.1...2.7.0
[2.7.1]: https://github.com/readium/swift-toolkit/compare/2.7.0...2.7.1
[2.7.2]: https://github.com/readium/swift-toolkit/compare/2.7.1...2.7.2
[3.0.0-alpha.1]: https://github.com/readium/swift-toolkit/compare/2.7.1...3.0.0-alpha.1
2 changes: 1 addition & 1 deletion Sources/Internal/Extensions/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public extension String {
guard let range = range(of: delimiter, options: [.backwards, .literal]) else {
return self
}
return String(self[...range.lowerBound])
return String(self[..<range.lowerBound])
}

/// Replaces multiple whitespaces by a single space.
Expand Down
38 changes: 15 additions & 23 deletions Sources/Navigator/EditingAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,26 @@ import UIKit
public struct EditingAction: Hashable {
/// Default editing actions enabled in the navigator.
public static var defaultActions: [EditingAction] {
[copy, share, define, lookup, translate]
[copy, share, lookup, translate]
}

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

/// Look up the text selection in the dictionary and other sources.
///
/// Not available on iOS 16+
public static let lookup = EditingAction(kind: .native("_lookup:"))

/// Look up the text selection in the dictionary (and other sources on
/// iOS 16+).
///
/// On iOS 16+, enabling this action will show two items: Look Up and
/// Search Web.
public static let define = EditingAction(kind: .native("_define:"))
public static let lookup = EditingAction(kind: .native(["lookup", "_lookup:", "define:", "_define:"]))

@available(*, deprecated, message: "lookup and define were merged", renamed: "lookup")
public static let define = lookup

/// Translate the text selection.
public static let translate = EditingAction(kind: .native("_translate:"))
public static let translate = EditingAction(kind: .native(["translate:", "_translate:"]))

/// Share the text selection.
public static let share = EditingAction(kind: .native("_share:"))
public static let share = EditingAction(kind: .native(["share:", "_share:"]))

/// Create a custom editing action.
///
Expand All @@ -53,7 +50,7 @@ public struct EditingAction: Hashable {
}

enum Kind: Hashable {
case native(String)
case native([String])
case custom(UIMenuItem)
}

Expand All @@ -63,12 +60,12 @@ public struct EditingAction: Hashable {
self.kind = kind
}

var action: Selector {
var actions: [Selector] {
switch kind {
case let .native(action):
return Selector(action)
case let .native(actions):
return actions.map { Selector($0) }
case let .custom(item):
return item.action
return [item.action]
}
}

Expand Down Expand Up @@ -119,14 +116,14 @@ final class EditingActionsController {
}

func canPerformAction(_ action: EditingAction) -> Bool {
canPerformAction(action.action)
action.actions.contains { canPerformAction($0) }
}

func canPerformAction(_ selector: Selector) -> Bool {
guard
isEnabled,
let selection = selection,
let action = actions.first(where: { $0.action == selector }),
let action = actions.first(where: { $0.actions.contains(selector) }),
isActionAllowed(action)
else {
return false
Expand All @@ -147,11 +144,6 @@ final class EditingActionsController {

@available(iOS 13.0, *)
func buildMenu(with builder: UIMenuBuilder) {
// On iOS 16, there's a new "Search Web" menu item which is required
// to enable the define action.
if #available(iOS 16.0, *), !canPerformAction(.define) {
builder.remove(menu: .lookup)
}
if !canPerformAction(.lookup) {
builder.remove(menu: .lookup)
}
Expand Down
17 changes: 17 additions & 0 deletions Tests/InternalTests/Extensions/StringTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Copyright 2024 Readium Foundation. All rights reserved.
// Use of this source code is governed by the BSD-style license
// available in the top-level LICENSE file of the project.
//

import Foundation
@testable import ReadiumInternal
import XCTest

class StringTests: XCTestCase {
func testSubstringBeforeLast() {
XCTAssertEqual("href".substringBeforeLast("#"), "href")
XCTAssertEqual("href#anchor".substringBeforeLast("#"), "href")
XCTAssertEqual("href#anchor#test".substringBeforeLast("#"), "href#anchor")
}
}

0 comments on commit 8fad4d5

Please sign in to comment.