Skip to content

Commit d57125b

Browse files
committed
fix position calculation with mixed tabs and spaces
1 parent e343b30 commit d57125b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/content.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ function findHoverCharacter({
110110
// hovering over the second half of the character.
111111
let x = 0
112112
for (let i = 0; i < text.length; i++) {
113-
x += characterWidth * (text[i] === '\t' ? tabSize : 1)
113+
if (text[i] === '\t') x = characterWidth * Math.floor(x / characterWidth / tabSize + 1) * tabSize
114+
else x += characterWidth
114115
if (x > contentX) {
115116
return i
116117
}

0 commit comments

Comments
 (0)