Skip to content

Commit

Permalink
fix(vscode): selection style with media (#1863)
Browse files Browse the repository at this point in the history
Co-authored-by: cuiluc <cuilulu4043@126.com>
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
3 people committed Nov 9, 2022
1 parent 9da073a commit dbee1fd
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/vscode/src/selectionStyle.ts
Expand Up @@ -35,7 +35,7 @@ export async function registerSelectionStyle(cwd: string, contextLoader: Context
code = `${code} >`
const ctx = await contextLoader.resolveContext(code, id) || (await contextLoader.resolveClosestContext(code, id))
const result = await getMatchedPositionsFromCode(ctx.uno, code)
if (!result.length)
if (result.length <= 1)
return reset()

const uniqMap = new Map<string, string>()
Expand All @@ -47,21 +47,23 @@ export async function registerSelectionStyle(cwd: string, contextLoader: Context
await Promise.all(Array.from(uniqMap.values())
.map(async (name) => {
const tokens = await ctx.uno.parseToken(name, classNamePlaceholder) || []
tokens.forEach((token) => {
if (token[1] && token[2]) {
const key = token[1]
tokens.forEach(([, className, cssText, media]) => {
if (className && cssText) {
let key = className
.replace(`.${classNamePlaceholder}`, '&')
.replace(regexScopePlaceholder, ' ')
.trim()
sheetMap.set(key, (sheetMap.get(key) || '') + token[2])
if (media)
key = `${media}{${key}`
sheetMap.set(key, (sheetMap.get(key) || '') + cssText)
}
})
}),
)

const css = Array.from(sheetMap.keys())
.sort()
.map(key => `${key}{${sheetMap.get(key)}}`)
.map(key => `${key}{${sheetMap.get(key)}}${key.includes('{') ? '}' : ''}`)
.join('\n')

const prettified = prettier.format(css, {
Expand Down

0 comments on commit dbee1fd

Please sign in to comment.