mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-22 10:14:22 +01:00
fix: properly handle utf-8 in diff highlighting (#585)
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/alecthomas/chroma/v2"
|
"github.com/alecthomas/chroma/v2"
|
||||||
"github.com/alecthomas/chroma/v2/formatters"
|
"github.com/alecthomas/chroma/v2/formatters"
|
||||||
@@ -575,7 +576,10 @@ func applyHighlighting(content string, segments []Segment, segmentType LineType,
|
|||||||
ansiSequences[visibleIdx] = lastAnsiSeq
|
ansiSequences[visibleIdx] = lastAnsiSeq
|
||||||
}
|
}
|
||||||
visibleIdx++
|
visibleIdx++
|
||||||
i++
|
|
||||||
|
// Properly advance by UTF-8 rune, not byte
|
||||||
|
_, size := utf8.DecodeRuneInString(content[i:])
|
||||||
|
i += size
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply highlighting
|
// Apply highlighting
|
||||||
@@ -622,8 +626,9 @@ func applyHighlighting(content string, segments []Segment, segmentType LineType,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get current character
|
// Get current character (properly handle UTF-8)
|
||||||
char := string(content[i])
|
r, size := utf8.DecodeRuneInString(content[i:])
|
||||||
|
char := string(r)
|
||||||
|
|
||||||
if inSelection {
|
if inSelection {
|
||||||
// Get the current styling
|
// Get the current styling
|
||||||
@@ -657,7 +662,7 @@ func applyHighlighting(content string, segments []Segment, segmentType LineType,
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentPos++
|
currentPos++
|
||||||
i++
|
i += size
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.String()
|
return sb.String()
|
||||||
|
|||||||
Reference in New Issue
Block a user