From a17f7a1adc14a59c4de0b951948650e852e07197 Mon Sep 17 00:00:00 2001 From: Richard Musiol Date: Wed, 8 Feb 2017 14:00:13 -0800 Subject: [PATCH] fix offsets for files with multibyte characters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When using multibyte characters like 🚨 in comments, actions like hover and go-to-def were using wrong offsets after that character. --- src/util.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/util.ts b/src/util.ts index b27dbbcde..f155a0fb6 100644 --- a/src/util.ts +++ b/src/util.ts @@ -53,12 +53,7 @@ let telemtryReporter: TelemetryReporter; export function byteOffsetAt(document: vscode.TextDocument, position: vscode.Position): number { let offset = document.offsetAt(position); let text = document.getText(); - let byteOffset = 0; - for (let i = 0; i < offset; i++) { - let clen = Buffer.byteLength(text[i]); - byteOffset += clen; - } - return byteOffset; + return Buffer.byteLength(text.substr(0, offset)); } export interface Prelude {