Fix setEndOffset (#2214)

* Add _layoutAwareScan option to TextSourceElement.setEndOffset for parity

* Remove default param
This commit is contained in:
toasted-nutbread 2022-08-20 12:38:55 -04:00 committed by GitHub
parent c5c5308ff2
commit cd0a6b60e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 6 deletions

View File

@ -60,7 +60,7 @@ class TextSourceElement {
return this._content; return this._content;
} }
setEndOffset(length, fromEnd=false) { setEndOffset(length, _layoutAwareScan, fromEnd) {
if (fromEnd) { if (fromEnd) {
const delta = Math.min(this._fullContent.length - this._endOffset, length); const delta = Math.min(this._fullContent.length - this._endOffset, length);
this._endOffset += delta; this._endOffset += delta;

View File

@ -66,7 +66,7 @@ class TextSourceRange {
return this._content; return this._content;
} }
setEndOffset(length, layoutAwareScan, fromEnd=false) { setEndOffset(length, layoutAwareScan, fromEnd) {
const state = ( const state = (
fromEnd ? fromEnd ?
new DOMTextScanner(this._range.endContainer, this._range.endOffset, !layoutAwareScan, layoutAwareScan).seek(length) : new DOMTextScanner(this._range.endContainer, this._range.endOffset, !layoutAwareScan, layoutAwareScan).seek(length) :

View File

@ -226,7 +226,7 @@ class TextScanner extends EventDispatcher {
getTextSourceContent(textSource, length, layoutAwareScan) { getTextSourceContent(textSource, length, layoutAwareScan) {
const clonedTextSource = textSource.clone(); const clonedTextSource = textSource.clone();
clonedTextSource.setEndOffset(length, layoutAwareScan); clonedTextSource.setEndOffset(length, layoutAwareScan, false);
const includeSelector = this._includeSelector; const includeSelector = this._includeSelector;
const excludeSelector = this._excludeSelector; const excludeSelector = this._excludeSelector;
@ -872,7 +872,7 @@ class TextScanner extends EventDispatcher {
const {dictionaryEntries, originalTextLength} = await yomichan.api.termsFind(searchText, details, optionsContext); const {dictionaryEntries, originalTextLength} = await yomichan.api.termsFind(searchText, details, optionsContext);
if (dictionaryEntries.length === 0) { return null; } if (dictionaryEntries.length === 0) { return null; }
textSource.setEndOffset(originalTextLength, layoutAwareScan); textSource.setEndOffset(originalTextLength, layoutAwareScan, false);
const sentence = this._documentUtil.extractSentence( const sentence = this._documentUtil.extractSentence(
textSource, textSource,
layoutAwareScan, layoutAwareScan,
@ -899,7 +899,7 @@ class TextScanner extends EventDispatcher {
const dictionaryEntries = await yomichan.api.kanjiFind(searchText, optionsContext); const dictionaryEntries = await yomichan.api.kanjiFind(searchText, optionsContext);
if (dictionaryEntries.length === 0) { return null; } if (dictionaryEntries.length === 0) { return null; }
textSource.setEndOffset(1, layoutAwareScan); textSource.setEndOffset(1, layoutAwareScan, false);
const sentence = this._documentUtil.extractSentence( const sentence = this._documentUtil.extractSentence(
textSource, textSource,
layoutAwareScan, layoutAwareScan,
@ -1121,7 +1121,7 @@ class TextScanner extends EventDispatcher {
(excludeSelector !== null && DocumentUtil.anyNodeMatchesSelector(nodes, excludeSelector)) (excludeSelector !== null && DocumentUtil.anyNodeMatchesSelector(nodes, excludeSelector))
) { ) {
--length; --length;
textSource.setEndOffset(length, layoutAwareScan); textSource.setEndOffset(length, layoutAwareScan, false);
} else { } else {
break; break;
} }