Web Inspector: Table should support select all (Cmd-A)
authormattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Nov 2018 20:44:36 +0000 (20:44 +0000)
committermattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Nov 2018 20:44:36 +0000 (20:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190299
<rdar://problem/45029170>

Reviewed by Devin Rousso.

Source/WebInspectorUI:

* UserInterface/Views/Table.js:
(WI.Table.prototype.selectAll):
(WI.Table.prototype._handleKeyDown):

LayoutTests:

* inspector/table/table-selection-expected.txt:
* inspector/table/table-selection.html:
Add tests that `selectAll` works when multiple selection is enabled,
and does nothing when multiple selection is disabled.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@238140 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/inspector/table/table-selection-expected.txt
LayoutTests/inspector/table/table-selection.html
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Views/Table.js

index 82fc5ca..476d1ba 100644 (file)
@@ -1,3 +1,16 @@
+2018-11-13  Matt Baker  <mattbaker@apple.com>
+
+        Web Inspector: Table should support select all (Cmd-A)
+        https://bugs.webkit.org/show_bug.cgi?id=190299
+        <rdar://problem/45029170>
+
+        Reviewed by Devin Rousso.
+
+        * inspector/table/table-selection-expected.txt:
+        * inspector/table/table-selection.html:
+        Add tests that `selectAll` works when multiple selection is enabled,
+        and does nothing when multiple selection is disabled.
+
 2018-11-13  Timothy Hatcher  <timothy@apple.com>
 
         Treat supported-color-schemes as the second highest priority property.
index fd905af..58dccf2 100644 (file)
@@ -74,3 +74,19 @@ Deselecting row 999.
 PASS: Table selection changed.
 PASS: selectedRows should not include 999.
 
+-- Running test case: Table.SelectAll.MultipleSelectionDisabled
+Selecting row 0.
+PASS: Table selection changed.
+PASS: selectedRow should be 0.
+Select all.
+PASS: Should not have selected additional rows.
+PASS: Row 0 should still be selected.
+
+-- Running test case: Table.SelectAll.MultipleSelectionEnabled
+Selecting row 0.
+PASS: Table selection changed.
+PASS: selectedRow should be 0.
+Select all.
+PASS: Table selection changed.
+PASS: Should have selected all rows.
+
index d28fa87..27ae7ba 100644 (file)
@@ -146,6 +146,38 @@ function test()
         }
     });
 
+    suite.addTestCase({
+        name: "Table.SelectAll.MultipleSelectionDisabled",
+        description: "Select all table rows when multiple selection is disabled.",
+        test() {
+            let table = InspectorTest.createTable();
+
+            triggerSelectRow(table, 0);
+            InspectorTest.log("Select all.");
+            table.selectAll();
+            InspectorTest.expectEqual(table.selectedRows.length, 1, "Should not have selected additional rows.");
+            InspectorTest.expectThat(table.isRowSelected(0), "Row 0 should still be selected.");
+
+            return true;
+        }
+    });
+
+    suite.addTestCase({
+        name: "Table.SelectAll.MultipleSelectionEnabled",
+        description: "Select all table rows when multiple selection is enabled.",
+        test() {
+            let table = InspectorTest.createTable();
+            table.allowsMultipleSelection = true;
+
+            triggerSelectRow(table, 0);
+            InspectorTest.log("Select all.");
+            table.selectAll();
+            InspectorTest.expectEqual(table.selectedRows.length, table.numberOfRows, "Should have selected all rows.");
+
+            return true;
+        }
+    });
+
     suite.runTestCasesAndFinish();
 }
 </script>
index 8170af1..2b02d5f 100644 (file)
@@ -1,5 +1,17 @@
 2018-11-13  Matt Baker  <mattbaker@apple.com>
 
+        Web Inspector: Table should support select all (Cmd-A)
+        https://bugs.webkit.org/show_bug.cgi?id=190299
+        <rdar://problem/45029170>
+
+        Reviewed by Devin Rousso.
+
+        * UserInterface/Views/Table.js:
+        (WI.Table.prototype.selectAll):
+        (WI.Table.prototype._handleKeyDown):
+
+2018-11-13  Matt Baker  <mattbaker@apple.com>
+
         Web Inspector: Table with no selection should select the first/last row on down/up arrow key
         https://bugs.webkit.org/show_bug.cgi?id=190100
         <rdar://problem/44879243>
index 4d74b21..2769fed 100644 (file)
@@ -388,6 +388,23 @@ WI.Table = class Table extends WI.View
         this._notifySelectionDidChange();
     }
 
+    selectAll()
+    {
+        if (!this.numberOfRows || !this._allowsMultipleSelection)
+            return;
+
+        if (this._selectedRows.size === this.numberOfRows)
+            return;
+
+        this._selectedRows.addRange(0, this.numberOfRows);
+        this._selectedRowIndex = this._selectedRows.size - 1;
+
+        for (let row of this._cachedRows.values())
+            row.classList.add("selected");
+
+        this._notifySelectionDidChange();
+    }
+
     deselectAll()
     {
         const rowIndex = NaN;
@@ -1302,6 +1319,11 @@ WI.Table = class Table extends WI.View
         if (!this.numberOfRows)
             return;
 
+        if (event.key === "a" && event.commandOrControlKey) {
+            this.selectAll();
+            return;
+        }
+
         if (event.metaKey || event.ctrlKey)
             return;