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