Skip to content

Commit

Permalink
simplify dom text scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
Casheeew committed Dec 28, 2023
1 parent 8d5d215 commit 78a5f00
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions ext/js/dom/dom-text-scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,28 @@ export class DOMTextScanner {
let newlines = 0;
while (node !== null) {
let enterable = false;
const nodeType = node.nodeType;

if (nodeType === TEXT_NODE) {
lastNode = node;
if (!(
forward ?
this._seekTextNodeForward(/** @type {Text} */ (node), resetOffset) :
this._seekTextNodeBackward(/** @type {Text} */ (node), resetOffset)
)) {
// Length reached
let lengthReached = false;
switch (node.nodeType) {
case TEXT_NODE:
if (!(
forward ?
this._seekTextNodeForward(/** @type {Text} */ (node), resetOffset) :
this._seekTextNodeBackward(/** @type {Text} */ (node), resetOffset)
)) {
lengthReached = true;
}
break;
}
} else if (nodeType === ELEMENT_NODE) {
lastNode = node;
this._offset = 0;
({enterable, newlines} = DOMTextScanner.getElementSeekInfo(/** @type {Element} */ (node)));
if (newlines > this._newlines && generateLayoutContent) {
this._newlines = newlines;
}
case ELEMENT_NODE:
lastNode = node;
this._offset = 0;
({enterable, newlines} = DOMTextScanner.getElementSeekInfo(/** @type {Element} */ (node)));
if (newlines > this._newlines && generateLayoutContent) {
this._newlines = newlines;
}
break;
}
if (lengthReached) {
break;
}

/** @type {Node[]} */
Expand Down

0 comments on commit 78a5f00

Please sign in to comment.