Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Didn't get highlighted text. #128

Closed
vishalpatel-simformsolutions opened this issue Sep 16, 2021 · 17 comments
Closed

Question: Didn't get highlighted text. #128

vishalpatel-simformsolutions opened this issue Sep 16, 2021 · 17 comments

Comments

@vishalpatel-simformsolutions
Copy link

Hey,
I want to get Highlighted text in EPUBViewController.
So I have added custom editAction
var config = EPUBNavigatorViewController.Configuration() config.editingActions.append(EditingAction(title: "Highlight", action: #selector(highlight)))

@objc func highlight(_ sender: Any) { print(epubNavigator.currentLocation?.text.highlight) }

but I am getting nil in highlight.

Is there something else that I am missing here ?
@vishalpatel-simformsolutions vishalpatel-simformsolutions changed the title didn't get highlighted text. Question: Didn't get highlighted text. Sep 16, 2021
@mickael-menu
Copy link
Member

currentLocation is used for bookmarking and match the top of the page, not the user selection. Try using currentSelection instead, available in Readium 2.1.

@vishalpatel-simformsolutions
Copy link
Author

Thank you very much @mickael-menu
But still, I am getting nil.

@vishalpatel-simformsolutions
Copy link
Author

@mickael-menu
Is it possible to give an example of the use of SelectableNavigator,SelectableNavigatorDelegate .?
So I get the idea that my created inherited EPUBNavigatorViewController is proper or not.

@mickael-menu
Copy link
Member

Did you try this after selecting some text?

@objc func highlight(_ sender: Any) {
    print(epubNavigator.currentSelection?.locator)
}

If it still doesn't work, create a new issue following the Bug Report issue template with a sample EPUB having the problem and a screenshot of your text selection.

@vishalpatel-simformsolutions
Copy link
Author

@vishalpatel-simformsolutions
Copy link
Author

@mickael-menu
I guess I problem with the custom navigator class with the use of EPUBNavigatorViewController, SelectableNavigator
So If you can provide a sample example then it will be greatly helpful for us.

@mickael-menu
Copy link
Member

What is this BaseNavigator? Are you subclassing EPUBNavigatorViewController? currentSelection is only available since the last 2.1 release. It's implemented like this in EPUBNavigatorViewController: https://github.com/readium/r2-navigator-swift/blob/160b7207e0d4a08fd1d7aca65c5a0aa931d56e39/r2-navigator-swift/EPUB/EPUBNavigatorViewController.swift#L567-L575

@vishalpatel-simformsolutions
Copy link
Author

Hey @mickael-menu
currentSelection is not in tag 2.1.0.
It's in develop.
Please check the video.
http://files.simformsolutions.com.s3.amazonaws.com/simformscreen/screencast_2021-09-16_16-15-32.mp4

@vishalpatel-simformsolutions
Copy link
Author

Also @mickael-menu

when I use develop branch code then book stop rendering.
http://files.simformsolutions.com.s3.amazonaws.com/simformscreen/screencast_2021-09-16_16-21-46.mp4

@mickael-menu
Copy link
Member

Ha you're right, I thought it was released already. Then getting the highlighted text is not supported yet (in a release).

You can't use a develop branch in one project without using develop in all the other Readium modules.

@vishalpatel-simformsolutions
Copy link
Author

Okey @mickael-menu . let me try with develop in all other Readium module,
Thank you man for personally look into this, Really appreciate.

@vishalpatel-simformsolutions
Copy link
Author

after changing all Readium modules to develop
Still getting the same issue not loading book.

http://files.simformsolutions.com.s3.amazonaws.com/simformscreen/R2_Reader_demo.xcodeproj_2021-09-16_16-30-20.png

@vishalpatel-simformsolutions
Copy link
Author

@mickael-menu
Is there something else that I am missing here?
Please guild me.

@mickael-menu
Copy link
Member

I don't know, this issue is honestly too vague to help you out. Try debugging to see where it comes from.

I would avoid subclassing EPUBNavigatorViewController too, it's not designed for it.

@vishalpatel-simformsolutions
Copy link
Author

Currently, I am not subclassing EPUBNavigatorViewController , I am using the default EPUBNavigatorViewController .
Okey Thank you @mickael-menu
Let me debug the issue. and let you know if I find out something.
Once again Really appreciate @mickael-menu

@emartinson
Copy link

@vishalpatel-simformsolutions if you're using R2 Test App and you've already added custom highlight Menu Action via

var config = EPUBNavigatorViewController.Configuration()
    
config.editingActions = EditingAction.defaultActions
config.editingActions.append(EditingAction(title: "Highlight", action: #selector(highlight(_:))))
    
let navigator = EPUBNavigatorViewController(publication: publication, initialLocation: locator, resourcesServer: resourcesServer, config: config)

Here is working example of text highlighting using menu.

@objc func highlight(_ sender: Any) {
    
    guard let selection = epubNavigator.currentSelection else {
      return
    }
    print("highlight: \(selection)")

    if let text = selection.locator.text.highlight {
      epubNavigator.apply(decorations: [Decoration(id: Decoration.Id(), locator: selection.locator, style: Decoration.Style.highlight())], in: text)
    }
  }

@vishalpatel-simformsolutions
Copy link
Author

thank you @emartinson . It worked with develop branch.

@mickael-menu mickael-menu transferred this issue from readium/r2-navigator-swift Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants