Skip to content

Commit

Permalink
fix(caret): getting last letter top in long multiline words (@NadAlaba)…
Browse files Browse the repository at this point in the history
… (#5856)

* fix(caret): getting last letter top in long multiline words (@NadAlaba)

* no need to check for invisible extra letters

This check was needed when `letterPosTop` was
`currentLetter?.offsetTop ?? previousLetter?.offsetTop ??
lastWordLetter?.offsetTop` where `previousLetter?.offsetTop` was defined
but 0 in extra letters in blind mode, so we got the value of zero
although in some fonts the real value (`lastWordLetter` value) is not 0.

However, now we don't use `previousLetter`, and `currentLetter` is
undefined in extra letters (blind mode or not), so we'll get the value
we want (`lastWordLetter` value) in extra letters.

* update comment
  • Loading branch information
NadAlaba authored Sep 6, 2024
1 parent 77c1e8e commit cbaefbf
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions frontend/src/ts/test/caret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,15 @@ export async function updatePosition(noAnim = false): Promise<void> {
const isLanguageRightToLeft = currentLanguage.rightToLeft;

// in blind mode, and hide extra letters, extra letters have zero offsets
// offsetTop and offsetHeight is the same for all visible letters
// offsetHeight is the same for all visible letters
// so is offsetTop (for same line letters)
const letterHeight =
currentLetter?.offsetHeight ||
lastWordLetter?.offsetHeight ||
Config.fontSize * Numbers.convertRemToPixels(1);

const letterPosTop =
currentLetter?.offsetTop || lastWordLetter?.offsetTop || 0;
currentLetter?.offsetTop ?? lastWordLetter?.offsetTop ?? 0;
const diff = letterHeight - caret.offsetHeight;
let newTop = activeWordEl.offsetTop + letterPosTop + diff / 2;
if (Config.caretStyle === "underline") {
Expand Down

0 comments on commit cbaefbf

Please sign in to comment.