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 <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Ian Cottrell 2019-03-13 18:00:13 -04:00
parent dbad8e90c9
commit 48d47c461c
1 changed files with 4 additions and 1 deletions

View File

@ -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)