Skip to content

Commit 5804e66

Browse files
authored
Merge pull request #94 from code-hike/fix-annotation-focus-string
Fix multi-annotation focus string
2 parents debdf51 + 2112ee3 commit 5804e66

File tree

17 files changed

+45
-989
lines changed

17 files changed

+45
-989
lines changed

packages/highlighter/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"dependencies": {
1919
"@code-hike/utils": "^0.3.0-next.0",
20-
"shiki": "^0.9.11"
20+
"shiki": "^0.9.14"
2121
},
2222
"homepage": "https://codehike.org",
2323
"repository": "code-hike/codehike",

packages/playground/content/meta-annotations.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Besides `focus`, there are a few more annotations that can be used to highlight
66

77
### `box` annotation
88

9-
```js box=2[15:43]
9+
```js box=2[15:43],4[10:12]
1010
function lorem(ipsum, dolor = 1) {
1111
const sit = ipsum == null ? 0 : ipsum.sit
1212
dolor = sit - amet(dolor)
@@ -18,7 +18,7 @@ function lorem(ipsum, dolor = 1) {
1818

1919
### `bg` annotation
2020

21-
```js bg=4:6
21+
```js bg=2,4:6
2222
function lorem(ipsum, dolor = 1) {
2323
const sit = ipsum == null ? 0 : ipsum.sit
2424
dolor = sit - amet(dolor)

packages/smooth-code/src/annotations.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import {
77
FocusedLine,
88
AnnotatedLine,
99
LineGroup,
10-
} from "./step-parser"
10+
} from "./partial-step-parser"
1111
import {
1212
Tween,
1313
FullTween,
1414
mapWithDefault,
1515
map,
1616
hasColumns,
1717
parsePartToObject,
18+
splitParts,
1819
ColumnExtremes,
1920
parseExtremes,
2021
} from "@code-hike/utils"
@@ -32,13 +33,27 @@ export function parseAnnotations(
3233
>
3334
multilineAnnotations: FullTween<MultiLineAnnotation[]>
3435
} {
35-
const inlineCodeAnnotations = mapWithDefault(
36+
// split annotations with multiple parts in the focus string
37+
// "1:2,3[4:5]" becomes two annotations "1:2" and "3[4:5]"
38+
const expandedAnnotations = mapWithDefault(
3639
annotations,
3740
[],
41+
annotations =>
42+
annotations!.flatMap(annotation =>
43+
splitParts(annotation.focus).map(part => ({
44+
...annotation,
45+
focus: part,
46+
}))
47+
)
48+
)
49+
50+
const inlineCodeAnnotations = mapWithDefault(
51+
expandedAnnotations,
52+
[],
3853
annotations => annotations!.filter(isInline)
3954
)
4055
const multilineCodeAnnotations = mapWithDefault(
41-
annotations,
56+
expandedAnnotations,
4257
[],
4358
annotations => annotations!.filter(a => !isInline(a))
4459
)

packages/smooth-code/src/differ.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
HighlightedLine,
55
MergedCode,
66
MergedLine,
7-
} from "./step-parser"
7+
} from "./partial-step-parser"
88

99
export function mergeLines(
1010
code: FullTween<string>,

packages/smooth-code/src/heavy-code.tsx

Lines changed: 0 additions & 150 deletions
This file was deleted.

0 commit comments

Comments
 (0)