Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions packages/tui/internal/components/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strconv"
"strings"
"sync"
"unicode/utf8"

"github.com/alecthomas/chroma/v2"
"github.com/alecthomas/chroma/v2/formatters"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -686,7 +691,7 @@ func applyHighlighting(content string, segments []Segment, segmentType LineType,
}

currentPos++
i++
i += size
}

return sb.String()
Expand Down