You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@annotator.apache.org by ra...@apache.org on 2019/10/07 20:02:40 UTC
[incubator-annotator] 04/10: Improve handling of affixes at scope
boundaries
This is an automated email from the ASF dual-hosted git repository.
randall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git
commit 8b29fec247bac3f33b3b9179504de108ecd61171
Author: Randall Leeds <ra...@apache.org>
AuthorDate: Sat Sep 28 16:30:42 2019 -0700
Improve handling of affixes at scope boundaries
---
packages/dom/src/text-quote.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/packages/dom/src/text-quote.js b/packages/dom/src/text-quote.js
index 9a7f28c..81bd0d8 100644
--- a/packages/dom/src/text-quote.js
+++ b/packages/dom/src/text-quote.js
@@ -135,7 +135,7 @@ export async function describeTextQuote(range, scope = null) {
: seek(iter, startNode);
const endIndex = startIndex + exact.length;
- const affixLengthPairs = [[0, 0]];
+ const affixLengthPairs = [];
for await (const match of selector(scope)) {
const matchIter = createNodeIterator(root, SHOW_TEXT);
@@ -174,11 +174,11 @@ export async function describeTextQuote(range, scope = null) {
if (affixLengthPairs.length) {
const [prefixLength, suffixLength] = minimalSolution(affixLengthPairs);
- if (prefixLength > 0) {
+ if (prefixLength > 0 && startIndex > 0) {
result.prefix = text.substring(startIndex - prefixLength, startIndex);
}
- if (suffixLength > 0) {
+ if (suffixLength > 0 && endIndex < text.length) {
result.suffix = text.substring(endIndex, endIndex + suffixLength);
}
}