From cd0a6b60e2f910e497a5b72bee1a27a0d1c575d2 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 20 Aug 2022 12:38:55 -0400 Subject: [PATCH] Fix setEndOffset (#2214) * Add _layoutAwareScan option to TextSourceElement.setEndOffset for parity * Remove default param --- ext/js/dom/text-source-element.js | 2 +- ext/js/dom/text-source-range.js | 2 +- ext/js/language/text-scanner.js | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ext/js/dom/text-source-element.js b/ext/js/dom/text-source-element.js index 264a913e..257b9df4 100644 --- a/ext/js/dom/text-source-element.js +++ b/ext/js/dom/text-source-element.js @@ -60,7 +60,7 @@ class TextSourceElement { return this._content; } - setEndOffset(length, fromEnd=false) { + setEndOffset(length, _layoutAwareScan, fromEnd) { if (fromEnd) { const delta = Math.min(this._fullContent.length - this._endOffset, length); this._endOffset += delta; diff --git a/ext/js/dom/text-source-range.js b/ext/js/dom/text-source-range.js index e0e2c5b0..5e3e814c 100644 --- a/ext/js/dom/text-source-range.js +++ b/ext/js/dom/text-source-range.js @@ -66,7 +66,7 @@ class TextSourceRange { return this._content; } - setEndOffset(length, layoutAwareScan, fromEnd=false) { + setEndOffset(length, layoutAwareScan, fromEnd) { const state = ( fromEnd ? new DOMTextScanner(this._range.endContainer, this._range.endOffset, !layoutAwareScan, layoutAwareScan).seek(length) : diff --git a/ext/js/language/text-scanner.js b/ext/js/language/text-scanner.js index 1ef92115..93de4dd4 100644 --- a/ext/js/language/text-scanner.js +++ b/ext/js/language/text-scanner.js @@ -226,7 +226,7 @@ class TextScanner extends EventDispatcher { getTextSourceContent(textSource, length, layoutAwareScan) { const clonedTextSource = textSource.clone(); - clonedTextSource.setEndOffset(length, layoutAwareScan); + clonedTextSource.setEndOffset(length, layoutAwareScan, false); const includeSelector = this._includeSelector; const excludeSelector = this._excludeSelector; @@ -872,7 +872,7 @@ class TextScanner extends EventDispatcher { const {dictionaryEntries, originalTextLength} = await yomichan.api.termsFind(searchText, details, optionsContext); if (dictionaryEntries.length === 0) { return null; } - textSource.setEndOffset(originalTextLength, layoutAwareScan); + textSource.setEndOffset(originalTextLength, layoutAwareScan, false); const sentence = this._documentUtil.extractSentence( textSource, layoutAwareScan, @@ -899,7 +899,7 @@ class TextScanner extends EventDispatcher { const dictionaryEntries = await yomichan.api.kanjiFind(searchText, optionsContext); if (dictionaryEntries.length === 0) { return null; } - textSource.setEndOffset(1, layoutAwareScan); + textSource.setEndOffset(1, layoutAwareScan, false); const sentence = this._documentUtil.extractSentence( textSource, layoutAwareScan, @@ -1121,7 +1121,7 @@ class TextScanner extends EventDispatcher { (excludeSelector !== null && DocumentUtil.anyNodeMatchesSelector(nodes, excludeSelector)) ) { --length; - textSource.setEndOffset(length, layoutAwareScan); + textSource.setEndOffset(length, layoutAwareScan, false); } else { break; }