Web Inspector: Table with no selection should select the first/last row on down/up...
authormattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Nov 2018 19:41:39 +0000 (19:41 +0000)
committermattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Nov 2018 19:41:39 +0000 (19:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190100
<rdar://problem/44879243>

Reviewed by Devin Rousso.

Pressing the up or down arrow key when nothing is selected should select
the last or first row, respectively. After selecting the row make sure
it is visible by calling the new Table method `revealRow`.

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

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Views/Table.js

index 81083fa..8170af1 100644 (file)
@@ -1,3 +1,20 @@
+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>
+
+        Reviewed by Devin Rousso.
+
+        Pressing the up or down arrow key when nothing is selected should select
+        the last or first row, respectively. After selecting the row make sure
+        it is visible by calling the new Table method `revealRow`.
+
+        * UserInterface/Views/Table.js:
+        (WI.Table.prototype.revealRow):
+        (WI.Table.prototype._handleKeyDown):
+        (WI.Table.prototype._selectRowsFromArrowKey):
+
 2018-11-13  Nikita Vasilyev  <nvasilyev@apple.com>
 
         Web Inspector: Styles: Command-A should select all properties
index 2f024f0..4d74b21 100644 (file)
@@ -435,6 +435,27 @@ WI.Table = class Table extends WI.View
         this._removeRows(oldSelectedRows);
     }
 
+    revealRow(rowIndex)
+    {
+        console.assert(rowIndex >= 0 && rowIndex < this.numberOfRows);
+        if (rowIndex < 0 || rowIndex >= this.numberOfRows)
+            return;
+
+        // Force our own scroll update because we may have scrolled.
+        this._cachedScrollTop = NaN;
+
+        if (this._isRowVisible(rowIndex)) {
+            let row = this._cachedRows.get(rowIndex);
+            console.assert(row, "Visible rows should always be in the cache.");
+            if (row)
+                row.scrollIntoViewIfNeeded(false);
+            this.needsLayout();
+        } else {
+            this._scrollContainerElement.scrollTop = rowIndex * this._rowHeight;
+            this.updateLayout();
+        }
+    }
+
     columnWithIdentifier(identifier)
     {
         return this._columnSpecs.get(identifier);
@@ -1281,22 +1302,13 @@ WI.Table = class Table extends WI.View
         if (!this.numberOfRows)
             return;
 
-        if (!this._isRowVisible(this._selectedRowIndex))
-            return;
-
         if (event.metaKey || event.ctrlKey)
             return;
 
         if (event.keyIdentifier === "Up" || event.keyIdentifier === "Down") {
             this._selectRowsFromArrowKey(event.keyIdentifier === "Up", event.shiftKey);
 
-            let row = this._cachedRows.get(this._selectedRowIndex);
-            console.assert(row, "Moving up or down by one should always find a cached row since it is within the overflow bounds.");
-            row.scrollIntoViewIfNeeded(false);
-
-            // Force our own scroll update because we may have scrolled.
-            this._cachedScrollTop = NaN;
-            this.needsLayout();
+            this.revealRow(this._selectedRowIndex);
 
             event.preventDefault();
             event.stopPropagation();
@@ -1305,6 +1317,12 @@ WI.Table = class Table extends WI.View
 
     _selectRowsFromArrowKey(goingUp, shiftKey)
     {
+        if (!this._selectedRows.size) {
+            let rowIndex = goingUp ? this.numberOfRows - 1 : 0;
+            this.selectRow(rowIndex);
+            return;
+        }
+
         let rowIncrement = goingUp ? -1 : 1;
         let rowIndex = this._selectedRowIndex + rowIncrement;
         if (rowIndex < 0 || rowIndex >= this.numberOfRows)