summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLev <[email protected]>2025-07-03 12:42:40 +0200
committerGitHub <[email protected]>2025-07-03 05:42:40 -0500
commit2ace57404b72a40466ce1d55b28e57c5e8b4be44 (patch)
tree78eb8b826818480f6dd1390b591ea794dec90e98
parent8c4b5e088ba6e9b76f34d140a49caab1bd9479c5 (diff)
downloadopencode-2ace57404b72a40466ce1d55b28e57c5e8b4be44.tar.gz
opencode-2ace57404b72a40466ce1d55b28e57c5e8b4be44.zip
fix: properly handle utf-8 in diff highlighting (#585)
-rw-r--r--packages/tui/internal/components/diff/diff.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/packages/tui/internal/components/diff/diff.go b/packages/tui/internal/components/diff/diff.go
index 02c2c31e9..03f58cc26 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"
@@ -575,7 +576,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
@@ -622,8 +626,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
@@ -657,7 +662,7 @@ func applyHighlighting(content string, segments []Segment, segmentType LineType,
}
currentPos++
- i++
+ i += size
}
return sb.String()