aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/bg/js/search.js2
-rw-r--r--ext/bg/js/translator.js23
-rw-r--r--ext/mixed/js/japanese.js8
3 files changed, 25 insertions, 8 deletions
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index 673f066b..ea68915c 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -265,7 +265,7 @@ class DisplaySearch extends Display {
text !== this.clipboardPreviousText
) {
this.clipboardPreviousText = text;
- if (jpIsJapaneseText(text)) {
+ if (jpIsAnyCharacterJapanese(text)) {
this.setQuery(this.isWanakanaEnabled() ? window.wanakana.toKana(text) : text);
window.history.pushState(null, '', `${window.location.pathname}?query=${encodeURIComponent(text)}`);
this.onSearchQueryUpdated(this.query.value, true);
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index d9cb0c54..2fb36194 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -214,11 +214,9 @@ class Translator {
}
async findTermsInternal(text, dictionaries, details, options) {
- if (!options.scanning.alphanumeric && text.length > 0) {
- const c = text[0];
- if (!jpIsKana(c) && !jpIsKanji(c)) {
- return [[], 0];
- }
+ text = Translator.getSearchableText(text, options);
+ if (text.length === 0) {
+ return [[], 0];
}
const titles = Object.keys(dictionaries);
@@ -587,4 +585,19 @@ class Translator {
yield variant;
}
}
+
+ static getSearchableText(text, options) {
+ if (!options.scanning.alphanumeric) {
+ const ii = text.length;
+ for (let i = 0; i < ii; ++i) {
+ const c = text[i];
+ if (!jpIsCharacterJapanese(c)) {
+ text = text.substring(0, i);
+ break;
+ }
+ }
+ }
+
+ return text;
+ }
}
diff --git a/ext/mixed/js/japanese.js b/ext/mixed/js/japanese.js
index 44db4b8c..8d69c180 100644
--- a/ext/mixed/js/japanese.js
+++ b/ext/mixed/js/japanese.js
@@ -92,9 +92,13 @@ function jpIsKana(c) {
);
}
-function jpIsJapaneseText(text) {
+function jpIsCharacterJapanese(c) {
+ return jpIsKanji(c) || jpIsKana(c);
+}
+
+function jpIsAnyCharacterJapanese(text) {
for (const c of text) {
- if (jpIsKanji(c) || jpIsKana(c)) {
+ if (jpIsCharacterJapanese(c)) {
return true;
}
}