Skip to content

Commit 1a1d672

Browse files
committed
fix: re-apply style on each column in getMultiCodePointCharacters
1 parent bf137a8 commit 1a1d672

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/utils/strings.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,27 @@ export function getMultiCodePointCharacters(text: string): string[] {
1717
if (matched?.includes("\x1b")) {
1818
const arr: string[] = [];
1919
let i = 0;
20-
let ansi = false;
20+
let ansi = 0;
21+
let lastStyle = "";
2122
for (const char of matched) {
2223
arr[i] ??= "";
23-
arr[i] += char;
24+
arr[i] += lastStyle + char;
2425

2526
if (char === "\x1b") {
26-
ansi = true;
27+
++ansi;
28+
lastStyle += "\x1b";
2729
} else if (ansi) {
28-
if (char === "m") ansi = false;
30+
lastStyle += char;
31+
32+
if (ansi === 3 && char === "m" && lastStyle[lastStyle.length - 2] === "0") {
33+
lastStyle = "";
34+
}
35+
36+
if (char === "m") {
37+
ansi = 0;
38+
} else {
39+
++ansi;
40+
}
2941
} else {
3042
++i;
3143
}

0 commit comments

Comments
 (0)