diff --git a/packages/tui/internal/components/diff/diff.go b/packages/tui/internal/components/diff/diff.go index 3d0e41fc37..7cc179c35b 100644 --- a/packages/tui/internal/components/diff/diff.go +++ b/packages/tui/internal/components/diff/diff.go @@ -10,6 +10,7 @@ import ( "strconv" "strings" "sync" + "unicode/utf8" "github.com/alecthomas/chroma/v2" "github.com/alecthomas/chroma/v2/formatters" @@ -604,7 +605,10 @@ func applyHighlighting(content string, segments []Segment, segmentType LineType, ansiSequences[visibleIdx] = lastAnsiSeq } visibleIdx++ - i++ + + // Properly advance by UTF-8 rune, not byte + _, size := utf8.DecodeRuneInString(content[i:]) + i += size } // Apply highlighting @@ -651,8 +655,9 @@ func applyHighlighting(content string, segments []Segment, segmentType LineType, } } - // Get current character - char := string(content[i]) + // Get current character (properly handle UTF-8) + r, size := utf8.DecodeRuneInString(content[i:]) + char := string(r) if inSelection { // Get the current styling @@ -686,7 +691,7 @@ func applyHighlighting(content string, segments []Segment, segmentType LineType, } currentPos++ - i++ + i += size } return sb.String()