Changeset 237495 in webkit
- Timestamp:
- Oct 27, 2018, 4:30:03 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 7 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/inspector/table/resources/table-utilities.js (modified) (3 diffs)
-
LayoutTests/inspector/table/table-remove-rows-expected.txt (added)
-
LayoutTests/inspector/table/table-remove-rows.html (added)
-
LayoutTests/inspector/unit-tests/index-set-expected.txt (modified) (1 diff)
-
LayoutTests/inspector/unit-tests/index-set.html (modified) (1 diff)
-
Source/WebInspectorUI/ChangeLog (modified) (1 diff)
-
Source/WebInspectorUI/UserInterface/Base/IndexSet.js (modified) (1 diff)
-
Source/WebInspectorUI/UserInterface/Views/Table.js (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r237486 r237495 1 2018-10-27 Matt Baker <mattbaker@apple.com> 2 3 Web Inspector: Table should support deleting rows 4 https://bugs.webkit.org/show_bug.cgi?id=189803 5 <rdar://problem/44655709> 6 7 Reviewed by Devin Rousso. 8 9 * inspector/table/resources/table-utilities.js: 10 (TestPage.registerInitializer.InspectorTest.TableDelegate.prototype.tableDidRemoveRows): 11 (TestPage.registerInitializer.createDataSource): 12 (TestPage.registerInitializer.InspectorTest.createTable): 13 (TestPage.registerInitializer.InspectorTest.createTableWithDelegate): 14 (TestPage.registerInitializer): 15 Update table test utilities to keep TableDataSource backing array in 16 sync when rows are removed. Also allow the number of table rows to be 17 specified when creating a table for testing. 18 19 * inspector/table/table-remove-rows-expected.txt: Added. 20 * inspector/table/table-remove-rows.html: Added. 21 Add tests for new Table methods `removeRow(rowIndex)` and `removeSelectedRows()`. 22 23 * inspector/unit-tests/index-set-expected.txt: 24 * inspector/unit-tests/index-set.html: 25 Add tests for new IndexSet method `copy()`. 26 1 27 2018-10-26 Commit Queue <commit-queue@webkit.org> 2 28 -
trunk/LayoutTests/inspector/table/resources/table-utilities.js
r237155 r237495 22 22 } 23 23 24 tableDidRemoveRows(table, rowIndexes) 25 { 26 // Prevent data source from getting out of sync. 27 for (let index = rowIndexes.length - 1; index >= 0; --index) 28 this.items.splice(index, 1); 29 } 30 24 31 tableSelectionDidChange(table) 25 32 { … … 37 44 }; 38 45 39 function createDataSource( ) {46 function createDataSource(numberOfRows = 10) { 40 47 let items = []; 41 for (let i = 0; i < 10; ++i)48 for (let i = 0; i < numberOfRows; ++i) 42 49 items.push({index: i, name: `Row ${i}`}); 43 50 … … 59 66 } 60 67 61 InspectorTest.createTable = function( ) {62 let dataSource = createDataSource( );68 InspectorTest.createTable = function(numberOfRows) { 69 let dataSource = createDataSource(numberOfRows); 63 70 let delegate = new InspectorTest.TableDelegate(dataSource.items); 64 71 return createTableInternal(dataSource, delegate); 65 72 }; 66 73 67 InspectorTest.createTableWithDelegate = function(delegate ) {74 InspectorTest.createTableWithDelegate = function(delegate, numberOfRows) { 68 75 InspectorTest.assert(delegate instanceof InspectorTest.TableDelegate); 69 76 70 let dataSource = createDataSource( );77 let dataSource = createDataSource(numberOfRows); 71 78 delegate.items = dataSource.items; 72 79 return createTableInternal(dataSource, delegate); -
trunk/LayoutTests/inspector/unit-tests/index-set-expected.txt
r236853 r237495 69 69 PASS: Index less than 3 should be 2. 70 70 71 -- Running test case: IndexSet.prototype.copy 72 PASS: Copy and original should be different objects. 73 PASS: Copy and original should have the same values. 74 -
trunk/LayoutTests/inspector/unit-tests/index-set.html
r236853 r237495 195 195 }); 196 196 197 suite.addTestCase({ 198 name: "IndexSet.prototype.copy", 199 test() { 200 let original = new WI.IndexSet([1, 2, 3]); 201 let copied = original.copy(); 202 InspectorTest.expectNotEqual(copied, original, "Copy and original should be different objects."); 203 InspectorTest.expectShallowEqual(Array.from(copied), Array.from(original), "Copy and original should have the same values."); 204 205 return true; 206 } 207 }); 208 197 209 suite.runTestCasesAndFinish(); 198 210 } -
trunk/Source/WebInspectorUI/ChangeLog
r237482 r237495 1 2018-10-27 Matt Baker <mattbaker@apple.com> 2 3 Web Inspector: Table should support deleting rows 4 https://bugs.webkit.org/show_bug.cgi?id=189803 5 <rdar://problem/44655709> 6 7 Reviewed by Devin Rousso. 8 9 Add methods for removing rows from a Table without reloading the data 10 source. This patch adds Table.prototype.removeRow for removing a single 11 row, and Table.prototype.removeSelectedRows for removing the entire selection. 12 The latter also attempts to select a new row, if possible, before removing 13 the selection. 14 15 * UserInterface/Base/IndexSet.js: 16 (WI.IndexSet.prototype.copy): 17 18 * UserInterface/Views/Table.js: 19 (WI.Table): 20 (WI.Table.prototype.get numberOfRows): 21 Cache the number of rows in the table data source. Invalidate cached 22 value whenever table data is reloaded. Removing rows immediately updates 23 cached value, without incurring a potentially expensive reload. 24 25 (WI.Table.prototype.reloadData): 26 (WI.Table.prototype.selectRow): 27 (WI.Table.prototype.deselectRow): 28 (WI.Table.prototype.removeRow): 29 (WI.Table.prototype.removeSelectedRows): 30 Remove the selected rows and select a new row, if possible. 31 (WI.Table.prototype._updateVisibleRows): 32 (WI.Table.prototype._handleKeyDown): 33 (WI.Table.prototype._deselectAllAndSelect): 34 Drive-by fix: should work when `rowToSelect` isn't already selected. 35 (WI.Table.prototype._removeRows): 36 Remove rows and adjust the indexes of rows that are shifted up as a result 37 of preceding rows being removed. 38 1 39 2018-10-26 Devin Rousso <drousso@apple.com> 2 40 -
trunk/Source/WebInspectorUI/UserInterface/Base/IndexSet.js
r236853 r237495 97 97 } 98 98 99 copy() 100 { 101 let indexSet = new WI.IndexSet; 102 indexSet._indexes = this._indexes.slice(); 103 return indexSet; 104 } 105 99 106 indexGreaterThan(value) 100 107 { -
trunk/Source/WebInspectorUI/UserInterface/Views/Table.js
r237016 r237495 77 77 78 78 this._cachedRows = new Map; 79 this._cachedNumberOfRows = NaN; 79 80 80 81 this._columnSpecs = new Map; … … 133 134 get scrollContainer() { return this._scrollContainerElement; } 134 135 136 get numberOfRows() 137 { 138 if (isNaN(this._cachedNumberOfRows)) 139 this._cachedNumberOfRows = this._dataSource.tableNumberOfRows(this); 140 141 return this._cachedNumberOfRows; 142 } 143 135 144 get sortOrder() 136 145 { … … 242 251 this._selectedRows.clear(); 243 252 253 this._cachedNumberOfRows = NaN; 244 254 this._previousRevealedRowCount = NaN; 245 255 this.needsLayout(); … … 310 320 { 311 321 console.assert(!extendSelection || this._allowsMultipleSelection, "Cannot extend selection with multiple selection disabled."); 322 console.assert(rowIndex >= 0 && rowIndex < this.numberOfRows); 312 323 313 324 if (this._isRowSelected(rowIndex)) { … … 334 345 deselectRow(rowIndex) 335 346 { 347 console.assert(rowIndex >= 0 && rowIndex < this.numberOfRows); 348 336 349 if (!this._isRowSelected(rowIndex)) 337 350 return; … … 374 387 } 375 388 389 removeRow(rowIndex) 390 { 391 console.assert(rowIndex >= 0 && rowIndex < this.numberOfRows); 392 393 if (this._isRowSelected(rowIndex)) 394 this.deselectRow(rowIndex); 395 396 this._removeRows(new WI.IndexSet([rowIndex])); 397 } 398 399 removeSelectedRows() 400 { 401 let numberOfSelectedRows = this._selectedRows.size; 402 if (!numberOfSelectedRows) 403 return; 404 405 // Try selecting the row following the selection. 406 let lastSelectedRow = this._selectedRows.lastIndex; 407 let rowToSelect = lastSelectedRow + 1; 408 if (rowToSelect === this.numberOfRows) { 409 // If no row exists after the last selected row, try selecting a 410 // deselected row (hole) within the selection. 411 let firstSelectedRow = this._selectedRows.firstIndex; 412 if (lastSelectedRow - firstSelectedRow > numberOfSelectedRows) { 413 rowToSelect = this._selectedRows.firstIndex + 1; 414 while (this._selectedRows.has(rowToSelect)) 415 rowToSelect++; 416 } else { 417 // If the selection contains no holes, try selecting the row 418 // preceding the selection. 419 rowToSelect = firstSelectedRow > 0 ? firstSelectedRow - 1 : NaN; 420 } 421 } 422 423 // Change the selection before removing rows. This matches the behavior 424 // of macOS Finder (in list and column modes) when removing selected items. 425 let oldSelectedRows = this._selectedRows.copy(); 426 this._deselectAllAndSelect(rowToSelect); 427 this._removeRows(oldSelectedRows); 428 } 429 376 430 columnWithIdentifier(identifier) 377 431 { … … 791 845 let availableHeight = this._cachedHeight; 792 846 793 let numberOfRows = this. _dataSource.tableNumberOfRows(this);847 let numberOfRows = this.numberOfRows; 794 848 this._cachedNumberOfRows = numberOfRows; 795 849 … … 1012 1066 return; 1013 1067 1014 let numberOfRows = this. _dataSource.tableNumberOfRows(this);1068 let numberOfRows = this.numberOfRows; 1015 1069 this._previousRevealedRowCount = numberOfRows; 1016 1070 … … 1223 1277 return; 1224 1278 1279 let numberOfRows = this.numberOfRows; 1225 1280 let rowToSelect = NaN; 1226 1281 … … 1367 1422 1368 1423 for (let selectedRowIndex of this._selectedRows) { 1369 if (selectedRowIndex === rowIndex)1370 continue;1371 1424 let oldSelectedRow = this._cachedRows.get(selectedRowIndex); 1372 1425 if (oldSelectedRow) … … 1377 1430 this._selectedRows.clear(); 1378 1431 1379 if (!isNaN(rowIndex)) 1432 if (!isNaN(rowIndex)) { 1380 1433 this._selectedRows.add(rowIndex); 1434 let newSelectedRow = this._cachedRows.get(rowIndex); 1435 if (newSelectedRow) 1436 newSelectedRow.classList.add("selected"); 1437 } 1381 1438 1382 1439 this._notifySelectionDidChange(); 1440 } 1441 1442 _removeRows(rowIndexes) 1443 { 1444 let removed = 0; 1445 1446 let adjustRowAtIndex = (index) => { 1447 let newIndex = index - removed; 1448 let row = this._cachedRows.get(index); 1449 if (row) { 1450 this._cachedRows.delete(row.__index); 1451 row.__index = newIndex; 1452 this._cachedRows.set(newIndex, row); 1453 } 1454 1455 if (this._isRowSelected(index)) { 1456 this._selectedRows.delete(index); 1457 this._selectedRows.add(newIndex); 1458 if (this._selectedRowIndex === index) 1459 this._selectedRowIndex = newIndex; 1460 } 1461 }; 1462 1463 if (rowIndexes.has(this._selectedRowIndex)) 1464 this._selectedRowIndex = NaN; 1465 1466 for (let index = rowIndexes.firstIndex; index <= rowIndexes.lastIndex; ++index) { 1467 if (rowIndexes.has(index)) { 1468 let row = this._cachedRows.get(index); 1469 if (row) { 1470 this._cachedRows.delete(index); 1471 row.remove(); 1472 } 1473 removed++; 1474 continue; 1475 } 1476 1477 if (removed) 1478 adjustRowAtIndex(index); 1479 } 1480 1481 if (!removed) 1482 return; 1483 1484 for (let index = rowIndexes.lastIndex + 1; index < this._cachedNumberOfRows; ++index) 1485 adjustRowAtIndex(index); 1486 1487 this._cachedNumberOfRows -= removed; 1488 console.assert(this._cachedNumberOfRows >= 0); 1489 1490 if (this._delegate.tableDidRemoveRows) { 1491 this._delegate.tableDidRemoveRows(this, Array.from(rowIndexes)); 1492 console.assert(this._cachedNumberOfRows === this._dataSource.tableNumberOfRows(this), "Table data source should update after removing rows."); 1493 } 1383 1494 } 1384 1495
Note:
See TracChangeset
for help on using the changeset viewer.