@@ -349,15 +349,17 @@ class CodeCrafterController extends TextEditingController {
349349 }
350350 }
351351
352- final List <Node >? nodes = highlight.parse (text, language: _langId).nodes;
352+ final newText = lines.join ('\n ' );
353+
354+ final List <Node >? nodes = highlight.parse (newText, language: _langId).nodes;
353355 final Set <int > unmatchedBrackets = _findUnmatchedBrackets (text);
354356 if (nodes != null && editorTheme.isNotEmpty) {
355357 return TextSpan (
356358 style: baseStyle,
357359 children: _convert (nodes, 0 , bracket1, bracket2, unmatchedBrackets),
358360 );
359361 } else {
360- return TextSpan (text: text , style: textStyle);
362+ return TextSpan (text: newText , style: textStyle);
361363 }
362364 }
363365
@@ -377,7 +379,10 @@ class CodeCrafterController extends TextEditingController {
377379 for (int lineIdx = 0 ; lineIdx < nodeLines.length; lineIdx++ ) {
378380 final line = nodeLines[lineIdx];
379381 final startOfLineOffset = offset;
380- offset += line.length + (lineIdx == nodeLines.length - 1 ? 0 : 1 );
382+ final lineChars = line.characters;
383+ offset +=
384+ lineChars.length + (lineIdx == nodeLines.length - 1 ? 0 : 1 );
385+
381386 final match = RegExp (r'^(\s*)' ).firstMatch (line);
382387 final leading = match? .group (0 ) ?? '' ;
383388 final indentLen = leading.length;
@@ -389,9 +394,9 @@ class CodeCrafterController extends TextEditingController {
389394 String accumulatedText = '' ;
390395 TextStyle ? currentStyle;
391396
392- for (int col = 0 ; col < line .length; col++ ) {
397+ for (int col = 0 ; col < lineChars .length; col++ ) {
393398 final globalIdx = startOfLineOffset + col;
394- String ch = line[ col] ;
399+ String ch = lineChars. elementAt ( col) ;
395400 if (ch == ' ' && guideCols.contains (col)) ch = '│' ;
396401
397402 final bool isMatch = globalIdx == b1 || globalIdx == b2;
0 commit comments