From a436246111628562ea295b8beee5cef0336aac01 Mon Sep 17 00:00:00 2001 From: Burrito Date: Mon, 30 Sep 2024 04:56:57 +0800 Subject: [PATCH] Fix incorrect positioning with tabs (#8) --- src/decoration.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/decoration.ts b/src/decoration.ts index 7215b95..7c72459 100644 --- a/src/decoration.ts +++ b/src/decoration.ts @@ -40,8 +40,16 @@ export const getDecorations = async ( const maxShift = getMaxShift() - const getLineLength = (line: number) => - editor.document.lineAt(line).range.end.character + const tabWidth = editor.options.tabSize as number + + const getLineLength = (line: number) => { + let length = 0 + for (const c of editor.document.lineAt(line).text) { + length += c === '\t' ? tabWidth : 1 + } + + return length + } const layouts = positions.map((position, i) => { const paddings: number[] = []