| 93 | } |
| 94 | } |
| 95 | function truncateLine(text: string, maxLen: number): string { |
| 96 | const firstLine = text.split('\n')[0] ?? ''; |
| 97 | if (stringWidth(firstLine) <= maxLen) { |
| 98 | return firstLine; |
| 99 | } |
| 100 | let result = ''; |
| 101 | let width = 0; |
| 102 | const targetWidth = maxLen - 1; |
| 103 | for (const char of firstLine) { |
| 104 | const charWidth = stringWidth(char); |
| 105 | if (width + charWidth > targetWidth) break; |
| 106 | result += char; |
| 107 | width += charWidth; |
| 108 | } |
| 109 | return result + '\u2026'; |
| 110 | } |
| 111 | type PickerProps = { |
| 112 | fullText: string; |
| 113 | codeBlocks: CodeBlock[]; |