Commit 7a0d191
fix(core): stop chars ranges leaking across patterns and shared tokens (#276)
* fix(core): stop chars ranges leaking across patterns and shared tokens
Two defects made ranged char highlights (`/foo/2`, `/foo/#a`) affect the
wrong characters, per #169.
1. Range/pattern misalignment (index.ts). `charsList` always received an
entry, but `charsListNumbers` (the parallel ranges array) was only
pushed when a numeric range was present. An id-only annotation like
`/foo/#a` therefore left the arrays misaligned, so a later pattern
inherited the previous pattern's range. Always push a ranges entry
(empty array when there is no range) to keep the arrays index-aligned.
2. Ignored occurrences over-consumed their token (chars/*). When a range
excluded an occurrence, `splitElement` returned the whole node unsplit,
so the entire containing token was marked visited. Any other pattern
living in the same token on that line (e.g. `Length` inside
`getStringLength` when `/get/1` is range-ignored on later lines) could
then never match. Let ignored occurrences split like any other so only
the matched part is marked visited; the now-unused `ignoreChars`
plumbing is removed from `getElementsToHighlight`/`splitElement`.
Result: `/get/1 /Length/` now highlights `Length` on every line while
`get` stays on its first occurrence, and `/get/#a /Length/2` highlights
`get` everywhere while `Length` is limited to its second occurrence.
Snapshots: `highlightedMultipleCharsRange` gains the two occurrences that
were previously dropped; the other three updated snapshots are unchanged
in what they highlight (identical <mark> sets) and only gain cosmetic
span splits on ignored, unhighlighted tokens. Added a
`charsRangeInheritance` fixture covering both scenarios.
This addresses the range-inheritance part of #169. Highlighting a pattern
that is a substring of another highlighted pattern (`/getStringLength/
/get/`) is a separate nested-highlight feature and is out of scope here.
Refs #169
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* chore: add patch changeset
* fix(core): keep split fragments from spelling synthetic matches
Splitting an occurrence a range excludes leaves the token in pieces around
a node the scanner has to skip. Two things then went wrong.
The remaining text was recomputed by dropping the excluded node, which
joined its neighbours: 'bal' + 'on;' reads as 'balon;' and contains an
occurrence of 'lo' the code never had. That phantom either advanced the
range counter past a real later occurrence, or led the matcher across the
gap and returned non-adjacent elements, which wrapHighlightedChars then
spliced as if they were consecutive -- deleting and duplicating text.
Keep a boundary in place of an excluded node so fragments cannot spell a
match across it, count an occurrence only once it resolves to elements,
abandon a partial run as soon as it stops being contiguous, and read the
positions back from the tree before splicing.
* test(core): pin the unranged variant of the fragment-joining bug
`/con/` on `coconnection` renders as `coconneconon;` on master: the
highlighted `con` is dropped when the remaining text is recomputed, `co`
and `nection;` join into a phantom second occurrence, and wrapping it
splices siblings that were never matched.
* fix(core): preserve chars highlights across token trees
* fix(core): preserve markup around ranged highlights
* fix(core): batch character highlight mutations
* fix(core): preserve whole transformer boundaries
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: atomiks <cc.glows@gmail.com>1 parent 012acb6 commit 7a0d191
11 files changed
Lines changed: 1399 additions & 434 deletions
File tree
- .changeset
- packages/core
- src
- chars
- test
- fixtures
- results
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | 2 | | |
6 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
7 | 184 | | |
8 | 185 | | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
| 186 | + | |
| 187 | + | |
16 | 188 | | |
17 | 189 | | |
18 | 190 | | |
| |||
23 | 195 | | |
24 | 196 | | |
25 | 197 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
60 | 201 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
94 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
95 | 210 | | |
96 | 211 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
101 | 217 | | |
102 | | - | |
| 218 | + | |
103 | 219 | | |
0 commit comments