@@ -5,45 +5,13 @@ import {useI18n} from '../../../i18n/I18nContext.js';
55import { useTerminalSize } from '../../../hooks/ui/useTerminalSize.js' ;
66import { streamBtwResponse } from '../../../utils/commands/btwStream.js' ;
77import { visualWidth } from '../../../utils/core/textUtils.js' ;
8+ import { renderMarkdownToLines } from '../common/MarkdownRenderer.js' ;
89
910type Step = 'streaming' | 'done' | 'error' ;
1011
1112const VISIBLE_ROWS = 8 ;
1213const DEBOUNCE_MS = 80 ;
1314
14- /**
15- * Split text into visual lines that each fit within `maxWidth` columns.
16- * Accounts for wide characters (CJK, emoji) via visualWidth.
17- */
18- function toVisualLines ( text : string , maxWidth : number ) : string [ ] {
19- if ( maxWidth <= 0 ) return text . split ( '\n' ) ;
20-
21- const result : string [ ] = [ ] ;
22- for ( const logical of text . split ( '\n' ) ) {
23- if ( ! logical || visualWidth ( logical ) <= maxWidth ) {
24- result . push ( logical ) ;
25- continue ;
26- }
27-
28- const chars = [ ...logical ] ;
29- let cur = '' ;
30- let curW = 0 ;
31- for ( const ch of chars ) {
32- const w = visualWidth ( ch ) ;
33- if ( curW + w > maxWidth ) {
34- result . push ( cur ) ;
35- cur = ch ;
36- curW = w ;
37- } else {
38- cur += ch ;
39- curW += w ;
40- }
41- }
42- if ( cur ) result . push ( cur ) ;
43- }
44- return result ;
45- }
46-
4715interface Props {
4816 prompt : string ;
4917 onClose : ( ) => void ;
@@ -68,8 +36,8 @@ export const BtwPanel: React.FC<Props> = ({prompt, onClose}) => {
6836 const contentWidth = Math . max ( 1 , columns - 4 ) ;
6937
7038 const visualLines = useMemo (
71- ( ) => toVisualLines ( response , contentWidth ) ,
72- [ response , contentWidth ] ,
39+ ( ) => ( response ? renderMarkdownToLines ( response ) : [ ] ) ,
40+ [ response ] ,
7341 ) ;
7442
7543 const flushPending = useCallback ( ( ) => {
0 commit comments