MCPcopy Index your code
hub / github.com/monkeytypegame/monkeytype / updateWordsInputPosition

Function updateWordsInputPosition

frontend/src/ts/test/test-ui.ts:522–570  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

520}
521
522export function updateWordsInputPosition(): void {
523 if (getActivePage() !== "test") return;
524 const isTestRightToLeft = TestState.isDirectionReversed
525 ? !TestState.isLanguageRightToLeft
526 : TestState.isLanguageRightToLeft;
527
528 const el = getInputElement();
529
530 if (el === null) return;
531
532 const activeWord = getActiveWordElement();
533
534 if (!activeWord) {
535 el.style.top = "0px";
536 el.style.left = "0px";
537 return;
538 }
539
540 const letterHeight = convertRemToPixels(Config.fontSize);
541 const targetTop =
542 activeWord.getOffsetTop() + letterHeight / 2 - el.offsetHeight / 2 + 1; //+1 for half of border
543
544 if (Config.tapeMode !== "off") {
545 el.style.maxWidth = `${100 - Config.tapeMargin}%`;
546 } else {
547 el.style.maxWidth = "";
548 }
549 if (activeWord.getOffsetWidth() < letterHeight) {
550 el.style.width = `${letterHeight}px`;
551 } else {
552 el.style.width = `${activeWord.getOffsetWidth()}px`;
553 }
554
555 el.style.top = `${targetTop}px`;
556
557 if (Config.tapeMode !== "off") {
558 el.style.left = `${
559 wordsWrapperEl.getOffsetWidth() * (Config.tapeMargin / 100)
560 }px`;
561 } else {
562 if (activeWord.getOffsetWidth() < letterHeight && isTestRightToLeft) {
563 el.style.left = `${activeWord.getOffsetLeft() - letterHeight}px`;
564 } else {
565 el.style.left = `${Math.max(0, activeWord.getOffsetLeft())}px`;
566 }
567 }
568
569 keepWordsInputInTheCenter();
570}
571
572let centeringActiveLine: Promise<void> = Promise.resolve();
573

Callers 2

updateActiveElementFunction · 0.85
updateWordWrapperClassesFunction · 0.85

Calls 7

getInputElementFunction · 0.90
convertRemToPixelsFunction · 0.90
getActiveWordElementFunction · 0.85
getOffsetTopMethod · 0.80
getOffsetWidthMethod · 0.80
getOffsetLeftMethod · 0.80

Tested by

no test coverage detected