Skip to content

Fix name attributes in CSS selector hovers - #545

Open
Xnerv Wang (xnervwang) wants to merge 1 commit into
microsoft:mainfrom
xnervwang:fix/name-attribute-hover
Open

Xnerv Wang (xnervwang) wants to merge 1 commit into
microsoft:mainfrom
xnervwang:fix/name-attribute-hover

Conversation

@xnervwang

Copy link
Copy Markdown
Contributor

The hover for [name="jmeno"] shows <jmeno> instead of <element name="jmeno">. input[name="jmeno"] shows <input jmeno>, and input[name] shows <input undefined>. Other attributes, such as [names="jmeno"], display correctly.

The Element class in src/services/selectorPrinting.ts stores the element name in its attribute list under the key name, which collides with a real name attribute. In the earlier PR #299, aeschli identified this collision and suggested a separate property or a key such as <> that is not a valid attribute name.

This change stores the element name under a new ELEMENT_NAME constant with the value <>. The name stays at the same position in the attribute list, so the Sass & handling for &__bar and prefixes before &, which appends to the last entry and prepends to the first, works as before.

An escaped attribute name that decodes to <>, such as [\<\>=x], now collides with the key and displays as <x> instead of the previous <element <>="x">.

New tests cover the reported [name="jmeno"] selector and an SCSS rule nested in o1[name=x]; they fail on main. With the change, they pass along with the rest of npm test.

Fixes microsoft/vscode#160987.

@xnervwang

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integration note: synchronize #546 with the new label-name storage

This PR looks correct independently, but please coordinate with #546 before merging both. #546 adds a LabelElement.clone() implementation that still reads findAttribute("name"); this PR changes label-name storage to ELEMENT_NAME (<>). The combination therefore clones a null label.

For .foo ~ .bar { .baz & { color: red; } }, the combined preview contains literal null instead of ⋮; descendant placeholders can also lose …. Both CSS and SCSS sibling-reference tests fail in the combined suite, although each PR passes separately.

The detailed reproduction/fix request is also posted on #546. Updating its clone lookup to the same storage key resolves the mismatch; this is not a request to revert the [name] fix here.

Reviewed commit: 5b3751b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[scss] Wrongly shown selector in SCSS

2 participants