From 48d47c461c4e2a323cb7c6608d6a830afc4711d3 Mon Sep 17 00:00:00 2001 From: Ian Cottrell Date: Wed, 13 Mar 2019 18:00:13 -0400 Subject: [PATCH] internal/span: fix utf16 column when span is line based A span with column 0 is intended to mean the start of the line, which in utf16 mode must be the 1st character Change-Id: I4b98fe86528b889bbfe4b5ed3ae79c4da81017b1 Reviewed-on: https://go-review.googlesource.com/c/tools/+/167459 Run-TryBot: Ian Cottrell Reviewed-by: Rebecca Stambler TryBot-Result: Gobot Gobot --- internal/span/utf16.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/span/utf16.go b/internal/span/utf16.go index 4cc16a17..79f35f2d 100644 --- a/internal/span/utf16.go +++ b/internal/span/utf16.go @@ -14,9 +14,12 @@ import ( // This is used to convert from the native (always in bytes) column // representation and the utf16 counts used by some editors. func ToUTF16Column(offsets Offsets, p Point, content []byte) int { - if content == nil || p.Column < 1 { + if content == nil || p.Column < 0 { return -1 } + if p.Column == 0 { + return 1 + } // make sure we have a valid offset p.updateOffset(offsets) lineOffset := p.Offset - (p.Column - 1)