Skip to content

Commit e37b447

Browse files
byseif21Miodec
andauthored
fix(caret): positioning for mixed language directions in zen (@byseif21) (monkeytypegame#7281)
Co-authored-by: Jack <jack@monkeytype.com>
1 parent ca91f6e commit e37b447

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

frontend/src/ts/utils/caret.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,15 @@ export class Caret {
405405
isLanguageRightToLeft: boolean;
406406
isDirectionReversed: boolean;
407407
}): { left: number; top: number; width: number } {
408+
// in zen, custom or polyglot mode we need to check per-letter
409+
const checkRtlByLetter =
410+
Config.mode === "zen" ||
411+
Config.mode === "custom" ||
412+
Config.funbox.includes("polyglot");
408413
const [isWordRTL, isFullMatch] = isWordRightToLeft(
409-
options.wordText,
414+
checkRtlByLetter
415+
? (options.letter.native.textContent ?? "")
416+
: options.wordText,
410417
options.isLanguageRightToLeft,
411418
options.isDirectionReversed,
412419
);
@@ -455,7 +462,7 @@ export class Caret {
455462

456463
// yes, this is all super verbose, but its easier to maintain and understand
457464
if (isWordRTL) {
458-
if (isFullMatch) options.word.addClass("wordRtl");
465+
if (!checkRtlByLetter && isFullMatch) options.word.addClass("wordRtl");
459466
let afterLetterCorrection = 0;
460467
if (options.side === "afterLetter") {
461468
if (this.isFullWidth()) {

0 commit comments

Comments
 (0)