mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 23:01:30 +00:00
Fix emoji and multi-byte character handling in markdown wrapping
This commit is contained in:
parent
95d040195c
commit
c531304d5d
1 changed files with 18 additions and 3 deletions
|
|
@ -403,8 +403,23 @@ export class Markdown implements Component {
|
|||
break;
|
||||
}
|
||||
} else {
|
||||
// Regular character
|
||||
const char = line[i];
|
||||
// Regular character - extract full grapheme cluster
|
||||
// Handle multi-byte characters (emoji, surrogate pairs, etc.)
|
||||
let char: string;
|
||||
let charByteLength: number;
|
||||
|
||||
// Check for surrogate pair (emoji and other multi-byte chars)
|
||||
const codePoint = line.charCodeAt(i);
|
||||
if (codePoint >= 0xd800 && codePoint <= 0xdbff && i + 1 < line.length) {
|
||||
// High surrogate - get the pair
|
||||
char = line.substring(i, i + 2);
|
||||
charByteLength = 2;
|
||||
} else {
|
||||
// Regular character
|
||||
char = line[i];
|
||||
charByteLength = 1;
|
||||
}
|
||||
|
||||
const charWidth = visibleWidth(char);
|
||||
|
||||
// Check if adding this character would exceed width
|
||||
|
|
@ -423,7 +438,7 @@ export class Markdown implements Component {
|
|||
|
||||
currentLine += char;
|
||||
currentLength += charWidth;
|
||||
i++;
|
||||
i += charByteLength;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue