Fix empty sentence on some search page URLs (#1919)
This commit is contained in:
parent
3e7f3af63c
commit
ce1a862df4
@ -216,13 +216,14 @@ class DisplayAnki {
|
|||||||
if (typeof url !== 'string') {
|
if (typeof url !== 'string') {
|
||||||
url = window.location.href;
|
url = window.location.href;
|
||||||
}
|
}
|
||||||
sentence = this._getValidSentenceData(sentence);
|
const {query, fullQuery} = this._display;
|
||||||
|
sentence = this._getValidSentenceData(sentence, query);
|
||||||
return {
|
return {
|
||||||
url,
|
url,
|
||||||
sentence,
|
sentence,
|
||||||
documentTitle,
|
documentTitle,
|
||||||
query: this._display.query,
|
query,
|
||||||
fullQuery: this._display.fullQuery
|
fullQuery
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,10 +564,14 @@ class DisplayAnki {
|
|||||||
return isTerms ? ['term-kanji', 'term-kana'] : ['kanji'];
|
return isTerms ? ['term-kanji', 'term-kana'] : ['kanji'];
|
||||||
}
|
}
|
||||||
|
|
||||||
_getValidSentenceData(sentence) {
|
_getValidSentenceData(sentence, fallback) {
|
||||||
let {text, offset} = (isObject(sentence) ? sentence : {});
|
let {text, offset} = (isObject(sentence) ? sentence : {});
|
||||||
if (typeof text !== 'string') { text = ''; }
|
if (typeof text !== 'string') {
|
||||||
|
text = fallback;
|
||||||
|
offset = 0;
|
||||||
|
} else {
|
||||||
if (typeof offset !== 'number') { offset = 0; }
|
if (typeof offset !== 'number') { offset = 0; }
|
||||||
|
}
|
||||||
return {text, offset};
|
return {text, offset};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user