Commit 4f9ad082 authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Split type guard into two helper functions

parent fbcd5bf2
......@@ -161,6 +161,10 @@ export function onDocumentReady(
{ pollInterval = 10 }: { pollInterval?: number } = {}
): () => void {
let pollTimer: number | undefined;
// Two linting rules are conflicting here, so muting one of them.
// This should be fixable by refactoring the whole function, as there are
// crossed dependencies between local callbacks, that rely on each other
// having been called in a specific order.
// eslint-disable-next-line prefer-const
let pollForDocumentChange: () => void;
......
......@@ -52,10 +52,12 @@ export function forEachNodeInRange(range: Range, callback: (n: Node) => void) {
}
function nodeIsText(node: Node): node is Text {
return node.nodeType === Node.TEXT_NODE;
}
function textNodeContainsText(textNode: Text): boolean {
const whitespaceOnly = /^\s*$/;
return (
node.nodeType === Node.TEXT_NODE && !node.textContent!.match(whitespaceOnly)
);
return !textNode.textContent!.match(whitespaceOnly);
}
/**
......@@ -66,7 +68,7 @@ function nodeIsText(node: Node): node is Text {
export function getTextBoundingBoxes(range: Range): DOMRect[] {
const textNodes: Text[] = [];
forEachNodeInRange(range, node => {
if (nodeIsText(node)) {
if (nodeIsText(node) && textNodeContainsText(node)) {
textNodes.push(node);
}
});
......
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