Commit 7034a09
Yogthos
fix(ui): strip ANSI escapes from terminal selection (copy/paste)
Markdown rendering bakes SGR codes (`\x1b[31m` …) directly into
`LineEntry::text` for inline-styled spans (see markdown.rs:291).
Without filtering, a user dragging to select styled text — bold,
emphasis, code spans, diff highlights — copied the raw escape
sequences into the clipboard. Paste lands in editors / shells as
visible `[31m` garbage and the actual content fragmented around it.
- New `ui::ansi::strip_ansi(&str) -> String` shares the CSI-skip
loop with `wrap::visible_width` (terminator set 0x40..=0x7E so
cursor-moves / scroll-region escapes also strip — anything a
misbehaving producer might leave in the buffer). Lone ESC (not
followed by `[`) also drops, defensive against truncated
OSC/DCS heads.
- `Renderer::selected_text` strips per-row before applying the
column slice. Selection columns are user-perceived character
offsets in the visible glyphs, so column-indexing the cleaned
string is correct; the prior implementation column-indexed
the escape-laden source, which could land mid-escape and
produce mojibake on the substring path too.
Tests: 7 new — 6 ANSI-strip cases (SGR sequences, nested escapes,
lone ESC, unicode payload, non-SGR CSI, truncated escape) + 1
end-to-end through selected_text. 1071 → 1078 with plugin
feature; 866 → 873 without.1 parent 1a90d57 commit 7034a09
2 files changed
Lines changed: 137 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 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 | + | |
103 | 150 | | |
104 | 151 | | |
105 | 152 | | |
| |||
157 | 204 | | |
158 | 205 | | |
159 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
160 | 250 | | |
161 | 251 | | |
162 | 252 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
310 | 323 | | |
311 | 324 | | |
312 | | - | |
313 | | - | |
314 | | - | |
| 325 | + | |
315 | 326 | | |
316 | 327 | | |
317 | 328 | | |
318 | 329 | | |
319 | 330 | | |
320 | 331 | | |
321 | 332 | | |
322 | | - | |
323 | | - | |
324 | | - | |
| 333 | + | |
325 | 334 | | |
326 | 335 | | |
327 | 336 | | |
328 | 337 | | |
329 | 338 | | |
330 | | - | |
331 | | - | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
332 | 342 | | |
333 | 343 | | |
334 | 344 | | |
335 | | - | |
336 | | - | |
| 345 | + | |
337 | 346 | | |
338 | 347 | | |
339 | 348 | | |
| |||
1807 | 1816 | | |
1808 | 1817 | | |
1809 | 1818 | | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
1810 | 1847 | | |
1811 | 1848 | | |
1812 | 1849 | | |
| |||
0 commit comments