Add scan dictionary type filters (#822)
* Add options for searchTerms and searchKanji * Add settings HTML * Add options to TextScanner * Update _search/_findDefinitions to include searchTerms/searchKanji args * Update _searchAtFromMouseMove args * Change argument structure for _searchAt * Use scanning options for searchTerms and searchKanji
This commit is contained in:
parent
b180ebc3bc
commit
621aa354e7
@ -352,7 +352,9 @@
|
|||||||
"showAdvanced": false,
|
"showAdvanced": false,
|
||||||
"scanOnPenHover": true,
|
"scanOnPenHover": true,
|
||||||
"scanOnPenPress": true,
|
"scanOnPenPress": true,
|
||||||
"scanOnPenRelease": false
|
"scanOnPenRelease": false,
|
||||||
|
"searchTerms": true,
|
||||||
|
"searchKanji": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -367,7 +369,9 @@
|
|||||||
"showAdvanced": false,
|
"showAdvanced": false,
|
||||||
"scanOnPenHover": true,
|
"scanOnPenHover": true,
|
||||||
"scanOnPenPress": true,
|
"scanOnPenPress": true,
|
||||||
"scanOnPenRelease": false
|
"scanOnPenRelease": false,
|
||||||
|
"searchTerms": true,
|
||||||
|
"searchKanji": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -415,7 +419,9 @@
|
|||||||
"showAdvanced",
|
"showAdvanced",
|
||||||
"scanOnPenHover",
|
"scanOnPenHover",
|
||||||
"scanOnPenPress",
|
"scanOnPenPress",
|
||||||
"scanOnPenRelease"
|
"scanOnPenRelease",
|
||||||
|
"searchTerms",
|
||||||
|
"searchKanji"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"showAdvanced": {
|
"showAdvanced": {
|
||||||
@ -433,6 +439,14 @@
|
|||||||
"scanOnPenRelease": {
|
"scanOnPenRelease": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
|
},
|
||||||
|
"searchTerms": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
|
"searchKanji": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -522,7 +522,9 @@ class OptionsUtil {
|
|||||||
showAdvanced: false,
|
showAdvanced: false,
|
||||||
scanOnPenHover: true,
|
scanOnPenHover: true,
|
||||||
scanOnPenPress: true,
|
scanOnPenPress: true,
|
||||||
scanOnPenRelease: false
|
scanOnPenRelease: false,
|
||||||
|
searchTerms: true,
|
||||||
|
searchKanji: true
|
||||||
});
|
});
|
||||||
for (const {options: profileOptions} of options.profiles) {
|
for (const {options: profileOptions} of options.profiles) {
|
||||||
profileOptions.general.usePopupWindow = false;
|
profileOptions.general.usePopupWindow = false;
|
||||||
|
@ -101,7 +101,9 @@ class ScanInputsController {
|
|||||||
showAdvanced: false,
|
showAdvanced: false,
|
||||||
scanOnPenHover: true,
|
scanOnPenHover: true,
|
||||||
scanOnPenPress: true,
|
scanOnPenPress: true,
|
||||||
scanOnPenRelease: false
|
scanOnPenRelease: false,
|
||||||
|
searchTerms: true,
|
||||||
|
searchKanji: true
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
}]);
|
}]);
|
||||||
|
@ -472,6 +472,8 @@
|
|||||||
<div class="scan-input-prefix-cell" data-property="options"><div class="scan-input-prefix">Options</div></div>
|
<div class="scan-input-prefix-cell" data-property="options"><div class="scan-input-prefix">Options</div></div>
|
||||||
<div class="scan-input-content-cell" data-property="options"><div class="scan-input-input-cell-inner">
|
<div class="scan-input-content-cell" data-property="options"><div class="scan-input-input-cell-inner">
|
||||||
<div class="scan-input-type-list-container form-control"><div>
|
<div class="scan-input-type-list-container form-control"><div>
|
||||||
|
<div><label class="scan-input-toggle"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.searchTerms"><span>Search for terms</span></label></div>
|
||||||
|
<div><label class="scan-input-toggle"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.searchKanji"><span>Search for kanji</span></label></div>
|
||||||
<div><label class="scan-input-toggle"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.scanOnPenHover"><span>Scan on pen hover</span></label></div>
|
<div><label class="scan-input-toggle"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.scanOnPenHover"><span>Scan on pen hover</span></label></div>
|
||||||
<div><label class="scan-input-toggle"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.scanOnPenPress"><span>Scan on pen press</span></label></div>
|
<div><label class="scan-input-toggle"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.scanOnPenPress"><span>Scan on pen press</span></label></div>
|
||||||
<div><label class="scan-input-toggle"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.scanOnPenRelease"><span>Scan on pen release</span></label></div>
|
<div><label class="scan-input-toggle"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.scanOnPenRelease"><span>Scan on pen release</span></label></div>
|
||||||
|
@ -119,12 +119,12 @@ class TextScanner extends EventDispatcher {
|
|||||||
include,
|
include,
|
||||||
exclude,
|
exclude,
|
||||||
types,
|
types,
|
||||||
options: {scanOnPenHover, scanOnPenPress, scanOnPenRelease}
|
options: {scanOnPenHover, scanOnPenPress, scanOnPenRelease, searchTerms, searchKanji}
|
||||||
}) => ({
|
}) => ({
|
||||||
include: this._getInputArray(include),
|
include: this._getInputArray(include),
|
||||||
exclude: this._getInputArray(exclude),
|
exclude: this._getInputArray(exclude),
|
||||||
types: this._getInputTypeSet(types),
|
types: this._getInputTypeSet(types),
|
||||||
options: {scanOnPenHover, scanOnPenPress, scanOnPenRelease}
|
options: {scanOnPenHover, scanOnPenPress, scanOnPenRelease, searchTerms, searchKanji}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
if (typeof deepContentScan === 'boolean') {
|
if (typeof deepContentScan === 'boolean') {
|
||||||
@ -206,19 +206,19 @@ class TextScanner extends EventDispatcher {
|
|||||||
|
|
||||||
async searchLast() {
|
async searchLast() {
|
||||||
if (this._textSourceCurrent !== null && this._inputCurrent !== null) {
|
if (this._textSourceCurrent !== null && this._inputCurrent !== null) {
|
||||||
await this._search(this._textSourceCurrent, this._inputCurrent);
|
await this._search(this._textSourceCurrent, this._searchTerms, this._searchKanji, this._inputCurrent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async search(textSource) {
|
async search(textSource) {
|
||||||
return await this._search(textSource, {cause: 'script', index: -1, empty: false});
|
return await this._search(textSource, this._searchTerms, this._searchKanji, {cause: 'script', index: -1, empty: false});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
|
||||||
async _search(textSource, input) {
|
async _search(textSource, searchTerms, searchKanji, input) {
|
||||||
let definitions = null;
|
let definitions = null;
|
||||||
let sentence = null;
|
let sentence = null;
|
||||||
let type = null;
|
let type = null;
|
||||||
@ -234,7 +234,7 @@ class TextScanner extends EventDispatcher {
|
|||||||
optionsContext = await this._getOptionsContext();
|
optionsContext = await this._getOptionsContext();
|
||||||
searched = true;
|
searched = true;
|
||||||
|
|
||||||
const result = await this._findDefinitions(textSource, optionsContext);
|
const result = await this._findDefinitions(textSource, searchTerms, searchKanji, optionsContext);
|
||||||
if (result !== null) {
|
if (result !== null) {
|
||||||
({definitions, sentence, type} = result);
|
({definitions, sentence, type} = result);
|
||||||
this._inputCurrent = input;
|
this._inputCurrent = input;
|
||||||
@ -274,8 +274,7 @@ class TextScanner extends EventDispatcher {
|
|||||||
const inputInfo = this._getMatchingInputGroupFromEvent(e, 'mouse');
|
const inputInfo = this._getMatchingInputGroupFromEvent(e, 'mouse');
|
||||||
if (inputInfo === null) { return; }
|
if (inputInfo === null) { return; }
|
||||||
|
|
||||||
const {index, empty} = inputInfo;
|
this._searchAtFromMouseMove(e.clientX, e.clientY, inputInfo);
|
||||||
this._searchAtFromMouseMove(e.clientX, e.clientY, index, empty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_onMouseDown(e) {
|
_onMouseDown(e) {
|
||||||
@ -299,7 +298,7 @@ class TextScanner extends EventDispatcher {
|
|||||||
|
|
||||||
_onClick(e) {
|
_onClick(e) {
|
||||||
if (this._searchOnClick) {
|
if (this._searchOnClick) {
|
||||||
this._searchAt(e.clientX, e.clientY, {type: 'mouse', cause: 'click', index: -1, empty: false});
|
this._searchAt(e.clientX, e.clientY, 'mouse', 'click', {index: -1, empty: false, input: null});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._preventNextClick) {
|
if (this._preventNextClick) {
|
||||||
@ -384,8 +383,7 @@ class TextScanner extends EventDispatcher {
|
|||||||
const inputInfo = this._getMatchingInputGroupFromEvent(e, type);
|
const inputInfo = this._getMatchingInputGroupFromEvent(e, type);
|
||||||
if (inputInfo === null) { return; }
|
if (inputInfo === null) { return; }
|
||||||
|
|
||||||
const {index, empty} = inputInfo;
|
this._searchAt(primaryTouch.clientX, primaryTouch.clientY, type, 'touchMove', inputInfo);
|
||||||
this._searchAt(primaryTouch.clientX, primaryTouch.clientY, {type, cause: 'touchMove', index, empty});
|
|
||||||
|
|
||||||
e.preventDefault(); // Disable scroll
|
e.preventDefault(); // Disable scroll
|
||||||
}
|
}
|
||||||
@ -492,8 +490,7 @@ class TextScanner extends EventDispatcher {
|
|||||||
const inputInfo = this._getMatchingInputGroupFromEvent(e, 'touch');
|
const inputInfo = this._getMatchingInputGroupFromEvent(e, 'touch');
|
||||||
if (inputInfo === null) { return; }
|
if (inputInfo === null) { return; }
|
||||||
|
|
||||||
const {index, empty} = inputInfo;
|
this._searchAt(e.clientX, e.clientY, 'touch', 'touchMove', inputInfo);
|
||||||
this._searchAt(e.clientX, e.clientY, {type: 'touch', cause: 'touchMove', index, empty});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTouchPointerUp() {
|
_onTouchPointerUp() {
|
||||||
@ -638,15 +635,15 @@ class TextScanner extends EventDispatcher {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async _findDefinitions(textSource, optionsContext) {
|
async _findDefinitions(textSource, searchTerms, searchKanji, optionsContext) {
|
||||||
if (textSource === null) {
|
if (textSource === null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (this._searchTerms) {
|
if (searchTerms) {
|
||||||
const results = await this._findTerms(textSource, optionsContext);
|
const results = await this._findTerms(textSource, optionsContext);
|
||||||
if (results !== null) { return results; }
|
if (results !== null) { return results; }
|
||||||
}
|
}
|
||||||
if (this._searchKanji) {
|
if (searchKanji) {
|
||||||
const results = await this._findKanji(textSource, optionsContext);
|
const results = await this._findKanji(textSource, optionsContext);
|
||||||
if (results !== null) { return results; }
|
if (results !== null) { return results; }
|
||||||
}
|
}
|
||||||
@ -684,10 +681,20 @@ class TextScanner extends EventDispatcher {
|
|||||||
return {definitions, sentence, type: 'kanji'};
|
return {definitions, sentence, type: 'kanji'};
|
||||||
}
|
}
|
||||||
|
|
||||||
async _searchAt(x, y, input) {
|
async _searchAt(x, y, type, cause, inputInfo) {
|
||||||
if (this._pendingLookup) { return; }
|
if (this._pendingLookup) { return; }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const {index, empty, input: sourceInput} = inputInfo;
|
||||||
|
let searchTerms = this._searchTerms;
|
||||||
|
let searchKanji = this._searchKanji;
|
||||||
|
if (sourceInput !== null) {
|
||||||
|
if (searchTerms && !sourceInput.options.searchTerms) { searchTerms = false; }
|
||||||
|
if (searchKanji && !sourceInput.options.searchKanji) { searchKanji = false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
const input = {type, cause, index, empty};
|
||||||
|
|
||||||
this._pendingLookup = true;
|
this._pendingLookup = true;
|
||||||
this._scanTimerClear();
|
this._scanTimerClear();
|
||||||
|
|
||||||
@ -697,7 +704,7 @@ class TextScanner extends EventDispatcher {
|
|||||||
|
|
||||||
const textSource = this._documentUtil.getRangeFromPoint(x, y, this._deepContentScan);
|
const textSource = this._documentUtil.getRangeFromPoint(x, y, this._deepContentScan);
|
||||||
try {
|
try {
|
||||||
await this._search(textSource, input);
|
await this._search(textSource, searchTerms, searchKanji, input);
|
||||||
} finally {
|
} finally {
|
||||||
if (textSource !== null) {
|
if (textSource !== null) {
|
||||||
textSource.cleanup();
|
textSource.cleanup();
|
||||||
@ -710,17 +717,17 @@ class TextScanner extends EventDispatcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async _searchAtFromMouseMove(x, y, inputIndex, inputEmpty) {
|
async _searchAtFromMouseMove(x, y, inputInfo) {
|
||||||
if (this._pendingLookup) { return; }
|
if (this._pendingLookup) { return; }
|
||||||
|
|
||||||
if (inputEmpty) {
|
if (inputInfo.empty) {
|
||||||
if (!await this._scanTimerWait()) {
|
if (!await this._scanTimerWait()) {
|
||||||
// Aborted
|
// Aborted
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await this._searchAt(x, y, {type: 'mouse', cause: 'mouseMove', index: inputIndex, empty: inputEmpty});
|
await this._searchAt(x, y, 'mouse', 'mouseMove', inputInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
async _searchAtFromTouchStart(e, x, y) {
|
async _searchAtFromTouchStart(e, x, y) {
|
||||||
@ -731,10 +738,9 @@ class TextScanner extends EventDispatcher {
|
|||||||
const inputInfo = this._getMatchingInputGroupFromEvent(e, type);
|
const inputInfo = this._getMatchingInputGroupFromEvent(e, type);
|
||||||
if (inputInfo === null) { return; }
|
if (inputInfo === null) { return; }
|
||||||
|
|
||||||
const {index, empty} = inputInfo;
|
|
||||||
const textSourceCurrentPrevious = this._textSourceCurrent !== null ? this._textSourceCurrent.clone() : null;
|
const textSourceCurrentPrevious = this._textSourceCurrent !== null ? this._textSourceCurrent.clone() : null;
|
||||||
|
|
||||||
await this._searchAt(x, y, {type, cause, index, empty});
|
await this._searchAt(x, y, type, cause, inputInfo);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this._textSourceCurrent !== null &&
|
this._textSourceCurrent !== null &&
|
||||||
@ -753,7 +759,7 @@ class TextScanner extends EventDispatcher {
|
|||||||
const inputInfo = this._getMatchingInputGroupFromEvent(e, type);
|
const inputInfo = this._getMatchingInputGroupFromEvent(e, type);
|
||||||
if (inputInfo === null) { return; }
|
if (inputInfo === null) { return; }
|
||||||
|
|
||||||
const {index, empty, input: {options}} = inputInfo;
|
const {input: {options}} = inputInfo;
|
||||||
if (
|
if (
|
||||||
(!options.scanOnPenRelease && this._penPointerReleased) ||
|
(!options.scanOnPenRelease && this._penPointerReleased) ||
|
||||||
!(this._penPointerPressed ? options.scanOnPenPress : options.scanOnPenHover)
|
!(this._penPointerPressed ? options.scanOnPenPress : options.scanOnPenHover)
|
||||||
@ -761,7 +767,7 @@ class TextScanner extends EventDispatcher {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this._searchAt(x, y, {type, cause, index, empty});
|
await this._searchAt(x, y, type, cause, inputInfo);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
prevent &&
|
prevent &&
|
||||||
|
Loading…
Reference in New Issue
Block a user