Skip to content

Commit

Permalink
impr(max line width): setting the value to 0 will now always align th…
Browse files Browse the repository at this point in the history
…e words to the width of the container
  • Loading branch information
Miodec committed Apr 30, 2024
1 parent db8b20f commit 7f04503
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 27 deletions.
2 changes: 1 addition & 1 deletion backend/src/api/schemas/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const CONFIG_SCHEMA = joi.object({
britishEnglish: joi.boolean(),
lazyMode: joi.boolean(),
showAverage: joi.string().valid("off", "speed", "acc", "both"),
maxLineWidth: joi.number().min(20).max(1000),
maxLineWidth: joi.number().min(20).max(1000).allow(0),
});

export default CONFIG_SCHEMA;
3 changes: 2 additions & 1 deletion frontend/src/html/pages/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -900,14 +900,15 @@
</div>
<div class="text">
Change the maximum width of the typing test, measured in characters.
Setting this to 0 will align the words to the edges of the content area.
</div>
<div class="inputs">
<div class="inputAndButton">
<input
type="number"
placeholder="max line width"
class="input"
min="20"
min="0"
/>
<button class="save no-auto-handle">
<i class="fas fa-save fa-fw"></i>
Expand Down
1 change: 0 additions & 1 deletion frontend/src/styles/test.scss
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@

#typingTest {
position: relative;
max-width: 70ch;
width: 100%;
margin: 0 auto;
}
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 @@ -1669,7 +1669,7 @@ export function setMaxLineWidth(
return false;
}

if (maxLineWidth < 20) {
if (maxLineWidth < 20 && maxLineWidth !== 0) {
maxLineWidth = 20;
}
if (maxLineWidth > 1000) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/constants/default-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,5 @@ export default {
lazyMode: false,
showAverage: "off",
tapeMode: "off",
maxLineWidth: 70,
maxLineWidth: 0,
} as SharedTypes.Config;
56 changes: 34 additions & 22 deletions frontend/src/ts/test/test-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ export function showWords(): void {

$("#words").html(wordsHTML);

updateWordsWidth();
updateWordsHeight(true);
updateActiveElement(undefined, true);
void Caret.updatePosition();
Expand Down Expand Up @@ -1407,6 +1408,38 @@ export function highlightMode(mode?: SharedTypes.Config.HighlightMode): void {
$("#words").attr("class", existing.join(" "));
}

function updateWordsWidth(): void {
let css: Record<string, string> = {};
if (Config.tapeMode === "off") {
if (Config.maxLineWidth === 0) {
css = {
"max-width": "100%",
};
} else {
css = {
"max-width": Config.maxLineWidth + "ch",
};
}
} else {
if (Config.maxLineWidth === 0) {
css = {
"max-width": "100%",
};
} else {
css = {
"max-width": "100%",
};
}
}
const el = $("#typingTest");
el.css(css);
if (Config.maxLineWidth === 0) {
el.removeClass("full-width-padding").addClass("content");
} else {
el.removeClass("content").addClass("full-width-padding");
}
}

$(".pageTest").on("click", "#saveScreenshotButton", () => {
void screenshot();
});
Expand Down Expand Up @@ -1528,28 +1561,7 @@ ConfigEvent.subscribe((key, value) => {
$(".pageTest #restartTestButton").addClass("hidden");
}
}
if (key === "tapeMode") {
if (value === "off") {
$("#typingTest").css({
"max-width": Config.maxLineWidth + "ch",
});
$("#miniTimerAndLiveWpm").css({
"grid-column": "full-width",
});
} else {
$("#typingTest").css({
"max-width": "100%",
});
$("#miniTimerAndLiveWpm").css({
"grid-column": "content",
});
}
}
if (key === "maxLineWidth") {
if (Config.tapeMode === "off") {
$("#typingTest").css({
"max-width": Config.maxLineWidth + "ch",
});
}
updateWordsWidth();
}
});

0 comments on commit 7f04503

Please sign in to comment.