diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-05-06 19:33:17 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-06 19:33:17 -0400 |
commit | f7df6254d6f71d5331b000dcbd27271bd2c3006f (patch) | |
tree | 99ec2aa66349ba07d4379f31ee3be762235249dd /ext/fg | |
parent | bb2d9501afc0e406b0dacf5675cd90985238be98 (diff) |
Dom text scanner fixes (#505)
* Fix test case
* Add test-dom-text-scanner
* Ensure that DOMTextScanner._node never becomes null
* Add remainder
Diffstat (limited to 'ext/fg')
-rw-r--r-- | ext/fg/js/dom-text-scanner.js | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/ext/fg/js/dom-text-scanner.js b/ext/fg/js/dom-text-scanner.js index 2de65041..8fa67ede 100644 --- a/ext/fg/js/dom-text-scanner.js +++ b/ext/fg/js/dom-text-scanner.js @@ -60,6 +60,15 @@ class DOMTextScanner { } /** + * Gets the remaining number of characters that weren't scanned in the last seek() call. + * This value is usually 0 unless the end of the document was reached. + * @returns An integer. + */ + get remainder() { + return this._remainder; + } + + /** * Gets the accumulated content string resulting from calls to seek(). * @returns A string. */ @@ -85,6 +94,7 @@ class DOMTextScanner { const generateLayoutContent = this._generateLayoutContent; let node = this._node; + let lastNode = node; let resetOffset = this._resetOffset; let newlines = 0; while (node !== null) { @@ -92,6 +102,7 @@ class DOMTextScanner { const nodeType = node.nodeType; if (nodeType === TEXT_NODE) { + lastNode = node; if (!( forward ? this._seekTextNodeForward(node, resetOffset) : @@ -101,6 +112,8 @@ class DOMTextScanner { break; } } else if (nodeType === ELEMENT_NODE) { + lastNode = node; + this._offset = 0; [enterable, newlines] = DOMTextScanner.getElementSeekInfo(node); if (newlines > this._newlines && generateLayoutContent) { this._newlines = newlines; @@ -121,7 +134,7 @@ class DOMTextScanner { resetOffset = true; } - this._node = node; + this._node = lastNode; this._resetOffset = resetOffset; return this; |