From c25e695ae9d91ba9b28bdf265472c493110161fe Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Fri, 27 Jun 2025 22:00:19 -0700 Subject: [PATCH] Fix line/column to byte conversion for unspecified columns --- tool_read_write_range.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tool_read_write_range.go b/tool_read_write_range.go index 9256192..5654dc3 100644 --- a/tool_read_write_range.go +++ b/tool_read_write_range.go @@ -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,8 +47,10 @@ 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 { - startByte = i + if currentLine == startLine && startByte == -1 { + if startCol < 0 || currentCol == startCol { + startByte = i + } } // Check if we're at the end position