Skip to content

Commit

Permalink
Merge pull request #81 from oleksandr-danylchenko/fix-nested-not-anno…
Browse files Browse the repository at this point in the history
…tatable-selection

#80 Fixed annotating of the nested `not annotatable` content
  • Loading branch information
rsimon committed Mar 29, 2024
2 parents 5389543 + a89112a commit bed5202
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
5 changes: 4 additions & 1 deletion packages/text-annotator/src/utils/splitAnnotatableRanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ const iterateNotAnnotatableElements = function*(range: Range): Generator<HTMLEle
range.commonAncestorContainer,
NodeFilter.SHOW_ELEMENT,
(node) =>
node instanceof HTMLElement && node.classList.contains(NOT_ANNOTATABLE_CLASS) && range.intersectsNode(node)
node instanceof HTMLElement // Only elements that can have the class applied
&& node.classList.contains(NOT_ANNOTATABLE_CLASS) // Only elements that are not annotatable
&& !node.parentElement.closest(NOT_ANNOTATABLE_SELECTOR) // Only elements that are not descendants of a not annotatable element
&& range.intersectsNode(node) // Only elements that are within the range
? NodeFilter.FILTER_ACCEPT
: NodeFilter.FILTER_SKIP
);
Expand Down
20 changes: 12 additions & 8 deletions packages/text-annotator/test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
}

#content .not-annotatable {
background-color: wheat;
color: dimgray;
border: 3px solid wheat;
}

h1 {
Expand Down Expand Up @@ -107,13 +108,16 @@ <h5>
other gods:
</p>

<p>
"See now, how men lay blame upon us gods for what is after all nothing but their own folly. Look at Aegisthus;
he must needs make love to Agamemnon's wife unrighteously and then kill Agamemnon, though he knew it would be
the death of him; for I sent Mercury to warn him not to do either of these things, inasmuch as Orestes would be
sure to take his revenge when he grew up and wanted to return home. Mercury told him this in all good will but
he would not listen, and now he has paid for everything in full."
</p>
<div class="not-annotatable">
<h3>Not annotatable block!</h3>
<p>
"See now, how men lay blame upon us gods for what is after all nothing but their own folly. Look at Aegisthus;
he must needs make love to Agamemnon's wife unrighteously and then kill Agamemnon, though he knew it would be
the <span class="not-annotatable">death of him; for I sent Mercury to warn him not</span> to do either of these things, inasmuch as Orestes would be
sure to take his revenge when he grew up and wanted to return home. Mercury told him this in all good will but
he would not listen, and now he has paid for everything in full."
</p>
</div>

<p>
Then Minerva said, "Father, son of Saturn, King of kings, it served Aegisthus right, and so it would any one
Expand Down

0 comments on commit bed5202

Please sign in to comment.