This is an automated email from the ASF dual-hosted git repository. gerben pushed a commit to branch import-dom-seek in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git
commit f15fe3447da6bae21504ad778d5698f2d9839319 Author: Gerben <[email protected]> AuthorDate: Fri Nov 20 13:06:30 2020 +0100 tweak comments --- packages/dom/src/text-quote/describe.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/dom/src/text-quote/describe.ts b/packages/dom/src/text-quote/describe.ts index 81cc4fa..756df1e 100644 --- a/packages/dom/src/text-quote/describe.ts +++ b/packages/dom/src/text-quote/describe.ts @@ -72,19 +72,21 @@ async function abstractDescribeTextQuote<TChunk extends Chunk<string>>( const matches = abstractTextQuoteSelectorMatcher(tentativeSelector)(scope()); let nextMatch = await matches.next(); + // If this match is the intended one, no need to act. // XXX This test is fragile: nextMatch and target are assumed to be normalised. if (!nextMatch.done && chunkRangeEquals(nextMatch.value, target)) { - // This match is the intended one, ignore it. nextMatch = await matches.next(); } // If there are no more unintended matches, our selector is unambiguous! if (nextMatch.done) return tentativeSelector; - // A subsequent search could safely skip the part we already processed, - // we’d need the matcher to start at the seeker’s position, instead of - // searching in the whole current chunk. - // seeker.seekBy(-prefix.length + 1); + // Possible optimisation: A subsequent search could safely skip the part we + // already processed, instead of starting from the beginning again. But we’d + // need the matcher to start at the seeker’s position, instead of searching + // in the whole current chunk. Then we could just seek back to just after + // the start of the prefix: seeker.seekBy(-prefix.length + 1); (don’t forget + // to also correct for any changes in the prefix we will make below) // We’ll have to add more prefix/suffix to disqualify this unintended match. const unintendedMatch = nextMatch.value;
