You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@annotator.apache.org by GitBox <gi...@apache.org> on 2022/08/28 14:37:56 UTC

[GitHub] [incubator-annotator] raphael10-collab opened a new issue, #128: I'm not getting the text position

raphael10-collab opened a new issue, #128:
URL: https://github.com/apache/incubator-annotator/issues/128

   The text is highlighted but I do not get the text position, needed for further annotating
   
   ![image](https://user-images.githubusercontent.com/70313067/187079466-224a78d1-8b7c-4787-9057-5e8934e5262f.png)
   
   This is the code I'm using:
   
       // https://annotator.apache.org/docs/getting-started/
       
       import { describeTextQuote } from '@apache-annotator/dom'
       import { createTextQuoteSelectorMatcher, highlightText } from '@apache-annotator/dom';
       
       async function describeCurrentSelection() {
         const userSelection = window.getSelection()?.getRangeAt(0);
       
         console.log("view-preload.ts-userSelection: ", userSelection)
       
         if (!userSelection || userSelection.isCollapsed) return;
       
         console.log("view-preloads-describeTextQuote(userSelection): ", describeTextQuote(userSelection))
       
         return describeTextQuote(userSelection);
       }
       
       async function highlightSelectorTarget(textQuoteSelector) {
         const matches = createTextQuoteSelectorMatcher(textQuoteSelector)(document.body);
       
         console.log("view-preload.ts-highlighSelectorTarger-matches: ", matches)
       
         // Modifying the DOM while searching can mess up; see issue #112.
         // Therefore, we first collect all matches before highlighting them.
         const matchList = [];
         for await (const match of matches) matchList.push(match);
       
         for (const match of matchList) highlightText(match);
       }
       
       
       document.addEventListener('mouseup', async () => {
       
         const selector = await describeCurrentSelection();
         const existingSelectors = JSON.parse(localStorage[document.URL] || '[]');
         localStorage[document.URL] = JSON.stringify([...existingSelectors, selector]);
         await highlightSelectorTarget(selector);
       })
       
       // Highlight the last selection that was stored, if any.
       async function highlightStoredSelectors() {
         if (localStorage[document.URL]) {
           const selectors = JSON.parse(localStorage[document.URL]);
           for (const selector of selectors) {
             console.log("view-preload.ts-highlightStoredSelectors-selector: ", selector)
             await highlightSelectorTarget(selector);
           }
         }
       }
       highlightStoredSelectors()
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@annotator.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-annotator] raphael10-collab closed issue #128: I'm not getting the text position

Posted by GitBox <gi...@apache.org>.
raphael10-collab closed issue #128: I'm not getting the text position
URL: https://github.com/apache/incubator-annotator/issues/128


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@annotator.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-annotator] Treora commented on issue #128: I'm not getting the text position

Posted by GitBox <gi...@apache.org>.
Treora commented on issue #128:
URL: https://github.com/apache/incubator-annotator/issues/128#issuecomment-1248013365

   A quick response, as I (nor others, it seems) get around to look further at your issue. From your description it’s not clear to me what you mean. If you mean to create a TextPositionSelector, see the [describeTextPosition](https://annotator.apache.org/docs/api/modules/dom.html#describetextposition). Best to get the position of the selection before highlighting it (if you do both), because the highlighter will modify the dom and thereby the selection.
   If you mean position as in coordinates on the page, you can get those from the browser’s APIs, e.g. [`Range.getBoundingClientRect`](https://developer.mozilla.org/en-US/docs/Web/API/Range/getBoundingClientRect). I hope that helps.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@annotator.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org