Skip to content

Commit cf172f1

Browse files
danilsomsikovDevtools-frontend LUCI CQ
authored andcommitted
Do not refresh the data grid node on selection
`refresh()` recreates the table cells, which is not only is expensive and unnecessary, but caused focus to be lost. Bug: 394287937 Change-Id: I838451513a2ca2aae6e39c3833d96117155dccd8 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6226109 Auto-Submit: Danil Somsikov <[email protected]> Reviewed-by: Benedikt Meurer <[email protected]> Commit-Queue: Benedikt Meurer <[email protected]>
1 parent fbd90ac commit cf172f1

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

front_end/ui/legacy/components/data_grid/DataGridElement.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,19 @@ class DataGridElement extends HTMLElement {
240240
}
241241
}
242242

243-
#updateNode(node: Node): void {
243+
#updateNode(node: Node, selectionOnly: boolean): void {
244244
const dataRow = node instanceof HTMLElement ? node.closest('tr') : null;
245245
const dataGridNode = dataRow ? DataGridElementNode.get(dataRow) : null;
246246
if (dataGridNode) {
247-
dataGridNode.refresh();
247+
if (selectionOnly) {
248+
if (dataRow?.hasAttribute('selected')) {
249+
dataGridNode.select();
250+
} else {
251+
dataGridNode.deselect();
252+
}
253+
} else {
254+
dataGridNode.refresh();
255+
}
248256
}
249257
}
250258

@@ -256,7 +264,7 @@ class DataGridElement extends HTMLElement {
256264
for (const mutation of mutationList) {
257265
this.#removeNodes(mutation.removedNodes);
258266
this.#addNodes(mutation.addedNodes);
259-
this.#updateNode(mutation.target);
267+
this.#updateNode(mutation.target, mutation.attributeName === 'selected');
260268
}
261269
}
262270

@@ -280,6 +288,9 @@ class DataGridElementNode extends SortableDataGridNode<DataGridElementNode> {
280288
DataGridElementNode.#elementToNode.set(configElement, this);
281289
this.#dataGridElement = dataGridElement;
282290
this.#updateData();
291+
if (this.#configElement.hasAttribute('selected')) {
292+
this.select();
293+
}
283294
}
284295

285296
static get(configElement: Element|undefined): DataGridElementNode|undefined {
@@ -297,9 +308,6 @@ class DataGridElementNode extends SortableDataGridNode<DataGridElementNode> {
297308
const columnId = this.#dataGridElement.columnsOrder[i];
298309
this.data[columnId] = cell.dataset.value ?? cell.textContent ?? '';
299310
}
300-
if (this.#configElement.hasAttribute('selected')) {
301-
this.select();
302-
}
303311
}
304312

305313
override createElement(): HTMLElement {

0 commit comments

Comments
 (0)