From 5c555e6b4b729bb743306328f0c10ac739a1856c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Wed, 20 Jun 2018 11:02:03 +0200 Subject: [PATCH] Properly parse deselection and improved detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- apps/files/js/filelist.js | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index bcec88765c..0e525f6c7e 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -751,22 +751,41 @@ // Select only visible checkboxes to filter out unmatched file in search this.$fileList.find('td.selection > .selectCheckBox:visible').prop('checked', checked) .closest('tr').toggleClass('selected', checked); - this._selectedFiles = {}; - this._selectionSummary.clear(); - - var selectionIds = []; - this.$fileList.find('td.selection > .selectCheckBox:checked').closest('tr').each(function() { - selectionIds.push($(this).data('id')); - }); if (checked) { for (var i = 0; i < this.files.length; i++) { - if (selectionIds.indexOf(this.files[i].id) >=0 ) { - var fileData = this.files[i]; + // a search will automatically hide the unwanted rows + // let's only select the matches + var fileRow = this.$fileList.find('[data-id=' + i + ']'); + var fileData = this.files[i]; + // do not select already selected ones + if (!fileRow.hasClass('hidden') && _.isUndefined(this._selectedFiles[fileData.id])) { this._selectedFiles[fileData.id] = fileData; this._selectionSummary.add(fileData); } } + } else { + // if we have some hidden row, then we're in a search + // Let's only deselect the visible ones + var hiddenFiles = this.$fileList.find('tr.hidden'); + if (hiddenFiles.length > 0) { + var visibleFiles = this.$fileList.find('tr:not(.hidden)'); + var self = this; + visibleFiles.each(function() { + var id = parseInt($(this).data('id')); + // do not deselect already deselected ones + if (!_.isUndefined(self._selectedFiles[id])) { + // a search will automatically hide the unwanted rows + // let's only select the matches + var fileData = self.files[id]; + delete self._selectedFiles[fileData.id]; + self._selectionSummary.remove(fileData); + } + }); + } else { + this._selectedFiles = {}; + this._selectionSummary.clear(); + } } this.updateSelectionSummary(); if (this._detailsView && !this._detailsView.$el.hasClass('disappear')) {