This is an automated email from the ASF dual-hosted git repository. gerben pushed a commit to branch faster-describeTextQuote in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git
commit 486c59f60b9125e87f250c8b7a725242cc942b0d Author: Gerben <[email protected]> AuthorDate: Fri Sep 18 15:29:59 2020 +0200 Add test, fix bug --- packages/dom/src/text-quote/describe.ts | 2 ++ packages/dom/test/text-quote/describe-cases.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/packages/dom/src/text-quote/describe.ts b/packages/dom/src/text-quote/describe.ts index 93cbe53..50a5653 100644 --- a/packages/dom/src/text-quote/describe.ts +++ b/packages/dom/src/text-quote/describe.ts @@ -92,6 +92,8 @@ function calculateContextForDisambiguation( // Use either the prefix or suffix, whichever is shortest. if (sufficientPrefixLength <= sufficientSuffixLength) { + // Compensate our search position for the increase in prefix length. + fromIndex -= sufficientPrefixLength - prefix.length; prefix = scopeText.substring( targetStartIndex - sufficientPrefixLength, targetStartIndex, diff --git a/packages/dom/test/text-quote/describe-cases.ts b/packages/dom/test/text-quote/describe-cases.ts index 7d43a5f..142437d 100644 --- a/packages/dom/test/text-quote/describe-cases.ts +++ b/packages/dom/test/text-quote/describe-cases.ts @@ -104,6 +104,21 @@ export const testCases: { suffix: '', }, }, + 'multiple, overlapping false matches': { + html: '<b>aaaaaaaaaa</b>', + range: { + startContainerXPath: '//b/text()', + startOffset: 4, + endContainerXPath: '//b/text()', + endOffset: 7, + }, + expected: { + type: 'TextQuoteSelector', + exact: 'aaa', + prefix: 'aaaa', + suffix: 'aaa', + }, + }, 'empty quote': { html: '<b>To annotate or not to annotate</b>', range: {
