Skip to content

Commit 441088b

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored and
Devtools-frontend LUCI CQ
committed
[AI Assistance] Fix edge case of div tag only selector
There is a special case in the SimpleSelector that don't return div with classes. So if we don't find a selector fall back to the node tag Fixed: 410484620 Change-Id: I391455a130360ef3c4052fecf62e88ad8148487c Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6454223 Reviewed-by: Ergün Erdoğmuş <ergunsh@chromium.org> Auto-Submit: Nikolay Vitkov <nvitkov@chromium.org> Commit-Queue: Ergün Erdoğmuş <ergunsh@chromium.org> Commit-Queue: Nikolay Vitkov <nvitkov@chromium.org>
1 parent 7688376 commit 441088b

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

front_end/models/ai_assistance/ExtensionScope.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@ describe('ExtensionScope', () => {
102102
const selector = ExtensionScope.ExtensionScope.getSelectorForNode(node);
103103
assert.strictEqual(selector, '.my\\.special-class.my-class-b');
104104
});
105+
106+
it('should work with only ai generated class', () => {
107+
const node = createNode({
108+
getAttribute: attribute => {
109+
if (attribute === 'class') {
110+
return `${Injected.AI_ASSISTANCE_CSS_CLASS_NAME}-2`;
111+
}
112+
113+
return undefined;
114+
}
115+
});
116+
const selector = ExtensionScope.ExtensionScope.getSelectorForNode(node);
117+
assert.strictEqual(selector, 'div');
118+
});
105119
});
106120

107121
describe('getSelectorFromRules', () => {

front_end/models/ai_assistance/ExtensionScope.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,20 @@ export class ExtensionScope {
219219
}
220220

221221
static getSelectorForNode(node: SDK.DOMModel.DOMNode): string {
222-
return node.simpleSelector()
223-
.split('.')
224-
.filter(chunk => {
225-
return !chunk.startsWith(AI_ASSISTANCE_CSS_CLASS_NAME);
226-
})
227-
.join('.');
222+
const simpleSelector = node.simpleSelector()
223+
.split('.')
224+
.filter(chunk => {
225+
return !chunk.startsWith(AI_ASSISTANCE_CSS_CLASS_NAME);
226+
})
227+
.join('.');
228+
// Handle the edge case where the node is DIV and the
229+
// only selector is the AI_ASSISTANCE_CSS_CLASS_NAME
230+
if (simpleSelector) {
231+
return simpleSelector;
232+
}
233+
234+
// Fallback to the HTML tag
235+
return node.localName() || node.nodeName().toLowerCase();
228236
}
229237

230238
static getSourceLocation(styleRule: SDK.CSSRule.CSSStyleRule): string|undefined {

0 commit comments

Comments
 (0)