Add a small delay before processing the key input of search boxes

PR #20465.
Closes #20025.
Closes #20235.
This commit is contained in:
Chocobo1
2024-02-27 12:57:55 +08:00
committed by GitHub
parent 46e8ee50c8
commit 15697f904d
14 changed files with 87 additions and 50 deletions

View File

@@ -695,6 +695,8 @@ window.addEventListener("DOMContentLoaded", function() {
$('error_div').set('html', '');
if (response) {
clearTimeout(torrentsFilterInputTimer);
torrentsFilterInputTimer = -1;
let torrentsTableSelectedRows;
let update_categories = false;
let updateTags = false;
@@ -1449,18 +1451,14 @@ window.addEventListener("DOMContentLoaded", function() {
$('torrentFilesFilterToolbar').addClass("invisible");
};
let prevTorrentsFilterValue;
let torrentsFilterInputTimer = null;
// listen for changes to torrentsFilterInput
$('torrentsFilterInput').addEvent('input', function() {
const value = $('torrentsFilterInput').get("value");
if (value !== prevTorrentsFilterValue) {
prevTorrentsFilterValue = value;
clearTimeout(torrentsFilterInputTimer);
torrentsFilterInputTimer = setTimeout(function() {
torrentsTable.updateTable(false);
}, 400);
}
let torrentsFilterInputTimer = -1;
$('torrentsFilterInput').addEvent('input', () => {
clearTimeout(torrentsFilterInputTimer);
torrentsFilterInputTimer = setTimeout(() => {
torrentsFilterInputTimer = -1;
torrentsTable.updateTable();
}, window.qBittorrent.Misc.FILTER_INPUT_DELAY);
});
$('transfersTabLink').addEvent('click', showTransfersTab);

View File

@@ -175,12 +175,14 @@ window.qBittorrent.ContextMenu = (function() {
const touchstartEvent = e;
this.touchstartTimer = setTimeout(function() {
this.touchstartTimer = -1;
this.triggerMenu(touchstartEvent, elem);
}.bind(this), this.options.touchTimer);
}.bind(this));
elem.addEvent('touchend', function(e) {
e.preventDefault();
clearTimeout(this.touchstartTimer);
this.touchstartTimer = -1;
}.bind(this));
},

View File

@@ -701,10 +701,7 @@ window.qBittorrent.DynamicTable = (function() {
return null;
},
updateTable: function(fullUpdate) {
if (fullUpdate === undefined)
fullUpdate = false;
updateTable: function(fullUpdate = false) {
const rows = this.getFilteredAndSortedRows();
for (let i = 0; i < this.selectedRows.length; ++i)

View File

@@ -47,6 +47,8 @@ window.qBittorrent.Misc = (function() {
toFixedPointString: toFixedPointString,
containsAllTerms: containsAllTerms,
sleep: sleep,
// variables
FILTER_INPUT_DELAY: 400,
MAX_ETA: 8640000
};
};

View File

@@ -366,6 +366,7 @@ window.qBittorrent.PropFiles = (function() {
},
onSuccess: function(files) {
clearTimeout(torrentFilesFilterInputTimer);
torrentFilesFilterInputTimer = -1;
if (files.length === 0) {
torrentFilesTable.clear();
@@ -640,26 +641,27 @@ window.qBittorrent.PropFiles = (function() {
if (torrentFilesTable.getSortedColumn() === null)
torrentFilesTable.setSortedColumn('name');
let prevTorrentFilesFilterValue;
let torrentFilesFilterInputTimer = null;
// listen for changes to torrentFilesFilterInput
$('torrentFilesFilterInput').addEvent('input', function() {
const value = $('torrentFilesFilterInput').get("value");
if (value !== prevTorrentFilesFilterValue) {
prevTorrentFilesFilterValue = value;
torrentFilesTable.setFilter(value);
clearTimeout(torrentFilesFilterInputTimer);
torrentFilesFilterInputTimer = setTimeout(function() {
if (current_hash === "")
return;
torrentFilesTable.updateTable(false);
let torrentFilesFilterInputTimer = -1;
$('torrentFilesFilterInput').addEvent('input', () => {
clearTimeout(torrentFilesFilterInputTimer);
if (value.trim() === "")
collapseAllNodes();
else
expandAllNodes();
}, 400);
}
const value = $('torrentFilesFilterInput').get("value");
torrentFilesTable.setFilter(value);
torrentFilesFilterInputTimer = setTimeout(() => {
torrentFilesFilterInputTimer = -1;
if (current_hash === "")
return;
torrentFilesTable.updateTable();
if (value.trim() === "")
collapseAllNodes();
else
expandAllNodes();
}, window.qBittorrent.Misc.FILTER_INPUT_DELAY);
});
/**