summaryrefslogtreecommitdiff
path: root/ext/js/language/text-scanner.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-12-18 12:38:39 -0500
committerGitHub <noreply@github.com>2021-12-18 12:38:39 -0500
commit0e52a1f509155673d26a2a1ad00987389a05fea6 (patch)
tree726344c15a28e6d7a43be6df34fbe201d6fee018 /ext/js/language/text-scanner.js
parent851014a404c6db2b07699382726fd10d028f4828 (diff)
Scanning wildcards (#2042)
* Add scanning.matchTypePrefix option * Update TextScanner to use matchTypePrefix option * Add setting * Update warning
Diffstat (limited to 'ext/js/language/text-scanner.js')
-rw-r--r--ext/js/language/text-scanner.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/ext/js/language/text-scanner.js b/ext/js/language/text-scanner.js
index 5d37c84b..cdcec257 100644
--- a/ext/js/language/text-scanner.js
+++ b/ext/js/language/text-scanner.js
@@ -61,6 +61,7 @@ class TextScanner extends EventDispatcher {
this._scanLength = 1;
this._layoutAwareScan = false;
this._preventMiddleMouse = false;
+ this._matchTypePrefix = false;
this._sentenceScanExtent = 0;
this._sentenceTerminateAtNewlines = true;
this._sentenceTerminatorMap = new Map();
@@ -155,7 +156,8 @@ class TextScanner extends EventDispatcher {
scanLength,
layoutAwareScan,
preventMiddleMouse,
- sentenceParsingOptions
+ sentenceParsingOptions,
+ matchTypePrefix
}) {
if (Array.isArray(inputs)) {
this._inputs = inputs.map(({
@@ -210,6 +212,9 @@ class TextScanner extends EventDispatcher {
if (typeof preventMiddleMouse === 'boolean') {
this._preventMiddleMouse = preventMiddleMouse;
}
+ if (typeof matchTypePrefix === 'boolean') {
+ this._matchTypePrefix = matchTypePrefix;
+ }
if (typeof sentenceParsingOptions === 'object' && sentenceParsingOptions !== null) {
const {scanExtent, terminationCharacterMode, terminationCharacters} = sentenceParsingOptions;
if (typeof scanExtent === 'number') {
@@ -854,7 +859,9 @@ class TextScanner extends EventDispatcher {
const searchText = this.getTextSourceContent(textSource, scanLength, layoutAwareScan);
if (searchText.length === 0) { return null; }
- const {dictionaryEntries, originalTextLength} = await yomichan.api.termsFind(searchText, {}, optionsContext);
+ const details = {};
+ if (this._matchTypePrefix) { details.matchType = 'prefix'; }
+ const {dictionaryEntries, originalTextLength} = await yomichan.api.termsFind(searchText, details, optionsContext);
if (dictionaryEntries.length === 0) { return null; }
textSource.setEndOffset(originalTextLength, layoutAwareScan);