Skip to content

Commit ec445a7

Browse files
Samiya CaurDevtools-frontend LUCI CQ
authored andcommitted
[AI Assistance] Remove ai-style-change-* class from the selector picker within AI Assistance
Fixed: 362464957 Change-Id: I13df1e61153c69f0fa57f763e78fefb65f0914d1 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6090598 Commit-Queue: Alex Rudenko <[email protected]> Reviewed-by: Alex Rudenko <[email protected]> Auto-Submit: Samiya Caur <[email protected]>
1 parent 2bc8417 commit ec445a7

File tree

5 files changed

+27
-16
lines changed

5 files changed

+27
-16
lines changed

front_end/core/sdk/DOMModel.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,11 @@ export class DOMNode {
10441044

10451045
return this.domModel().nodeForId(response.nodeId);
10461046
}
1047+
1048+
classNames(): string[] {
1049+
const classes = this.getAttribute('class');
1050+
return classes ? classes.split(/\s+/) : [];
1051+
}
10471052
}
10481053

10491054
export namespace DOMNode {

front_end/panels/ai_assistance/agents/StylingAgent.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import * as Root from '../../../core/root/root.js';
1010
import * as SDK from '../../../core/sdk/sdk.js';
1111
import * as UI from '../../../ui/legacy/legacy.js';
1212
import * as LitHtml from '../../../ui/lit-html/lit-html.js';
13-
import {ChangeManager} from '../ChangeManager.js';
13+
import {linkifyNodeReference} from '../../elements/DOMLinkifier.js';
14+
import {AI_ASSISTANCE_CSS_CLASS_NAME, ChangeManager} from '../ChangeManager.js';
1415
import {EvaluateAction, formatError, SideEffectError} from '../EvaluateAction.js';
1516
import {ExtensionScope, FREESTYLER_WORLD_NAME} from '../ExtensionScope.js';
1617

@@ -226,8 +227,10 @@ export class NodeContext extends ConversationContext<SDK.DOMModel.DOMNode> {
226227
}
227228

228229
override getTitle(): string|ReturnType<typeof LitHtml.Directives.until> {
230+
const hiddenClassList =
231+
this.#node.classNames().filter(className => className.startsWith(AI_ASSISTANCE_CSS_CLASS_NAME));
229232
return LitHtml.Directives.until(
230-
Common.Linkifier.Linkifier.linkify(this.#node),
233+
linkifyNodeReference(this.#node, {hiddenClassList}),
231234
);
232235
}
233236
}

front_end/panels/ai_assistance/components/ChatView.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// found in the LICENSE file.
44

55
import * as Host from '../../../core/host/host.js';
6-
import type * as SDK from '../../../core/sdk/sdk.js';
76
import {renderElementIntoDOM} from '../../../testing/DOMHelpers.js';
87
import {describeWithEnvironment, getGetHostConfigStub} from '../../../testing/EnvironmentHelpers.js';
98
import * as Marked from '../../../third_party/marked/marked.js';
@@ -104,6 +103,8 @@ css
104103
function getProp(options: Partial<Freestyler.Props>): Freestyler.Props {
105104
const noop = () => {};
106105
const messages: Freestyler.ChatMessage[] = options.messages ?? [];
106+
const selectedContext = sinon.createStubInstance(Freestyler.NodeContext);
107+
selectedContext.getTitle.returns('');
107108
return {
108109
onTextSubmit: noop,
109110
onInspectElementClick: noop,
@@ -116,7 +117,7 @@ css
116117
agentType: Freestyler.AgentType.STYLING,
117118
aidaAvailability: Host.AidaClient.AidaAccessPreconditions.AVAILABLE,
118119
messages,
119-
selectedContext: new Freestyler.NodeContext({} as unknown as SDK.DOMModel.DOMNode),
120+
selectedContext,
120121
isLoading: false,
121122
canShowFeedbackForm: false,
122123
userInfo: {},

front_end/panels/elements/DOMLinkifier.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ const UIStrings = {
2121
const str_ = i18n.i18n.registerUIStrings('panels/elements/DOMLinkifier.ts', UIStrings);
2222
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
2323

24+
export interface Options extends Common.Linkifier.Options {
25+
hiddenClassList?: string[];
26+
}
27+
2428
export const decorateNodeLabel = function(
25-
node: SDK.DOMModel.DOMNode, parentElement: HTMLElement, options: Common.Linkifier.Options): void {
29+
node: SDK.DOMModel.DOMNode, parentElement: HTMLElement, options: Options): void {
2630
const originalNode = node;
2731
const isPseudo = node.nodeType() === Node.ELEMENT_NODE && node.pseudoType();
2832
if (isPseudo && node.parentNode) {
@@ -69,7 +73,7 @@ export const decorateNodeLabel = function(
6973
const classesElement = parentElement.createChild('span', 'extra node-label-class');
7074
for (let i = 0; i < classes.length; ++i) {
7175
const className = classes[i];
72-
if (className && !foundClasses.has(className)) {
76+
if (className && !options.hiddenClassList?.includes(className) && !foundClasses.has(className)) {
7377
const part = '.' + className;
7478
title += part;
7579
UI.UIUtils.createTextChild(classesElement, part);
@@ -93,13 +97,12 @@ export const decorateNodeLabel = function(
9397
UI.Tooltip.Tooltip.install(parentElement, options.tooltip || title);
9498
};
9599

96-
export const linkifyNodeReference = function(
97-
node: SDK.DOMModel.DOMNode|null, options: Common.Linkifier.Options|undefined = {
98-
tooltip: undefined,
99-
preventKeyboardFocus: undefined,
100-
textContent: undefined,
101-
isDynamicLink: false,
102-
}): Node {
100+
export const linkifyNodeReference = function(node: SDK.DOMModel.DOMNode|null, options: Options|undefined = {
101+
tooltip: undefined,
102+
preventKeyboardFocus: undefined,
103+
textContent: undefined,
104+
isDynamicLink: false,
105+
}): Node {
103106
if (!node) {
104107
return document.createTextNode(i18nString(UIStrings.node));
105108
}
@@ -129,7 +132,7 @@ export const linkifyNodeReference = function(
129132
};
130133

131134
export const linkifyDeferredNodeReference = function(
132-
deferredNode: SDK.DOMModel.DeferredDOMNode, options: Common.Linkifier.Options|undefined = {
135+
deferredNode: SDK.DOMModel.DeferredDOMNode, options: Options|undefined = {
133136
tooltip: undefined,
134137
preventKeyboardFocus: undefined,
135138
}): Node {
@@ -166,7 +169,7 @@ export class Linkifier implements Common.Linkifier.Linkifier {
166169

167170
return linkifierInstance;
168171
}
169-
linkify(object: Object, options?: Common.Linkifier.Options): Node {
172+
linkify(object: Object, options?: Options): Node {
170173
if (object instanceof SDK.DOMModel.DOMNode) {
171174
return linkifyNodeReference(object, options);
172175
}

front_end/testing/DOMHelpers.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export const renderElementIntoDOM = (element: HTMLElement, renderOptions: Render
3333
if (container.childNodes.length !== 0 && !allowMultipleChildren) {
3434
throw new Error(`renderElementIntoDOM expects the container to be empty ${container.innerHTML}`);
3535
}
36-
3736
container.appendChild(element);
3837
return element;
3938
};

0 commit comments

Comments
 (0)