Clipboard lookup skip option (#1314)

* Add autoSearchClipboardContent option

* Hide header if there is any search text

* Add setting for autoSearchClipboardContent

* Add support for autoSearchClipboardContent
This commit is contained in:
toasted-nutbread 2021-01-25 22:05:06 -05:00 committed by GitHub
parent ea1d40f94b
commit 981f73b562
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 46 additions and 12 deletions

View File

@ -115,7 +115,8 @@
"maximumClipboardSearchLength", "maximumClipboardSearchLength",
"popupCurrentIndicatorMode", "popupCurrentIndicatorMode",
"popupActionBarVisibility", "popupActionBarVisibility",
"popupActionBarLocation" "popupActionBarLocation",
"autoSearchClipboardContent"
], ],
"properties": { "properties": {
"enable": { "enable": {
@ -286,6 +287,10 @@
"type": "string", "type": "string",
"enum": ["left", "right", "top", "bottom"], "enum": ["left", "right", "top", "bottom"],
"default": "top" "default": "top"
},
"autoSearchClipboardContent": {
"type": "boolean",
"default": true
} }
} }
}, },

View File

@ -668,6 +668,8 @@ class OptionsUtil {
// Added popupWindow. // Added popupWindow.
// Updated handlebars templates to include "stroke-count" definition. // Updated handlebars templates to include "stroke-count" definition.
// Updated global.useSettingsV2 to be true (opt-out). // Updated global.useSettingsV2 to be true (opt-out).
// Added audio.customSourceType.
// Added general.autoSearchClipboardContent.
await this._addFieldTemplatesToOptions(options, '/bg/data/anki-field-templates-upgrade-v8.handlebars'); await this._addFieldTemplatesToOptions(options, '/bg/data/anki-field-templates-upgrade-v8.handlebars');
options.global.useSettingsV2 = true; options.global.useSettingsV2 = true;
for (const profile of options.profiles) { for (const profile of options.profiles) {
@ -727,6 +729,7 @@ class OptionsUtil {
windowState: 'normal' windowState: 'normal'
}; };
profile.options.audio.customSourceType = 'audio'; profile.options.audio.customSourceType = 'audio';
profile.options.general.autoSearchClipboardContent = true;
} }
return options; return options;
} }

View File

@ -130,7 +130,7 @@ class DisplaySearch extends Display {
case 'terms': case 'terms':
case 'kanji': case 'kanji':
animate = !!content.animate; animate = !!content.animate;
valid = content.definitions.length > 0; valid = (typeof source === 'string' && source.length > 0);
this.blurElement(this._queryInput); this.blurElement(this._queryInput);
break; break;
case 'clear': case 'clear':
@ -159,12 +159,12 @@ class DisplaySearch extends Display {
e.preventDefault(); e.preventDefault();
e.stopImmediatePropagation(); e.stopImmediatePropagation();
this.blurElement(e.currentTarget); this.blurElement(e.currentTarget);
this._search(true, true); this._search(true, true, true);
} }
_onSearch(e) { _onSearch(e) {
e.preventDefault(); e.preventDefault();
this._search(true, true); this._search(true, true, true);
} }
_onCopy() { _onCopy() {
@ -173,12 +173,12 @@ class DisplaySearch extends Display {
} }
_onExternalSearchUpdate({text, animate=true}) { _onExternalSearchUpdate({text, animate=true}) {
const {general: {maximumClipboardSearchLength}} = this.getOptions(); const {general: {maximumClipboardSearchLength, autoSearchClipboardContent}} = this.getOptions();
if (text.length > maximumClipboardSearchLength) { if (text.length > maximumClipboardSearchLength) {
text = text.substring(0, maximumClipboardSearchLength); text = text.substring(0, maximumClipboardSearchLength);
} }
this._queryInput.value = text; this._queryInput.value = text;
this._search(animate, false); this._search(animate, false, autoSearchClipboardContent);
} }
_onWanakanaEnableChange(e) { _onWanakanaEnableChange(e) {
@ -323,7 +323,7 @@ class DisplaySearch extends Display {
}); });
} }
_search(animate, history) { _search(animate, history, lookup) {
const query = this._queryInput.value; const query = this._queryInput.value;
const depth = this.depth; const depth = this.depth;
const url = window.location.href; const url = window.location.href;
@ -346,6 +346,7 @@ class DisplaySearch extends Display {
animate animate
} }
}; };
if (!lookup) { details.params.lookup = 'false'; }
this.setContent(details); this.setContent(details);
} }

View File

@ -991,6 +991,29 @@
<input type="number" min="0" step="1" data-setting="general.maximumClipboardSearchLength"> <input type="number" min="0" step="1" data-setting="general.maximumClipboardSearchLength">
</div> </div>
</div></div> </div></div>
<div class="settings-item"><div class="settings-item-inner settings-item-inner-wrappable">
<div class="settings-item-left">
<div class="settings-item-label">Clipboard text search mode</div>
<div class="settings-item-description">Change how the search page reacts to new text in the clipboard.</div>
</div>
<div class="settings-item-right">
<select data-setting="general.autoSearchClipboardContent"
data-transform='[
{
"step": "pre",
"type": "toBoolean"
},
{
"step": "post",
"type": "toString"
}
]'
>
<option value="true">Search for definitions</option>
<option value="false">Update search query only</option>
</select>
</div>
</div></div>
<div class="settings-item"><div class="settings-item-inner settings-item-inner-wrappable"> <div class="settings-item"><div class="settings-item-inner settings-item-inner-wrappable">
<div class="settings-item-left"> <div class="settings-item-left">
<div class="settings-item-label">Size</div> <div class="settings-item-label">Size</div>

View File

@ -558,7 +558,8 @@ class Display extends EventDispatcher {
let queryFull = urlSearchParams.get('full'); let queryFull = urlSearchParams.get('full');
queryFull = (queryFull !== null ? this.postProcessQuery(queryFull) : query); queryFull = (queryFull !== null ? this.postProcessQuery(queryFull) : query);
const wildcardsEnabled = (urlSearchParams.get('wildcards') !== 'off'); const wildcardsEnabled = (urlSearchParams.get('wildcards') !== 'off');
await this._setContentTermsOrKanji(token, isTerms, query, queryFull, wildcardsEnabled, eventArgs); const lookup = (urlSearchParams.get('lookup') !== 'false');
await this._setContentTermsOrKanji(token, isTerms, query, queryFull, lookup, wildcardsEnabled, eventArgs);
} }
break; break;
case 'unloaded': case 'unloaded':
@ -844,7 +845,7 @@ class Display extends EventDispatcher {
} }
} }
async _setContentTermsOrKanji(token, isTerms, query, queryFull, wildcardsEnabled, eventArgs) { async _setContentTermsOrKanji(token, isTerms, query, queryFull, lookup, wildcardsEnabled, eventArgs) {
let {state, content} = this._history; let {state, content} = this._history;
let changeHistory = false; let changeHistory = false;
if (!isObject(content)) { if (!isObject(content)) {
@ -874,7 +875,7 @@ class Display extends EventDispatcher {
let {definitions} = content; let {definitions} = content;
if (!Array.isArray(definitions)) { if (!Array.isArray(definitions)) {
definitions = await this._findDefinitions(isTerms, query, wildcardsEnabled, optionsContext); definitions = lookup ? await this._findDefinitions(isTerms, query, wildcardsEnabled, optionsContext) : [];
if (this._setContentToken !== token) { return; } if (this._setContentToken !== token) { return; }
content.definitions = definitions; content.definitions = definitions;
changeHistory = true; changeHistory = true;
@ -899,7 +900,7 @@ class Display extends EventDispatcher {
this._definitions = definitions; this._definitions = definitions;
this._updateNavigation(this._history.hasPrevious(), this._history.hasNext()); this._updateNavigation(this._history.hasPrevious(), this._history.hasNext());
this._setNoContentVisible(definitions.length === 0); this._setNoContentVisible(definitions.length === 0 && lookup);
const container = this._container; const container = this._container;
container.textContent = ''; container.textContent = '';

View File

@ -296,7 +296,8 @@ function createProfileOptionsUpdatedTestData1() {
maximumClipboardSearchLength: 1000, maximumClipboardSearchLength: 1000,
popupCurrentIndicatorMode: 'triangle', popupCurrentIndicatorMode: 'triangle',
popupActionBarVisibility: 'auto', popupActionBarVisibility: 'auto',
popupActionBarLocation: 'top' popupActionBarLocation: 'top',
autoSearchClipboardContent: true
}, },
audio: { audio: {
enabled: true, enabled: true,