Maximum clipboard search length (#1118)

* Add maximumClipboardSearchLength an option

* Add setting

* Add limits

* Update tests
This commit is contained in:
toasted-nutbread 2020-12-18 11:24:43 -05:00 committed by GitHub
parent bf34905012
commit c728448a4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 3 deletions

View File

@ -108,7 +108,8 @@
"showIframePopupsInRootFrame",
"useSecurePopupFrameUrl",
"usePopupShadowDom",
"usePopupWindow"
"usePopupWindow",
"maximumClipboardSearchLength"
],
"properties": {
"enable": {
@ -259,6 +260,11 @@
"usePopupWindow": {
"type": "boolean",
"default": false
},
"maximumClipboardSearchLength": {
"type": "integer",
"default": 1000,
"minimum": 0
}
}
},

View File

@ -240,6 +240,10 @@ class Backend {
// Event handlers
async _onClipboardTextChange({text}) {
const {general: {maximumClipboardSearchLength}} = this.getOptions({current: true});
if (text.length > maximumClipboardSearchLength) {
text = text.substring(0, maximumClipboardSearchLength);
}
try {
const {tab, created} = await this._getOrCreateSearchPopup();
await this._focusTab(tab);

View File

@ -481,6 +481,10 @@ class OptionsUtil {
{
async: true,
update: this._updateVersion6.bind(this)
},
{
async: false,
update: this._updateVersion7.bind(this)
}
];
}
@ -654,4 +658,13 @@ class OptionsUtil {
templates = templates.replace(/\bcompactGlossaries=((?:\.*\/)*)compactGlossaries\b/g, (g0, g1) => `${g0} data=${g1}.`);
return templates;
}
_updateVersion7(options) {
// Version 7 changes:
// Added general.maximumClipboardSearchLength.
for (const profile of options.profiles) {
profile.options.general.maximumClipboardSearchLength = 1000;
}
return options;
}
}

View File

@ -197,6 +197,10 @@ class DisplaySearch extends Display {
}
_onExternalSearchUpdate({text, animate=true}) {
const {general: {maximumClipboardSearchLength}} = this.getOptions();
if (text.length > maximumClipboardSearchLength) {
text = text.substring(0, maximumClipboardSearchLength);
}
this._queryInput.value = text;
this._search(animate, false);
}

View File

@ -399,6 +399,15 @@
</p>
</div>
</div>
<div class="settings-item advanced-only"><div class="settings-item-inner">
<div class="settings-item-left">
<div class="settings-item-label">Maximum clipboard text search length</div>
<div class="settings-item-description">Limit the number of text characters used when searching clipboard content.</div>
</div>
<div class="settings-item-right">
<input type="number" min="0" step="1" data-setting="general.maximumClipboardSearchLength">
</div>
</div></div>
</div>
<h2 id="popup-appearance">Popup Appearance</h2>

View File

@ -292,7 +292,8 @@ function createProfileOptionsUpdatedTestData1() {
showIframePopupsInRootFrame: false,
useSecurePopupFrameUrl: true,
usePopupShadowDom: true,
usePopupWindow: false
usePopupWindow: false,
maximumClipboardSearchLength: 1000
},
audio: {
enabled: true,
@ -498,7 +499,7 @@ function createOptionsUpdatedTestData1() {
}
],
profileCurrent: 0,
version: 6,
version: 7,
global: {
database: {
prefixWildcardsSupported: false