Skip to content

Commit 1dcc489

Browse files
ktranDevtools-frontend LUCI CQ
authored andcommitted
Fix scrolling into view in Treeoutline
The scrollable container for the Treeoutline has changed, and as a result, the wrong container was used for scrolling when we attempted to scoll an item in the tree into view. This CL changes the way we retrieve the correct scroll container. Instead of using the parent element, we either get the parent element or the shadow host. Fixed: 374592181 Change-Id: Ib3d033b0a4d1c7f7b88e2af63f9bd1f67de452d9 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5961819 Commit-Queue: Kim-Anh Tran <[email protected]> Reviewed-by: Benedikt Meurer <[email protected]>
1 parent 235aa05 commit 1dcc489

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

front_end/ui/legacy/Treeoutline.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,12 @@ export class TreeOutline extends Common.ObjectWrapper.ObjectWrapper<EventTypes>
349349

350350
// Usually, this.element is the tree container that scrolls. But sometimes
351351
// (i.e. in the Elements panel), its parent is.
352-
let scrollParentElement: HTMLElement = this.element;
353-
while (getComputedStyle(scrollParentElement).overflow === 'visible' && scrollParentElement.parentElement) {
354-
scrollParentElement = scrollParentElement.parentElement;
352+
let scrollParentElement: Element = this.element;
353+
while (getComputedStyle(scrollParentElement).overflow === 'visible' &&
354+
scrollParentElement.parentElementOrShadowHost()) {
355+
const parent = scrollParentElement.parentElementOrShadowHost();
356+
Platform.assertNotNullOrUndefined(parent);
357+
scrollParentElement = parent;
355358
}
356359

357360
const viewRect = scrollParentElement.getBoundingClientRect();

test/e2e/sources/navigator-view_test.ts

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44

55
import {assert} from 'chai';
66

7-
import {getBrowserAndPages, waitFor, waitForNone} from '../../shared/helper.js';
8-
7+
import {getBrowserAndPages, waitFor, waitForElementWithTextContent, waitForNone} from '../../shared/helper.js';
98
import {openSoftContextMenuAndClickOnItem} from '../helpers/context-menu-helpers.js';
10-
import {openFileWithQuickOpen, runCommandWithQuickOpen} from '../helpers/quick_open-helpers.js';
119
import {
10+
getMenuItemAtPosition,
11+
openFileQuickOpen,
12+
openFileWithQuickOpen,
13+
runCommandWithQuickOpen,
14+
typeIntoQuickOpen,
15+
} from '../helpers/quick_open-helpers.js';
16+
import {
17+
createNewSnippet,
1218
openFileInSourcesPanel,
1319
openSnippetsSubPane,
1420
openSourceCodeEditorForFile,
@@ -140,5 +146,42 @@ describe('The Sources panel', () => {
140146
await toggleNavigatorSidebar(frontend);
141147
await waitFor('.navigator-tabbed-pane');
142148
});
149+
150+
it('which can scroll the navigator element into view on source file change', async () => {
151+
async function openSnippet(snippet: string) {
152+
await openFileQuickOpen();
153+
await typeIntoQuickOpen(snippet);
154+
const firstItem = await getMenuItemAtPosition(0);
155+
await firstItem.click();
156+
}
157+
158+
async function assertSnippetIsSelected(snippet: string) {
159+
const selectedItem = await waitFor('.navigator-file-tree-item.selected');
160+
const selectedItemName = await selectedItem.evaluate(node => node.textContent);
161+
assert.strictEqual(selectedItemName, snippet);
162+
}
163+
164+
await openSourcesPanel();
165+
await openSnippetsSubPane();
166+
167+
const numSnippets = 50;
168+
for (let i = 0; i < numSnippets; ++i) {
169+
await createNewSnippet(`Snippet${i}`);
170+
}
171+
const firstSnippetName = 'Snippet0';
172+
const lastSnippetName = `Snippet${numSnippets - 1}`;
173+
174+
await waitForElementWithTextContent(lastSnippetName);
175+
await assertSnippetIsSelected(lastSnippetName);
176+
177+
const snippetsPanel = await waitFor('[aria-label="Snippets panel"]');
178+
const scrollTopBeforeFileChange = await snippetsPanel.evaluate(panel => panel.scrollTop);
179+
180+
await openSnippet(firstSnippetName);
181+
await assertSnippetIsSelected(firstSnippetName);
182+
183+
const scrollTopAfterFileChange = await snippetsPanel.evaluate(panel => panel.scrollTop);
184+
assert.notStrictEqual(scrollTopBeforeFileChange, scrollTopAfterFileChange);
185+
});
143186
});
144187
});

0 commit comments

Comments
 (0)