Skip to content

Commit 8650f63

Browse files
committed
PR feedback
1 parent c196182 commit 8650f63

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

src/vs/platform/browserElements/common/browserElements.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ export interface INativeBrowserElementsService {
4949
}
5050

5151
/**
52-
* Extract a display name from outer HTML (e.g., "div#myId.myClass")
52+
* Extract a display name from outer HTML (e.g., "div#myId.myClass1.myClass2")
5353
*/
5454
export function getDisplayNameFromOuterHTML(outerHTML: string): string {
55-
const firstElementMatch = outerHTML.match(/^<(\w+)([^>]*?)>/);
55+
const firstElementMatch = outerHTML.match(/^<([^ >]+)([^>]*?)>/);
5656
if (!firstElementMatch) {
5757
throw new Error('No outer element found');
5858
}

src/vs/platform/browserElements/electron-main/nativeBrowserElementsMainService.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ export class NativeBrowserElementsMainService extends Disposable implements INat
406406
});
407407
}
408408

409-
formatMatchedStyles(matched: { inlineStyle?: { cssProperties?: Array<{ name: string; value: string }> }; matchedCSSRules?: Array<{ rule: { selectorList: { selectors: Array<{ text: string }> }; origin: string; style: { cssProperties: Array<{ name: string; value: string }> } } }>; inherited?: Array<{ matchedCSSRules?: Array<{ rule: { selectorList: { selectors: Array<{ text: string }> }; origin: string; style: { cssProperties: Array<{ name: string; value: string }> } } }> }> }): string {
409+
formatMatchedStyles(matched: { inlineStyle?: { cssProperties?: Array<{ name: string; value: string }> }; matchedCSSRules?: Array<{ rule: { selectorList: { selectors: Array<{ text: string }> }; origin: string; style: { cssProperties: Array<{ name: string; value: string }> } } }>; inherited?: Array<{ inlineStyle?: { cssText: string }; matchedCSSRules?: Array<{ rule: { selectorList: { selectors: Array<{ text: string }> }; origin: string; style: { cssProperties: Array<{ name: string; value: string }> } } }> }> }): string {
410410
const lines: string[] = [];
411411

412412
// inline
@@ -441,6 +441,14 @@ export class NativeBrowserElementsMainService extends Disposable implements INat
441441
if (matched.inherited?.length) {
442442
let level = 1;
443443
for (const inherited of matched.inherited) {
444+
const inline = inherited.inlineStyle;
445+
if (inline) {
446+
lines.push(`/* Inherited from ancestor level ${level} (inline) */`);
447+
lines.push('element {');
448+
lines.push(inline.cssText);
449+
lines.push('}\n');
450+
}
451+
444452
const rules = inherited.matchedCSSRules || [];
445453
for (const ruleEntry of rules) {
446454
const rule = ruleEntry.rule;

src/vs/workbench/contrib/browserView/electron-browser/browserEditor.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,9 @@ export class BrowserEditor extends EditorPane {
462462
}
463463

464464
/**
465-
* Select an element and add it to chat
465+
* Start element selection in the browser view, wait for a user selection, and add it to chat.
466466
*/
467-
public async selectElement(): Promise<void> {
467+
async addElementToChat(): Promise<void> {
468468
// If selection is already active, cancel it
469469
if (this._elementSelectionCts) {
470470
this._elementSelectionCts.dispose(true);
@@ -495,7 +495,7 @@ export class BrowserEditor extends EditorPane {
495495
// Get the browser container bounds
496496
const { width, height } = this._browserContainer.getBoundingClientRect();
497497

498-
// Get element data from browser
498+
// Get element data from user selection
499499
const elementData = await this.browserElementsService.getElementData({ x: 0, y: 0, width, height }, cts.token, locator);
500500
if (!elementData) {
501501
throw new Error('Element data not found');
@@ -506,8 +506,9 @@ export class BrowserEditor extends EditorPane {
506506

507507
// Prepare HTML/CSS context
508508
const displayName = getDisplayNameFromOuterHTML(elementData.outerHTML);
509-
let value = 'Attached HTML and CSS Context\n\n' + elementData.outerHTML;
510-
if (this.configurationService.getValue('chat.sendElementsToChat.attachCSS')) {
509+
const attachCss = this.configurationService.getValue<boolean>('chat.sendElementsToChat.attachCSS');
510+
let value = (attachCss ? 'Attached HTML and CSS Context' : 'Attached HTML Context') + '\n\n' + elementData.outerHTML;
511+
if (attachCss) {
511512
value += '\n\n' + elementData.computedStyle;
512513
}
513514

@@ -542,7 +543,7 @@ export class BrowserEditor extends EditorPane {
542543

543544
} catch (error) {
544545
if (!cts.token.isCancellationRequested) {
545-
this.logService.error('BrowserEditor.selectElement: Failed to select element', error);
546+
this.logService.error('BrowserEditor.addElementToChat: Failed to select element', error);
546547
}
547548
} finally {
548549
cts.dispose();

src/vs/workbench/contrib/browserView/electron-browser/browserViewActions.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ class ReloadAction extends Action2 {
139139
}
140140
}
141141

142-
class SelectElementAction extends Action2 {
143-
static readonly ID = 'workbench.action.browser.selectElement';
142+
class AddElementToChatAction extends Action2 {
143+
static readonly ID = 'workbench.action.browser.addElementToChat';
144144

145145
constructor() {
146146
super({
147-
id: SelectElementAction.ID,
148-
title: localize2('browser.selectElementAction', 'Add Element to Chat'),
147+
id: AddElementToChatAction.ID,
148+
title: localize2('browser.addElementToChatAction', 'Add Element to Chat'),
149149
icon: Codicon.inspect,
150150
f1: true,
151151
precondition: ChatContextKeys.enabled,
@@ -161,7 +161,7 @@ class SelectElementAction extends Action2 {
161161

162162
async run(accessor: ServicesAccessor, browserEditor = accessor.get(IEditorService).activeEditorPane): Promise<void> {
163163
if (browserEditor instanceof BrowserEditor) {
164-
await browserEditor.selectElement();
164+
await browserEditor.addElementToChat();
165165
}
166166
}
167167
}
@@ -248,7 +248,7 @@ registerAction2(OpenIntegratedBrowserAction);
248248
registerAction2(GoBackAction);
249249
registerAction2(GoForwardAction);
250250
registerAction2(ReloadAction);
251-
registerAction2(SelectElementAction);
251+
registerAction2(AddElementToChatAction);
252252
registerAction2(ToggleDevToolsAction);
253253
registerAction2(ClearGlobalBrowserStorageAction);
254254
registerAction2(ClearWorkspaceBrowserStorageAction);

src/vs/workbench/contrib/chat/browser/attachments/simpleBrowserEditorOverlay.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,9 @@ class SimpleBrowserOverlayWidget {
262262
const toAttach: IChatRequestVariableEntry[] = [];
263263

264264
const widget = await this._chatWidgetService.revealWidget() ?? this._chatWidgetService.lastFocusedWidget;
265-
let value = 'Attached HTML and CSS Context\n\n' + elementData.outerHTML;
266-
if (this.configurationService.getValue('chat.sendElementsToChat.attachCSS')) {
265+
const attachCss = this.configurationService.getValue<boolean>('chat.sendElementsToChat.attachCSS');
266+
let value = (attachCss ? 'Attached HTML and CSS Context' : 'Attached HTML Context') + '\n\n' + elementData.outerHTML;
267+
if (attachCss) {
267268
value += '\n\n' + elementData.computedStyle;
268269
}
269270
const displayName = getDisplayNameFromOuterHTML(elementData.outerHTML);

0 commit comments

Comments
 (0)