Skip to content

Commit f3af36f

Browse files
committed
fix comments
1 parent c41abb4 commit f3af36f

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

src/annotator/anchoring/rendered-text.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ function substituteBrs(root: Element): string {
1515
/**
1616
* Return the text within `range` with each `<br>` replaced by a space.
1717
*
18-
* Same as `range.toString()` otherwise — no whitespace collapsing, no
19-
* block-tag handling. The `<br>` → space substitution exists so that
20-
* selections spanning a line break aren't reported as run-together words.
18+
* Unlike block tags (which almost always have whitespace between them in
19+
* the HTML source), `<br>` elements are written inline with no surrounding
20+
* whitespace, so `textContent` produces no separation. Each `<br>` is
21+
* replaced by a space so the quote reflects what the user sees on screen.
2122
*/
2223
export function renderedTextFromRange(range: Range): string {
2324
const container = document.createElement('div');

src/annotator/anchoring/test/html-boundary-test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ describe('annotator/anchoring/html boundary handling', () => {
4242
});
4343

4444
it('describes selection spanning <br> with a space in exact', () => {
45-
// This is the bug the PR fixes: a selection that crosses a `<br>` used
46-
// to produce `exact: "foobar"` because `textContent` doesn't include a
47-
// character for the `<br>`. With the substitution, the stored quote
48-
// reflects what the user actually sees in the rendered page.
45+
// A selection crossing a `<br>` should produce `exact: "foo bar"` (with
46+
// a space), not `"foobar"`, so the stored quote reflects what the user
47+
// sees on the rendered page.
4948
const range = document.createRange();
5049
range.selectNodeContents(container.querySelector('p'));
5150

0 commit comments

Comments
 (0)