Skip to content

Commit 0d2b6d9

Browse files
committed
Improve style inspector scrolling and layout
1 parent 6b74505 commit 0d2b6d9

1 file changed

Lines changed: 33 additions & 6 deletions

File tree

src/vs/workbench/contrib/roopik/browser/projectMode/components/styleInspectPanel.ts

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ export class StyleInspectPanel {
604604
content.style.cssText = `
605605
flex: 1;
606606
overflow-y: auto;
607-
overflow-x: hidden;
607+
overflow-x: auto;
608608
padding: 8px;
609609
`;
610610

@@ -747,11 +747,37 @@ export class StyleInspectPanel {
747747
private scrollToSelectedNode(nodeId: number): void {
748748
// Use direct reference from map (no querySelector needed)
749749
const selectedElement = this.nodeIdToElement.get(nodeId);
750-
if (selectedElement) {
751-
// Use setTimeout to ensure DOM is fully rendered
752-
setTimeout(() => {
753-
selectedElement.scrollIntoView({ block: 'center', behavior: 'smooth' });
754-
}, 100);
750+
if (selectedElement && this.componentsContent) {
751+
// Use requestAnimationFrame for faster response (no artificial delay)
752+
requestAnimationFrame(() => {
753+
const container = this.componentsContent;
754+
755+
// Get element position relative to container using getBoundingClientRect
756+
const containerRect = container.getBoundingClientRect();
757+
const elementRect = selectedElement.getBoundingClientRect();
758+
759+
// Calculate element's position relative to container's scroll content
760+
const elementTopRelative = elementRect.top - containerRect.top + container.scrollTop;
761+
const elementHeight = elementRect.height;
762+
const containerHeight = container.clientHeight;
763+
764+
// Target: element's center should be at container's vertical center
765+
const targetScrollTop = elementTopRelative - (containerHeight / 2) + (elementHeight / 2);
766+
const clampedScrollTop = Math.max(0, Math.min(targetScrollTop, container.scrollHeight - containerHeight));
767+
768+
// Calculate horizontal scroll to center of viewport
769+
const containerWidth = container.clientWidth;
770+
const scrollWidth = container.scrollWidth;
771+
const centerScrollLeft = (scrollWidth - containerWidth) / 2;
772+
const clampedScrollLeft = Math.max(0, centerScrollLeft);
773+
774+
// Scroll both axes together
775+
container.scrollTo({
776+
top: clampedScrollTop,
777+
left: clampedScrollLeft,
778+
behavior: 'smooth'
779+
});
780+
});
755781
}
756782
}
757783

@@ -1548,6 +1574,7 @@ export class StyleInspectPanel {
15481574
align-items: center;
15491575
padding: 2px 8px 2px ${8 + depth * 16}px;
15501576
cursor: pointer;
1577+
white-space: nowrap;
15511578
${isSelected ? 'background: var(--vscode-list-activeSelectionBackground); color: var(--vscode-list-activeSelectionForeground);' : ''}
15521579
`;
15531580

0 commit comments

Comments
 (0)