diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-02-28 14:18:18 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-28 14:18:18 -0500 |
commit | 4806414f957ca324fad7d152ef04e34602a7bdbd (patch) | |
tree | 77e28414d19a5a417a208ea13e1a1d492c2404a3 /ext/js/language/text-scanner.js | |
parent | 6f76645f4cf0005ddb1022406fdf259a5117ce26 (diff) |
Text source element scanning improvements (#1464)
* Add api.textHasJapaneseCharacters
* Add support for empty query
* Add support for showing the query parser for TextSourceElement
with content that does not start with Japanese text
Diffstat (limited to 'ext/js/language/text-scanner.js')
-rw-r--r-- | ext/js/language/text-scanner.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/ext/js/language/text-scanner.js b/ext/js/language/text-scanner.js index 073b1a6c..4994faea 100644 --- a/ext/js/language/text-scanner.js +++ b/ext/js/language/text-scanner.js @@ -17,6 +17,7 @@ /* global * DocumentUtil + * TextSourceElement */ class TextScanner extends EventDispatcher { @@ -321,6 +322,12 @@ class TextScanner extends EventDispatcher { ({definitions, sentence, type} = result); this._inputInfoCurrent = inputInfo; this.setCurrentTextSource(textSource); + } else if (textSource instanceof TextSourceElement && await this._hasJapanese(textSource.fullContent)) { + definitions = []; + sentence = {sentence: '', offset: 0}; + type = 'terms'; + this._inputInfoCurrent = inputInfo; + this.setCurrentTextSource(textSource); } } catch (e) { error = e; @@ -978,4 +985,12 @@ class TextScanner extends EventDispatcher { } } } + + async _hasJapanese(text) { + try { + return await yomichan.api.textHasJapaneseCharacters(text); + } catch (e) { + return false; + } + } } |