Scanning wildcards (#2042)
* Add scanning.matchTypePrefix option * Update TextScanner to use matchTypePrefix option * Add setting * Update warning
This commit is contained in:
parent
851014a404
commit
0e52a1f509
@ -435,7 +435,8 @@
|
|||||||
"enableOnPopupExpressions",
|
"enableOnPopupExpressions",
|
||||||
"enableOnSearchPage",
|
"enableOnSearchPage",
|
||||||
"enableSearchTags",
|
"enableSearchTags",
|
||||||
"layoutAwareScan"
|
"layoutAwareScan",
|
||||||
|
"matchTypePrefix"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
@ -658,6 +659,10 @@
|
|||||||
"layoutAwareScan": {
|
"layoutAwareScan": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
|
},
|
||||||
|
"matchTypePrefix": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -397,6 +397,7 @@ class Frontend {
|
|||||||
pointerEventsEnabled: scanningOptions.pointerEventsEnabled,
|
pointerEventsEnabled: scanningOptions.pointerEventsEnabled,
|
||||||
scanLength: scanningOptions.length,
|
scanLength: scanningOptions.length,
|
||||||
layoutAwareScan: scanningOptions.layoutAwareScan,
|
layoutAwareScan: scanningOptions.layoutAwareScan,
|
||||||
|
matchTypePrefix: scanningOptions.matchTypePrefix,
|
||||||
preventMiddleMouse,
|
preventMiddleMouse,
|
||||||
sentenceParsingOptions
|
sentenceParsingOptions
|
||||||
});
|
});
|
||||||
|
@ -464,7 +464,8 @@ class OptionsUtil {
|
|||||||
{async: true, update: this._updateVersion12.bind(this)},
|
{async: true, update: this._updateVersion12.bind(this)},
|
||||||
{async: true, update: this._updateVersion13.bind(this)},
|
{async: true, update: this._updateVersion13.bind(this)},
|
||||||
{async: false, update: this._updateVersion14.bind(this)},
|
{async: false, update: this._updateVersion14.bind(this)},
|
||||||
{async: false, update: this._updateVersion15.bind(this)}
|
{async: false, update: this._updateVersion15.bind(this)},
|
||||||
|
{async: false, update: this._updateVersion16.bind(this)}
|
||||||
];
|
];
|
||||||
if (typeof targetVersion === 'number' && targetVersion < result.length) {
|
if (typeof targetVersion === 'number' && targetVersion < result.length) {
|
||||||
result.splice(targetVersion);
|
result.splice(targetVersion);
|
||||||
@ -888,4 +889,13 @@ class OptionsUtil {
|
|||||||
}
|
}
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_updateVersion16(options) {
|
||||||
|
// Version 16 changes:
|
||||||
|
// Added scanning.matchTypePrefix.
|
||||||
|
for (const profile of options.profiles) {
|
||||||
|
profile.options.scanning.matchTypePrefix = false;
|
||||||
|
}
|
||||||
|
return options;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -325,6 +325,7 @@ class Display extends EventDispatcher {
|
|||||||
scanLength: scanningOptions.length,
|
scanLength: scanningOptions.length,
|
||||||
layoutAwareScan: scanningOptions.layoutAwareScan,
|
layoutAwareScan: scanningOptions.layoutAwareScan,
|
||||||
preventMiddleMouse: scanningOptions.preventMiddleMouse.onSearchQuery,
|
preventMiddleMouse: scanningOptions.preventMiddleMouse.onSearchQuery,
|
||||||
|
matchTypePrefix: false,
|
||||||
sentenceParsingOptions
|
sentenceParsingOptions
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -61,6 +61,7 @@ class TextScanner extends EventDispatcher {
|
|||||||
this._scanLength = 1;
|
this._scanLength = 1;
|
||||||
this._layoutAwareScan = false;
|
this._layoutAwareScan = false;
|
||||||
this._preventMiddleMouse = false;
|
this._preventMiddleMouse = false;
|
||||||
|
this._matchTypePrefix = false;
|
||||||
this._sentenceScanExtent = 0;
|
this._sentenceScanExtent = 0;
|
||||||
this._sentenceTerminateAtNewlines = true;
|
this._sentenceTerminateAtNewlines = true;
|
||||||
this._sentenceTerminatorMap = new Map();
|
this._sentenceTerminatorMap = new Map();
|
||||||
@ -155,7 +156,8 @@ class TextScanner extends EventDispatcher {
|
|||||||
scanLength,
|
scanLength,
|
||||||
layoutAwareScan,
|
layoutAwareScan,
|
||||||
preventMiddleMouse,
|
preventMiddleMouse,
|
||||||
sentenceParsingOptions
|
sentenceParsingOptions,
|
||||||
|
matchTypePrefix
|
||||||
}) {
|
}) {
|
||||||
if (Array.isArray(inputs)) {
|
if (Array.isArray(inputs)) {
|
||||||
this._inputs = inputs.map(({
|
this._inputs = inputs.map(({
|
||||||
@ -210,6 +212,9 @@ class TextScanner extends EventDispatcher {
|
|||||||
if (typeof preventMiddleMouse === 'boolean') {
|
if (typeof preventMiddleMouse === 'boolean') {
|
||||||
this._preventMiddleMouse = preventMiddleMouse;
|
this._preventMiddleMouse = preventMiddleMouse;
|
||||||
}
|
}
|
||||||
|
if (typeof matchTypePrefix === 'boolean') {
|
||||||
|
this._matchTypePrefix = matchTypePrefix;
|
||||||
|
}
|
||||||
if (typeof sentenceParsingOptions === 'object' && sentenceParsingOptions !== null) {
|
if (typeof sentenceParsingOptions === 'object' && sentenceParsingOptions !== null) {
|
||||||
const {scanExtent, terminationCharacterMode, terminationCharacters} = sentenceParsingOptions;
|
const {scanExtent, terminationCharacterMode, terminationCharacters} = sentenceParsingOptions;
|
||||||
if (typeof scanExtent === 'number') {
|
if (typeof scanExtent === 'number') {
|
||||||
@ -854,7 +859,9 @@ class TextScanner extends EventDispatcher {
|
|||||||
const searchText = this.getTextSourceContent(textSource, scanLength, layoutAwareScan);
|
const searchText = this.getTextSourceContent(textSource, scanLength, layoutAwareScan);
|
||||||
if (searchText.length === 0) { return null; }
|
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; }
|
if (dictionaryEntries.length === 0) { return null; }
|
||||||
|
|
||||||
textSource.setEndOffset(originalTextLength, layoutAwareScan);
|
textSource.setEndOffset(originalTextLength, layoutAwareScan);
|
||||||
|
@ -484,6 +484,32 @@
|
|||||||
<label class="toggle"><input type="checkbox" data-setting="scanning.deepDomScan"><span class="toggle-body"><span class="toggle-track"></span><span class="toggle-knob"></span></span></label>
|
<label class="toggle"><input type="checkbox" data-setting="scanning.deepDomScan"><span class="toggle-body"><span class="toggle-track"></span><span class="toggle-knob"></span></span></label>
|
||||||
</div>
|
</div>
|
||||||
</div></div>
|
</div></div>
|
||||||
|
<div class="settings-item advanced-only">
|
||||||
|
<div class="settings-item-inner">
|
||||||
|
<div class="settings-item-left">
|
||||||
|
<div class="settings-item-label">Wildcard scanning</div>
|
||||||
|
<div class="settings-item-description">
|
||||||
|
Enable suffix wildcard when looking up scanned webpage text.
|
||||||
|
<a tabindex="0" class="more-toggle more-only" data-parent-distance="4">More…</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="settings-item-right">
|
||||||
|
<label class="toggle"><input type="checkbox" data-setting="scanning.matchTypePrefix"><span class="toggle-body"><span class="toggle-track"></span><span class="toggle-knob"></span></span></label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="settings-item-children more" hidden>
|
||||||
|
<p>
|
||||||
|
Rather than searching for the source text exactly, the text will only be required to be a prefix of an existing term.
|
||||||
|
For example, scanning 読み will effectively search for 読み*, which may bring up additional results such as 読み方.
|
||||||
|
</p>
|
||||||
|
<p class="danger-text">
|
||||||
|
This will likely cause scanning and lookup to be slower, and the results may not be as relevant.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<a tabindex="0" class="more-toggle" data-parent-distance="3">Less…</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="settings-item advanced-only"><div class="settings-item-inner settings-item-inner-wrappable">
|
<div class="settings-item advanced-only"><div class="settings-item-inner settings-item-inner-wrappable">
|
||||||
<div class="settings-item-left">
|
<div class="settings-item-left">
|
||||||
<div class="settings-item-label">Text scan length</div>
|
<div class="settings-item-label">Text scan length</div>
|
||||||
|
@ -344,6 +344,7 @@ function createProfileOptionsUpdatedTestData1() {
|
|||||||
layoutAwareScan: false,
|
layoutAwareScan: false,
|
||||||
hideDelay: 0,
|
hideDelay: 0,
|
||||||
pointerEventsEnabled: false,
|
pointerEventsEnabled: false,
|
||||||
|
matchTypePrefix: false,
|
||||||
preventMiddleMouse: {
|
preventMiddleMouse: {
|
||||||
onWebPages: false,
|
onWebPages: false,
|
||||||
onPopupPages: false,
|
onPopupPages: false,
|
||||||
@ -595,7 +596,7 @@ function createOptionsUpdatedTestData1() {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
profileCurrent: 0,
|
profileCurrent: 0,
|
||||||
version: 15,
|
version: 16,
|
||||||
global: {
|
global: {
|
||||||
database: {
|
database: {
|
||||||
prefixWildcardsSupported: false
|
prefixWildcardsSupported: false
|
||||||
|
Loading…
Reference in New Issue
Block a user