readium / SDKLauncher-Android

Launcher app for Readium SDK on Android
BSD 3-Clause "New" or "Revised" License
77 stars 65 forks source link

Highlights plugin not working properly #153

Closed rahulk11 closed 4 years ago

rahulk11 commented 4 years ago

Question

Hi, I included the highlights plugin into the shared-js project and rebuilt it. But, It is working in rare cases.

Upon clicking the highlight action button i am calling ReadiumSDK.reader.plugins.highlights.addSelectionHighlight js method but most of the time nothing happens because the Selection.getRangeAt() returns a range with same value of startOffset and endOffset and hence the range.toString() is empty.

Is it an issue or I am doing something wrong? thanks

Steps to reproduce

  1. add highlight plugin and build
  2. select the text on phone screen
  3. call ReadiumSDK.reader.plugins.highlights.addSelectionHighlight with params

SDKLauncher-Android

Additional information

This is the method where the selection (range.toString() !== '') is empty

_getCurrentSelectionRange: function() {
            var currentSelection;
            var iframeDocument = this.context.document;
            if (iframeDocument.getSelection) {

                currentSelection = iframeDocument.getSelection();
                if (!currentSelection || currentSelection.rangeCount === 0) {
                    return undefined;
                }

                var range = currentSelection.getRangeAt(0);
                // window.alert("startOffset "+range.startOffset+"\nendOffset "+range.endOffset);
                if (range.toString() !== '') {
                    return range;
                } else {
                    return undefined;
                }
            } else if (iframeDocument.selection) {
                return iframeDocument.selection.createRange();
            } else {
                return undefined;
            }
        }

ScreenRecord-2019-10-14-17-02-54_Trim__Trim_

rahulk11 commented 4 years ago

Its working now. It was my mistake actually. I was closing the action menu on the click event which also was setting the selection to empty before it could reach the JS method execution. Now I am closing my action menu after i receive a callback from JS to my native code.

rahulk11 commented 4 years ago

Now, another issue is there. Highlighting works properly on the first page of chapter. On other pages when i highlight an area, instead of showing the color on that page area, it shows on first page.

rahulk11 commented 4 years ago

Found the issue. needed to set paginationInfo.pageOffset .