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 a174e4cfd3baa759e358927df7597e3c92c7358d Author: Gerben <[email protected]> AuthorDate: Fri Nov 20 12:09:15 2020 +0100 Refactor clip range to scope --- packages/dom/src/chunker.ts | 9 +++++++++ packages/dom/src/text-position/describe.ts | 7 ------- packages/dom/src/text-quote/describe.ts | 7 ------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/packages/dom/src/chunker.ts b/packages/dom/src/chunker.ts index bb71857..8c28f78 100644 --- a/packages/dom/src/chunker.ts +++ b/packages/dom/src/chunker.ts @@ -114,6 +114,15 @@ export class TextNodeChunker implements Chunker<PartialTextNode> { } rangeToChunkRange(range: Range): ChunkRange<PartialTextNode> { + range = range.cloneRange(); + + // Take the part of the range that falls within the scope. + if (range.compareBoundaryPoints(Range.START_TO_START, this.scope) === -1) + range.setStart(this.scope.startContainer, this.scope.startOffset); + if (range.compareBoundaryPoints(Range.END_TO_END, this.scope) === 1) + range.setEnd(this.scope.endContainer, this.scope.endOffset); + + // Ensure it starts and ends at text nodes. const textRange = normalizeRange(range, this.scope); const startChunk = this.nodeToChunk(textRange.startContainer); diff --git a/packages/dom/src/text-position/describe.ts b/packages/dom/src/text-position/describe.ts index a711410..d4099a9 100644 --- a/packages/dom/src/text-position/describe.ts +++ b/packages/dom/src/text-position/describe.ts @@ -38,13 +38,6 @@ export async function describeTextPosition( scope.selectNodeContents(document); } - // Take the part of the range that falls within the scope. - range = range.cloneRange(); - if (range.compareBoundaryPoints(Range.START_TO_START, scope) === -1) - range.setStart(scope.startContainer, scope.startOffset); - if (range.compareBoundaryPoints(Range.END_TO_END, scope) === 1) - range.setEnd(scope.endContainer, scope.endOffset); - const textChunks = new TextNodeChunker(scope); if (textChunks.currentChunk === null) throw new RangeError('Range does not contain any Text nodes.'); diff --git a/packages/dom/src/text-quote/describe.ts b/packages/dom/src/text-quote/describe.ts index 2e4693e..688089f 100644 --- a/packages/dom/src/text-quote/describe.ts +++ b/packages/dom/src/text-quote/describe.ts @@ -38,13 +38,6 @@ export async function describeTextQuote( scope.selectNodeContents(document); } - // Take the part of the range that falls within the scope. - range = range.cloneRange(); - if (range.compareBoundaryPoints(Range.START_TO_START, scope) === -1) - range.setStart(scope.startContainer, scope.startOffset); - if (range.compareBoundaryPoints(Range.END_TO_END, scope) === 1) - range.setEnd(scope.endContainer, scope.endOffset); - const chunker = new TextNodeChunker(scope); return await abstractDescribeTextQuote(
