@openstax/highlighter
Advanced tools
Comparing version 1.1.6 to 1.1.7
{ | ||
"name": "@openstax/highlighter", | ||
"version": "1.1.6", | ||
"version": "1.1.7", | ||
"main": "dist/highlighter.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -7,2 +7,3 @@ import {DATA_ATTR} from '../../injectHighlightWrappers'; | ||
const isText = node => node && node.nodeType === 3; | ||
const isTextOrTextHighlight = node => isText(node) || isTextHighlight(node); | ||
const isElement = node => node && node.nodeType === 1; | ||
@@ -18,5 +19,5 @@ const isTextOrElement = node => isText(node) || isElement(node); | ||
// if the range offset designates a text highlight we need to move the target to the highlight | ||
// if the range offset designates text or a text highlight we need to move the target | ||
// so text offset stuff will work | ||
if (isElement(targetElement) && isTextHighlight(targetElement.childNodes[offset])) { | ||
if (isElement(targetElement) && isTextOrTextHighlight(targetElement.childNodes[offset])) { | ||
targetElement = targetElement.childNodes[offset]; | ||
@@ -23,0 +24,0 @@ offset = 0; |
@@ -224,2 +224,14 @@ import {DATA_ATTR} from '../../injectHighlightWrappers'; | ||
it('if target specifies the end of a highlight, move it ', () => { | ||
document.body.innerHTML = ` | ||
<div id="reference">qwer <span ${DATA_ATTR}>asdf</span> werewwer</div> | ||
`; | ||
const reference = document.getElementById('reference'); | ||
const [result, offset] = xpath.getXPathForElement(reference, 2, reference); | ||
expect(result).toEqual("./text()[1]"); | ||
expect(offset).toEqual(9); | ||
}); | ||
it('modifies offset for element target when treating text nodes separated by highlight as one', () => { | ||
@@ -226,0 +238,0 @@ document.body.innerHTML = ` |
Sorry, the diff of this file is too big to display
225976
5167