mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 04:00:10 +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;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Regular character
|
// Regular character - extract full grapheme cluster
|
||||||
const char = line[i];
|
// 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);
|
const charWidth = visibleWidth(char);
|
||||||
|
|
||||||
// Check if adding this character would exceed width
|
// Check if adding this character would exceed width
|
||||||
|
|
@ -423,7 +438,7 @@ export class Markdown implements Component {
|
||||||
|
|
||||||
currentLine += char;
|
currentLine += char;
|
||||||
currentLength += charWidth;
|
currentLength += charWidth;
|
||||||
i++;
|
i += charByteLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue