fix(caret): incorrect underline positioning

This commit is contained in:
Miodec 2025-10-17 16:54:41 +02:00
parent 5526088142
commit 79b79e0519
2 changed files with 7 additions and 3 deletions

View file

@ -72,6 +72,5 @@
&.underline {
height: 0.1em;
width: 0.5em;
margin-top: 1.2em;
}
}

View file

@ -519,10 +519,15 @@ export class Caret {
top += options.letter.offsetTop;
top += options.word.offsetTop;
// center the caret vertically and horizontally
if (this.style !== "underline") {
if (this.style === "underline") {
// if style is underline, add the height of the letter to the top
top += options.letter.offsetHeight;
} else {
// else center vertically in the letter
top += (options.letter.offsetHeight - this.getHeight()) / 2;
}
// also center horizontally
if (!this.isFullWidth()) {
left += (this.getWidth() / 2) * -1;
}