Commit e72f2bbd authored by Drini Cami's avatar Drini Cami Committed by Robert Knight

Feedback from code review

parent 637757fa
...@@ -237,9 +237,10 @@ export function highlightRange( ...@@ -237,9 +237,10 @@ export function highlightRange(
textNodeSpans = textNodeSpans.filter(span => { textNodeSpans = textNodeSpans.filter(span => {
const parentElement = span[0].parentElement; const parentElement = span[0].parentElement;
return ( return (
// Whitespace <span>s should be highlighted since they affect layout // Whitespace <span>s should be highlighted since they affect layout in
// some code editors
(parentElement?.childNodes.length === 1 && (parentElement?.childNodes.length === 1 &&
parentElement?.tagName.match(/^SPAN$/i)) || parentElement?.tagName === 'SPAN') ||
// Otherwise ignore white-space only Text node spans // Otherwise ignore white-space only Text node spans
span.some(node => !whitespace.test(node.data)) span.some(node => !whitespace.test(node.data))
); );
......
...@@ -235,7 +235,7 @@ describe('annotator/highlighter', () => { ...@@ -235,7 +235,7 @@ describe('annotator/highlighter', () => {
assert.equal(result[0].textContent, 'one two'); assert.equal(result[0].textContent, 'one two');
}); });
it('skips non-<span> text node spans which consist only of spaces', () => { it('skips whitespace-only text node spans, except inside <span>s', () => {
const el = document.createElement('div'); const el = document.createElement('div');
el.appendChild(document.createTextNode(' ')); el.appendChild(document.createTextNode(' '));
el.appendChild(document.createTextNode('')); el.appendChild(document.createTextNode(''));
...@@ -249,7 +249,7 @@ describe('annotator/highlighter', () => { ...@@ -249,7 +249,7 @@ describe('annotator/highlighter', () => {
assert.equal(result.length, 0); assert.equal(result.length, 0);
}); });
it('includes whitespace elements if <span> parent', () => { it('wraps whitespace-only text if <span> parent', () => {
// Real-world examples: // Real-world examples:
// - Codeblocks on https://h.readthedocs.io/en/latest/developing/install // - Codeblocks on https://h.readthedocs.io/en/latest/developing/install
// - Text layer on https://archive.org/details/goodytwoshoes00newyiala // - Text layer on https://archive.org/details/goodytwoshoes00newyiala
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment