Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impr(tape mode): support RTL languages (@NadAlaba) #5748

Draft
wants to merge 40 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1efd175
impr(tape mode): show next line if test has newlines (@NadAlaba)
NadAlaba Sep 5, 2024
2a0c4a4
Merge branch 'master' into tapeMode-newline
NadAlaba Sep 10, 2024
0191df2
re-add nlChar width to afterNewline margin
NadAlaba Sep 13, 2024
2dab48a
Merge branch 'master' into tapeMode-newline
NadAlaba Sep 13, 2024
905b9aa
animate next line shifting when extra letters are typed
NadAlaba Sep 13, 2024
550eb61
Merge branch 'master' into tapeMode-newline
NadAlaba Sep 13, 2024
b021237
only last leading .afterNewline element pushes .words to right
NadAlaba Sep 13, 2024
52688bf
don't hide words after active word
NadAlaba Sep 14, 2024
d9b3b5a
revert last commit
NadAlaba Sep 14, 2024
c34d109
Merge branch 'master' into tapeMode-newline
NadAlaba Sep 18, 2024
1fdc388
Merge branch 'master' into tapeMode-newline
NadAlaba Sep 21, 2024
bb9a510
split updateWordsHeight() and move css changes to test.scss
NadAlaba Sep 21, 2024
615b661
don't remove elements in scrollTape until after the margins are set
NadAlaba Sep 21, 2024
d6dbd99
change naming (hide -> remove)
NadAlaba Sep 21, 2024
a33821b
show 3 lines in tape mode
NadAlaba Sep 21, 2024
63c5da2
refactor updateWordsWrapperHeight()
NadAlaba Sep 21, 2024
9fbef47
add comment
NadAlaba Sep 21, 2024
d88a08f
allow Config.showAllLines change without restart
NadAlaba Sep 21, 2024
23cf24f
remove console.log/trace
NadAlaba Sep 21, 2024
a1c824d
make wordsWrapper's height auto with a max-height of 3 lines
NadAlaba Sep 26, 2024
c7f0ccd
Merge branch 'master' into tapeMode-newline
NadAlaba Sep 26, 2024
30b8ef2
split updateWordsHeight() and move some style changes to .scss files
NadAlaba Sep 26, 2024
d9ba967
revert the max-height commit and align .beforeNewline.offsetTOp with …
NadAlaba Sep 26, 2024
2e6323f
Merge branch 'words-height' into tapeMode-newline
NadAlaba Sep 26, 2024
77008c8
forgot .afterNewline
NadAlaba Sep 26, 2024
8139c75
fix min height instead of height
NadAlaba Sep 26, 2024
2a67b00
center outOfFocusWarning in css when it's possible
NadAlaba Sep 26, 2024
670c2e6
Merge branch 'words-height' into tapeMode-newline
NadAlaba Sep 26, 2024
1e9487b
forgot to set #words.margin before removing elements at the first scr…
NadAlaba Sep 26, 2024
d1ca1a5
Merge remote-tracking branch 'upstream/master' into words-height
NadAlaba Mar 4, 2025
da1e8a8
make wrapper height in zen mode less jumpy
NadAlaba Mar 5, 2025
74b14a1
Merge branch 'master' into words-height
NadAlaba Mar 5, 2025
34bb81d
reduce delay when unsetting words left margin
NadAlaba Mar 5, 2025
c609c85
Merge branch 'words-height' into tapeMode-newline
NadAlaba Mar 5, 2025
aa46b73
typo
NadAlaba Mar 5, 2025
47acd1b
better way to handle browser scrolling on window resize
NadAlaba Mar 5, 2025
a884a97
make wrapper height changes less jumpy in show all lines + zen
NadAlaba Mar 5, 2025
41df4fb
Merge branch 'master' into words-height
NadAlaba Mar 5, 2025
1a3acde
Merge branch 'words-height' into tapeMode-newline
NadAlaba Mar 5, 2025
5a01c97
impr(tape mode): support RTL languages (@NadAlaba)
NadAlaba Sep 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions frontend/src/styles/test.scss
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,23 @@
}
}

&.tape .word {
margin: 0.25em 0.6em 0.75em 0;
white-space: nowrap;
&.tape {
display: block;
text-wrap: nowrap;
width: 200vw;
.word {
margin: 0.25em 0.6em 0.25em 0;
display: inline-block;
vertical-align: top;
}
.beforeNewline {
display: inline-block;
vertical-align: top;
margin: 0.25em 0;
}
.afterNewline {
display: inline-block;
}
}

/* a little hack for right-to-left languages */
Expand Down Expand Up @@ -462,13 +476,13 @@
display: inline-block;
}

&.lastbeforenewline::after {
font-family: "Font Awesome";
font-weight: 600;
content: "\f107";
margin-left: 0.5rem;
opacity: 0.25;
}
//&.lastbeforenewline::after {
// font-family: "Font Awesome";
// font-weight: 600;
// content: "\f107";
// margin-left: 0.5rem;
// opacity: 0.25;
//}

.wordInputHighlight {
opacity: 1;
Expand Down Expand Up @@ -564,9 +578,9 @@
pointer-events: none;
top: -2.5rem;

&.focus {
// top: 0rem;
}
//&.focus {
// top: 0rem;
//}

i {
margin-right: 0.5rem;
Expand Down Expand Up @@ -1181,7 +1195,9 @@
.pageTest {
#wordsWrapper {
position: relative;
overflow: visible clip;
&.tape {
overflow: hidden;
-webkit-mask-image: linear-gradient(
90deg,
rgba(0, 0, 0, 0) 1%,
Expand Down Expand Up @@ -1220,7 +1236,8 @@
}
.outOfFocusWarning {
text-align: center;
height: 0;
height: 100%;
align-content: center;
font-size: 1rem;
z-index: 999;
position: absolute;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ export function setTapeMargin(
}

if (
!isConfigValueValid("max line width", value, ConfigSchemas.TapeMarginSchema)
!isConfigValueValid("tape margin", value, ConfigSchemas.TapeMarginSchema)
) {
return false;
}
Expand Down
51 changes: 27 additions & 24 deletions frontend/src/ts/controllers/input-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function updateUI(): void {
}
}

function backspaceToPrevious(): void {
async function backspaceToPrevious(): Promise<void> {
if (!TestState.isActive) return;

if (
Expand Down Expand Up @@ -155,7 +155,7 @@ function backspaceToPrevious(): void {
}
TestState.decreaseActiveWordIndex();
TestUI.setActiveWordElementIndex(TestUI.activeWordElementIndex - 1);
TestUI.updateActiveElement(true);
await TestUI.updateActiveElement(true);
Funbox.toggleScript(TestWords.words.getCurrent());
void TestUI.updateActiveWordLetters();

Expand Down Expand Up @@ -335,33 +335,36 @@ async function handleSpace(): Promise<void> {
}
}
TestUI.setActiveWordElementIndex(TestUI.activeWordElementIndex + 1);
TestUI.updateActiveElement();
await TestUI.updateActiveElement();
void Caret.updatePosition();

if (
!Config.showAllLines ||
const shouldLimitToThreeLines =
Config.mode === "time" ||
(Config.mode === "custom" && CustomText.getLimitValue() === 0) ||
(Config.mode === "custom" && CustomText.getLimitMode() === "time")
) {
const currentTop: number = Math.floor(
(Config.mode === "custom" && CustomText.getLimitMode() === "time") ||
(Config.mode === "custom" && CustomText.getLimitValue() === 0);

const currentTop: number = Math.floor(
document.querySelectorAll<HTMLElement>("#words .word")[
TestUI.activeWordElementIndex - 1
]?.offsetTop ?? 0
);
let nextTop: number;
try {
nextTop = Math.floor(
document.querySelectorAll<HTMLElement>("#words .word")[
TestUI.activeWordElementIndex - 1
TestUI.activeWordElementIndex
]?.offsetTop ?? 0
);
let nextTop: number;
try {
nextTop = Math.floor(
document.querySelectorAll<HTMLElement>("#words .word")[
TestUI.activeWordElementIndex
]?.offsetTop ?? 0
);
} catch (e) {
nextTop = 0;
}
} catch (e) {
nextTop = 0;
}

if (nextTop > currentTop) {
if (nextTop > currentTop) {
if (!Config.showAllLines || shouldLimitToThreeLines) {
TestUI.lineJump(currentTop);
} else if (Config.mode === "zen") {
// this makes wrapper height changes less jumpy in zen+showAllLines
TestUI.updateWordsWrapperHeight();
}
} //end of line wrap

Expand Down Expand Up @@ -1067,7 +1070,7 @@ $(document).on("keydown", async (event) => {
}

if (event.key === "Backspace" && TestInput.input.current.length === 0) {
backspaceToPrevious();
await backspaceToPrevious();
if (TestInput.input.current) {
setWordsInput(" " + TestInput.input.current + " ");
}
Expand Down Expand Up @@ -1266,7 +1269,7 @@ $("#wordsInput").on("beforeinput", (event) => {
}
});

$("#wordsInput").on("input", (event) => {
$("#wordsInput").on("input", async (event) => {
if (!event.originalEvent?.isTrusted || TestUI.testRestarting) {
(event.target as HTMLInputElement).value = " ";
return;
Expand Down Expand Up @@ -1335,7 +1338,7 @@ $("#wordsInput").on("input", (event) => {

if (realInputValue.length === 0 && currTestInput.length === 0) {
// fallback for when no Backspace keydown event (mobile)
backspaceToPrevious();
await backspaceToPrevious();
} else if (inputValue.length < currTestInput.length) {
if (containsChinese) {
if (
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/ts/test/caret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,17 @@ function getTargetPositionLeft(

if (Config.tapeMode === "word" && inputLen > 0) {
let currentWordWidth = 0;
let lastPositiveLetterWidth = 0;
for (let i = 0; i < inputLen; i++) {
if (invisibleExtraLetters && i >= wordLen) break;
currentWordWidth +=
$(currentWordNodeList[i] as HTMLElement).outerWidth(true) ?? 0;
const letterOuterWidth =
$(currentWordNodeList[i] as Element).outerWidth(true) ?? 0;
currentWordWidth += letterOuterWidth;
if (letterOuterWidth > 0) lastPositiveLetterWidth = letterOuterWidth;
}
// if current letter has zero width move the caret to previous positive width letter
if ($(currentWordNodeList[inputLen] as Element).outerWidth(true) === 0)
currentWordWidth -= lastPositiveLetterWidth;
if (isLanguageRightToLeft) currentWordWidth *= -1;
result += currentWordWidth;
}
Expand Down
10 changes: 1 addition & 9 deletions frontend/src/ts/test/test-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,6 @@ export async function init(): Promise<void> {
}
}

if (Config.tapeMode !== "off" && language.rightToLeft) {
Notifications.add("This language does not support tape mode.", 0, {
important: true,
});
UpdateConfig.setTapeMode("off");
}

const allowLazyMode = !language.noLazyMode || Config.mode === "custom";
if (Config.lazyMode && !allowLazyMode) {
rememberLazyMode = true;
Expand Down Expand Up @@ -518,7 +511,7 @@ export async function init(): Promise<void> {
Funbox.toggleScript(TestWords.words.getCurrent());
TestUI.setRightToLeft(language.rightToLeft);
TestUI.setLigatures(language.ligatures ?? false);
TestUI.showWords();
await TestUI.showWords();
console.debug("Test initialized with words", generatedWords);
console.debug(
"Test initialized with section indexes",
Expand Down Expand Up @@ -1424,7 +1417,6 @@ ConfigEvent.subscribe((eventKey, eventValue, nosave) => {
restart();
}
if (eventKey === "difficulty" && !nosave) restart();
if (eventKey === "showAllLines" && !nosave) restart();
if (
eventKey === "customLayoutFluid" &&
Config.funbox.includes("layoutfluid")
Expand Down
Loading