From 1d2a91523604cce7dd608408da65bea5645fc7d4 Mon Sep 17 00:00:00 2001 From: James Maa Date: Sun, 16 Jun 2024 18:39:44 -0700 Subject: Fix DOMTextScanner entering initial div on backwards seeks (#1071) * Fix dom-text-scanner entering initial div on reverse seeks * Add new case * Add launch.json * Cleanup launch.json --- ext/js/dom/dom-text-scanner.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'ext/js/dom') diff --git a/ext/js/dom/dom-text-scanner.js b/ext/js/dom/dom-text-scanner.js index eb56baf9..5325b894 100644 --- a/ext/js/dom/dom-text-scanner.js +++ b/ext/js/dom/dom-text-scanner.js @@ -36,6 +36,8 @@ export class DOMTextScanner { const resetOffset = (ruby !== null); if (resetOffset) { node = ruby; } + /** @type {Node} */ + this._initialNode = node; /** @type {Node} */ this._node = node; /** @type {number} */ @@ -129,11 +131,16 @@ export class DOMTextScanner { } } else if (nodeType === ELEMENT_NODE) { lastNode = node; + const initialNodeAtBeginningOfNodeGoingBackwards = node === this._initialNode && this._offset === 0 && !forward; + const initialNodeAtEndOfNodeGoingForwards = node === this._initialNode && this._offset === node.childNodes.length && forward; this._offset = 0; ({enterable, newlines} = DOMTextScanner.getElementSeekInfo(/** @type {Element} */ (node))); if (newlines > this._newlines && generateLayoutContent) { this._newlines = newlines; } + if (initialNodeAtBeginningOfNodeGoingBackwards || initialNodeAtEndOfNodeGoingForwards) { + enterable = false; + } } /** @type {Node[]} */ -- cgit v1.2.3