Skip to content

Commit 6b74505

Browse files
committed
Add auto-open toggle for style inspect panel
Introduces an auto-open toggle button to the style inspect panel, allowing users to enable or disable automatic panel opening when selecting elements in inspect mode. The toggle state is reflected in the UI and respected in the editor logic, with supporting callbacks and state management added to the relevant classes.
1 parent 9f8ccd7 commit 6b74505

3 files changed

Lines changed: 138 additions & 5 deletions

File tree

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

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export interface IStyleInspectPanelCallbacks {
4848
onUndoAll?: () => void;
4949
/** Called when user clicks Apply All */
5050
onApplyAll?: () => void;
51+
/** Called when user toggles auto-open mode (pin/unpin) */
52+
onAutoOpenToggle?: () => void;
5153
}
5254

5355
/**
@@ -127,6 +129,10 @@ export class StyleInspectPanel {
127129
// Pending changes data for Changes tab
128130
private pendingMoves: PendingMove[] = [];
129131

132+
// Auto-open toggle state and button
133+
private autoOpenEnabled: boolean = true;
134+
private autoOpenToggleBtn: HTMLButtonElement | null = null;
135+
130136
constructor(
131137
private readonly parent: HTMLElement,
132138
private readonly callbacks: IStyleInspectPanelCallbacks
@@ -314,6 +320,51 @@ export class StyleInspectPanel {
314320
title.textContent = 'Inspect';
315321
header.appendChild(title);
316322

323+
// Right side container for buttons
324+
const buttonsContainer = document.createElement('div');
325+
buttonsContainer.style.cssText = `
326+
display: flex;
327+
align-items: center;
328+
gap: 4px;
329+
`;
330+
331+
// Auto-open toggle button (ON/OFF text toggle)
332+
// When enabled (default): panel auto-opens on element click
333+
// When disabled: panel stays closed on element click (unless already open)
334+
this.autoOpenToggleBtn = document.createElement('button');
335+
this.autoOpenToggleBtn.style.cssText = `
336+
background: none;
337+
border: 1px solid var(--vscode-input-border);
338+
cursor: pointer;
339+
padding: 2px 6px;
340+
display: flex;
341+
align-items: center;
342+
justify-content: center;
343+
transition: all 0.15s;
344+
border-radius: 3px;
345+
font-size: 9px;
346+
font-weight: 600;
347+
text-transform: uppercase;
348+
letter-spacing: 0.5px;
349+
min-width: 32px;
350+
`;
351+
this.updateAutoOpenButtonState();
352+
this.autoOpenToggleBtn.addEventListener('mouseenter', () => {
353+
if (this.autoOpenToggleBtn) {
354+
this.autoOpenToggleBtn.style.borderColor = 'var(--vscode-focusBorder)';
355+
}
356+
});
357+
this.autoOpenToggleBtn.addEventListener('mouseleave', () => {
358+
if (this.autoOpenToggleBtn) {
359+
this.autoOpenToggleBtn.style.borderColor = 'var(--vscode-input-border)';
360+
}
361+
});
362+
this.autoOpenToggleBtn.addEventListener('click', () => {
363+
this.callbacks.onAutoOpenToggle?.();
364+
});
365+
buttonsContainer.appendChild(this.autoOpenToggleBtn);
366+
367+
// Close button
317368
const closeBtn = document.createElement('button');
318369
closeBtn.style.cssText = `
319370
background: none;
@@ -332,11 +383,44 @@ export class StyleInspectPanel {
332383
closeBtn.addEventListener('mouseenter', () => { closeBtn.style.opacity = '1'; });
333384
closeBtn.addEventListener('mouseleave', () => { closeBtn.style.opacity = '0.7'; });
334385
closeBtn.addEventListener('click', () => this.hide());
335-
header.appendChild(closeBtn);
386+
buttonsContainer.appendChild(closeBtn);
387+
388+
header.appendChild(buttonsContainer);
336389

337390
return header;
338391
}
339392

393+
/**
394+
* Update the auto-open toggle button visual state
395+
*/
396+
private updateAutoOpenButtonState(): void {
397+
if (!this.autoOpenToggleBtn) {
398+
return;
399+
}
400+
401+
if (this.autoOpenEnabled) {
402+
// Auto-open is ON
403+
this.autoOpenToggleBtn.textContent = 'ON';
404+
this.autoOpenToggleBtn.title = 'Auto-open ON - panel opens when clicking elements. Click to disable.';
405+
this.autoOpenToggleBtn.style.background = 'var(--vscode-button-background)';
406+
this.autoOpenToggleBtn.style.color = 'var(--vscode-button-foreground)';
407+
} else {
408+
// Auto-open is OFF
409+
this.autoOpenToggleBtn.textContent = 'OFF';
410+
this.autoOpenToggleBtn.title = 'Auto-open OFF - panel won\'t open when clicking elements (unless already open). Click to enable.';
411+
this.autoOpenToggleBtn.style.background = 'transparent';
412+
this.autoOpenToggleBtn.style.color = 'var(--vscode-descriptionForeground)';
413+
}
414+
}
415+
416+
/**
417+
* Set auto-open enabled state (called from styleInspect.ts)
418+
*/
419+
setAutoOpenEnabled(enabled: boolean): void {
420+
this.autoOpenEnabled = enabled;
421+
this.updateAutoOpenButtonState();
422+
}
423+
340424
// ============================================
341425
// Tab Bar
342426
// ============================================

src/vs/workbench/contrib/roopik/browser/projectMode/editor.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,10 @@ export class Editor extends EditorPane {
399399
/**
400400
* Handle element selection from inspect mode
401401
* - Copy HTML to clipboard
402-
* - Open style panel with CSS info
402+
* - Open style panel with CSS info (if auto-open is enabled OR panel already open)
403403
*/
404404
private async handleElementSelected(message: import('../../common/projectMode/types.js').ElementSelectedMessage): Promise<void> {
405-
// Copy HTML to clipboard
405+
// Copy HTML to clipboard (always, regardless of auto-open setting)
406406
if (message.html) {
407407
try {
408408
await this.clipboardService.writeText(message.html);
@@ -413,8 +413,17 @@ export class Editor extends EditorPane {
413413

414414
// Open style panel with element CSS info
415415
if (this.browserViewId && message.selector) {
416-
// Ensure style panel is initialized
417-
if (this.contentContainer && !this.styleInspect.isPanelVisible()) {
416+
const panelAlreadyVisible = this.styleInspect.isPanelVisible();
417+
418+
// If auto-open is disabled AND panel is not already open, skip opening
419+
// But if panel is already open, always load the new element's styles
420+
if (!this.styleInspect.isAutoOpenEnabled() && !panelAlreadyVisible) {
421+
this.logger.info('[InspectMode] Auto-open disabled and panel closed, not opening');
422+
return;
423+
}
424+
425+
// Ensure style panel is initialized (only if not already visible)
426+
if (this.contentContainer && !panelAlreadyVisible) {
418427
this.styleInspect.initialize(this.contentContainer);
419428
}
420429

src/vs/workbench/contrib/roopik/browser/projectMode/features/styleInspect.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ export class StyleInspect {
6464
// Flag to prevent DOM invalidation during style fetching
6565
private isFetchingStyles: boolean = false;
6666

67+
// Flag to control auto-opening of style panel when clicking elements in inspect mode
68+
// When false, clicking an element will NOT auto-open the panel
69+
private autoOpenEnabled: boolean = true;
70+
71+
// Callback for auto-open toggle state changes
72+
private onAutoOpenToggleCallback: ((enabled: boolean) => void) | undefined;
73+
6774
// Callback for tree node selection (to highlight in browser)
6875
private onTreeNodeSelectedCallback: ((nodeId: number) => void) | undefined;
6976

@@ -123,6 +130,33 @@ export class StyleInspect {
123130
this.onApplyAllCallback = callback;
124131
}
125132

133+
/**
134+
* Set callback for when auto-open toggle state changes
135+
*/
136+
setOnAutoOpenToggle(callback: (enabled: boolean) => void): void {
137+
this.onAutoOpenToggleCallback = callback;
138+
}
139+
140+
/**
141+
* Check if auto-open is enabled
142+
* When false, clicking elements in inspect mode won't auto-open the panel
143+
*/
144+
isAutoOpenEnabled(): boolean {
145+
return this.autoOpenEnabled;
146+
}
147+
148+
/**
149+
* Toggle auto-open state
150+
* Called when user clicks the toggle button in the panel header
151+
*/
152+
toggleAutoOpen(): void {
153+
this.autoOpenEnabled = !this.autoOpenEnabled;
154+
// Update panel UI
155+
this.panel?.setAutoOpenEnabled(this.autoOpenEnabled);
156+
// Notify callback (for persistence or other uses)
157+
this.onAutoOpenToggleCallback?.(this.autoOpenEnabled);
158+
}
159+
126160
/**
127161
* Initialize the style panel in a container
128162
*/
@@ -158,10 +192,16 @@ export class StyleInspect {
158192
},
159193
onApplyAll: () => {
160194
this.onApplyAllCallback?.();
195+
},
196+
// Auto-open toggle callback
197+
onAutoOpenToggle: () => {
198+
this.toggleAutoOpen();
161199
}
162200
};
163201

164202
this.panel = new StyleInspectPanel(container, callbacks);
203+
// Initialize panel with current auto-open state
204+
this.panel.setAutoOpenEnabled(this.autoOpenEnabled);
165205
}
166206

167207
/**

0 commit comments

Comments
 (0)