Fix line/column to byte conversion for unspecified columns

This commit is contained in:
Ian Gulliver
2025-06-27 22:00:19 -07:00
parent 55592f0e50
commit c25e695ae9

View File

@@ -32,6 +32,7 @@ func lineColToByteRange(data []byte, startLine, endLine, startCol, endCol int) (
if endLine > 0 {
endLine--
}
// Only decrement columns if they are positive (not -1 which means unspecified)
if startCol > 0 {
startCol--
}
@@ -46,9 +47,11 @@ func lineColToByteRange(data []byte, startLine, endLine, startCol, endCol int) (
for i := 0; i < len(data); i++ {
// Check if we're at the start position
if currentLine == startLine && currentCol == startCol && startByte == -1 {
if currentLine == startLine && startByte == -1 {
if startCol < 0 || currentCol == startCol {
startByte = i
}
}
// Check if we're at the end position
if currentLine == endLine {