Skip to content

Commit

Permalink
fix(vscode): highlight classes with >< characters (#2256)
Browse files Browse the repository at this point in the history
  • Loading branch information
sibbng committed Feb 24, 2023
1 parent cb1784f commit 03c56c8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
4 changes: 2 additions & 2 deletions packages/shared-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function getMatchedPositions(code: string, matched: string[], hasVariantG

// highlight for plain classes
let start = 0
code.split(/([\s"'`;<>*]|:\(|\)"|\)\s)/g).forEach((i) => {
code.split(/([\s"'`;*]|:\(|\)"|\)\s)/g).forEach((i) => {
const end = start + i.length
if (isPug) {
result.push(...getPlainClassMatchedPositionsForPug(i, plain, start))
Expand Down Expand Up @@ -133,7 +133,7 @@ export function getMatchedPositions(code: string, matched: string[], hasVariantG
const [, pre, sep, body] = match
const index = match.index!
let start = index + pre.length + sep.length + 1
body.split(/([\s"'`;<>*]|:\(|\)"|\)\s)/g).forEach((i) => {
body.split(/([\s"'`;*]|:\(|\)"|\)\s)/g).forEach((i) => {
const end = start + i.length
const full = pre + sep + i
if (plain.has(full)) {
Expand Down
49 changes: 31 additions & 18 deletions test/pos.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,41 @@ describe('matched-positions', async () => {
presets: [
presetUno(),
],
shortcuts: {
'<custom-shortcut': 'text-lg',
},
})

expect(await match(uno, '<div class="bg-gray-900 h-4 hover:scale-100"></div>'))
expect(await match(uno, '<div class="bg-gray-900 h-4 hover:scale-100 [&>span]:text-white <custom-shortcut"></div>'))
.toMatchInlineSnapshot(`
[
[
12,
23,
"bg-gray-900",
],
[
24,
27,
"h-4",
],
[
28,
43,
"hover:scale-100",
],
]
`)
[
12,
23,
"bg-gray-900",
],
[
24,
27,
"h-4",
],
[
28,
43,
"hover:scale-100",
],
[
44,
63,
"[&>span]:text-white",
],
[
64,
80,
"<custom-shortcut",
],
]
`)
})

test('variant-group', async () => {
Expand Down

0 comments on commit 03c56c8

Please sign in to comment.