add option to automatically hide search results (fixes #71)
This commit is contained in:
parent
5a53154123
commit
9280985306
@ -146,6 +146,7 @@ function optionsSetDefaults(options) {
|
|||||||
middleMouse: true,
|
middleMouse: true,
|
||||||
selectText: true,
|
selectText: true,
|
||||||
alphanumeric: true,
|
alphanumeric: true,
|
||||||
|
autoHideResults: false,
|
||||||
delay: 15,
|
delay: 15,
|
||||||
length: 10,
|
length: 10,
|
||||||
modifier: 'shift'
|
modifier: 'shift'
|
||||||
|
@ -35,6 +35,7 @@ async function formRead() {
|
|||||||
optionsNew.scanning.middleMouse = $('#middle-mouse-button-scan').prop('checked');
|
optionsNew.scanning.middleMouse = $('#middle-mouse-button-scan').prop('checked');
|
||||||
optionsNew.scanning.selectText = $('#select-matched-text').prop('checked');
|
optionsNew.scanning.selectText = $('#select-matched-text').prop('checked');
|
||||||
optionsNew.scanning.alphanumeric = $('#search-alphanumeric').prop('checked');
|
optionsNew.scanning.alphanumeric = $('#search-alphanumeric').prop('checked');
|
||||||
|
optionsNew.scanning.autoHideResults = $('#auto-hide-results').prop('checked');
|
||||||
optionsNew.scanning.delay = parseInt($('#scan-delay').val(), 10);
|
optionsNew.scanning.delay = parseInt($('#scan-delay').val(), 10);
|
||||||
optionsNew.scanning.length = parseInt($('#scan-length').val(), 10);
|
optionsNew.scanning.length = parseInt($('#scan-length').val(), 10);
|
||||||
optionsNew.scanning.modifier = $('#scan-modifier-key').val();
|
optionsNew.scanning.modifier = $('#scan-modifier-key').val();
|
||||||
@ -136,6 +137,7 @@ async function onReady() {
|
|||||||
$('#middle-mouse-button-scan').prop('checked', options.scanning.middleMouse);
|
$('#middle-mouse-button-scan').prop('checked', options.scanning.middleMouse);
|
||||||
$('#select-matched-text').prop('checked', options.scanning.selectText);
|
$('#select-matched-text').prop('checked', options.scanning.selectText);
|
||||||
$('#search-alphanumeric').prop('checked', options.scanning.alphanumeric);
|
$('#search-alphanumeric').prop('checked', options.scanning.alphanumeric);
|
||||||
|
$('#auto-hide-results').prop('checked', options.scanning.autoHideResults);
|
||||||
$('#scan-delay').val(options.scanning.delay);
|
$('#scan-delay').val(options.scanning.delay);
|
||||||
$('#scan-length').val(options.scanning.length);
|
$('#scan-length').val(options.scanning.length);
|
||||||
$('#scan-modifier-key').val(options.scanning.modifier);
|
$('#scan-modifier-key').val(options.scanning.modifier);
|
||||||
|
@ -96,6 +96,10 @@
|
|||||||
<label><input type="checkbox" id="search-alphanumeric"> Search alphanumeric text</label>
|
<label><input type="checkbox" id="search-alphanumeric"> Search alphanumeric text</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="checkbox">
|
||||||
|
<label><input type="checkbox" id="auto-hide-results"> Automatically hide results</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group options-advanced">
|
<div class="form-group options-advanced">
|
||||||
<label for="scan-delay">Scan delay (in milliseconds)</label>
|
<label for="scan-delay">Scan delay (in milliseconds)</label>
|
||||||
<input type="number" min="1" id="scan-delay" class="form-control">
|
<input type="number" min="1" id="scan-delay" class="form-control">
|
||||||
|
@ -169,27 +169,21 @@ class Frontend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async searchAt(point) {
|
async searchAt(point) {
|
||||||
let textSource = null;
|
const textSource = docRangeFromPoint(point);
|
||||||
|
let hideResults = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (this.pendingLookup) {
|
if (this.pendingLookup) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
textSource = docRangeFromPoint(point);
|
|
||||||
if (!textSource || !textSource.containsPoint(point)) {
|
|
||||||
docImposterDestroy();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.textSourceLast && this.textSourceLast.equals(textSource)) {
|
if (this.textSourceLast && this.textSourceLast.equals(textSource)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.pendingLookup = true;
|
if (textSource && textSource.containsPoint(point)) {
|
||||||
|
this.pendingLookup = true;
|
||||||
if (!await this.searchTerms(textSource)) {
|
hideResults = !await this.searchTerms(textSource) && !await this.searchKanji(textSource);
|
||||||
await this.searchKanji(textSource);
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (window.yomichan_orphaned) {
|
if (window.yomichan_orphaned) {
|
||||||
@ -201,6 +195,11 @@ class Frontend {
|
|||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
docImposterDestroy();
|
docImposterDestroy();
|
||||||
|
|
||||||
|
if (hideResults && this.options.scanning.autoHideResults) {
|
||||||
|
this.popup.hide();
|
||||||
|
}
|
||||||
|
|
||||||
this.pendingLookup = false;
|
this.pendingLookup = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ class TextSourceRange {
|
|||||||
}
|
}
|
||||||
|
|
||||||
equals(other) {
|
equals(other) {
|
||||||
return other.range && other.range.compareBoundaryPoints(Range.START_TO_START, this.range) === 0;
|
return other && other.range && other.range.compareBoundaryPoints(Range.START_TO_START, this.range) === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static shouldEnter(node) {
|
static shouldEnter(node) {
|
||||||
@ -239,6 +239,6 @@ class TextSourceElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
equals(other) {
|
equals(other) {
|
||||||
return other.element === this.element && other.content === this.content;
|
return other && other.element === this.element && other.content === this.content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user