Skip to content

Commit 443e27f

Browse files
committed
feat: add composition display setting
1 parent ea37960 commit 443e27f

File tree

9 files changed

+61
-22
lines changed

9 files changed

+61
-22
lines changed

frontend/src/html/pages/settings.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,26 @@
568568
<button data-config-value="true">on</button>
569569
</div>
570570
</div>
571+
<div class="section" data-config-name="compositionDisplay">
572+
<div class="groupTitle">
573+
<i class="fas fa-language"></i>
574+
<span>composition display</span>
575+
<button class="text" tabindex="-1">
576+
<i class="fas fa-fw fa-link"></i>
577+
</button>
578+
</div>
579+
<div class="text">
580+
Change how composition is displayed. "off" will just underline the
581+
letter if composition is active. "below" will show the composed
582+
character below the test. "replace" will replace the letter in the test
583+
with the composed character.
584+
</div>
585+
<div class="buttons">
586+
<button data-config-value="off">off</button>
587+
<button data-config-value="below">below</button>
588+
<button data-config-value="replace">replace</button>
589+
</div>
590+
</div>
571591
<div class="section" data-config-name="lazyMode">
572592
<div class="groupTitle">
573593
<i class="fas fa-couch"></i>

frontend/src/ts/commandline/commandline-metadata.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,11 @@ export const commandlineConfigMetadata: CommandlineConfigMetadataObject = {
323323
options: "fromSchema",
324324
},
325325
},
326+
compositionDisplay: {
327+
subgroup: {
328+
options: "fromSchema",
329+
},
330+
},
326331
hideExtraLetters: {
327332
subgroup: {
328333
options: "fromSchema",

frontend/src/ts/commandline/lists.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export const commands: CommandsSubgroup = {
134134
confidenceModeCommand,
135135
"quickEnd",
136136
"indicateTypos",
137+
"compositionDisplay",
137138
"hideExtraLetters",
138139
lazyModeCommand,
139140
layoutCommand,

frontend/src/ts/config-metadata.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,11 @@ export const configMetadata: ConfigMetadataObject = {
365365
displayString: "indicate typos",
366366
changeRequiresRestart: false,
367367
},
368+
compositionDisplay: {
369+
icon: "fa-language",
370+
displayString: "composition display",
371+
changeRequiresRestart: false,
372+
},
368373
hideExtraLetters: {
369374
icon: "fa-eye-slash",
370375
displayString: "hide extra letters",

frontend/src/ts/constants/default-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const obj: Config = {
4242
funbox: [],
4343
confidenceMode: "off",
4444
indicateTypos: "off",
45+
compositionDisplay: "replace",
4546
timerStyle: "mini",
4647
liveSpeedStyle: "off",
4748
liveAccStyle: "off",

frontend/src/ts/elements/composition-display.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
import Config from "../config";
2-
31
const compositionDisplay = document.getElementById(
42
"compositionDisplay",
53
) as HTMLElement;
64

7-
const languagesToShow = ["korean", "japanese", "chinese"];
8-
9-
export function shouldShow(): boolean {
10-
return languagesToShow.some((lang) => Config.language.startsWith(lang));
11-
}
12-
135
export function update(data: string): void {
146
compositionDisplay.innerText = data;
157
}

frontend/src/ts/test/test-logic.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ import * as Loader from "../elements/loader";
8383
import * as TestInitFailed from "../elements/test-init-failed";
8484
import { canQuickRestart } from "../utils/quick-restart";
8585
import { animate } from "animejs";
86-
import * as CompositionDisplay from "../elements/composition-display";
8786
import {
8887
getInputElement,
8988
isInputElementFocused,
@@ -329,13 +328,6 @@ export function restart(options = {} as RestartOptions): void {
329328
getInputElement().style.left = "0";
330329
setInputElementValue("");
331330

332-
if (CompositionDisplay.shouldShow()) {
333-
CompositionDisplay.update(" ");
334-
CompositionDisplay.show();
335-
} else {
336-
CompositionDisplay.hide();
337-
}
338-
339331
Focus.set(false);
340332
if (ActivePage.get() === "test") {
341333
AdController.updateFooterAndVerticalAds(false);
@@ -381,8 +373,9 @@ export function restart(options = {} as RestartOptions): void {
381373
if (isInputElementFocused()) OutOfFocus.hide();
382374
TestUI.focusWords(true);
383375

384-
const typingTestEl = document.querySelector("#typingTest") as HTMLElement;
376+
TestUI.onTestRestart();
385377

378+
const typingTestEl = document.querySelector("#typingTest") as HTMLElement;
386379
animate(typingTestEl, {
387380
opacity: [0, 1],
388381
onBegin: () => {

frontend/src/ts/test/test-ui.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
} from "../input/input-element";
5050
import * as MonkeyPower from "../elements/monkey-power";
5151
import * as SlowTimer from "../states/slow-timer";
52+
import * as CompositionDisplay from "../elements/composition-display";
5253

5354
const debouncedZipfCheck = debounce(250, async () => {
5455
const supports = await JSONData.checkIfLanguageSupportsZipf(Config.language);
@@ -89,10 +90,9 @@ ConfigEvent.subscribe((eventKey, eventValue, nosave) => {
8990
debouncedZipfCheck();
9091
}
9192
if (eventKey === "fontSize") {
92-
$("#caret, #paceCaret, #liveStatsMini, #typingTest, #wordsInput").css(
93-
"fontSize",
94-
(eventValue as number) + "rem",
95-
);
93+
$(
94+
"#caret, #paceCaret, #liveStatsMini, #typingTest, #wordsInput, #compositionDisplay",
95+
).css("fontSize", (eventValue as number) + "rem");
9696
if (!nosave) {
9797
OutOfFocus.hide();
9898
updateWordWrapperClasses();
@@ -880,7 +880,7 @@ export async function updateWordLetters({
880880
let charToShow =
881881
currentWordChars[input.length + i] ?? compositionChar;
882882

883-
if (Config.indicateTypos === "replace") {
883+
if (Config.compositionDisplay === "replace") {
884884
charToShow = compositionChar === " " ? "_" : compositionChar;
885885
}
886886

@@ -1919,6 +1919,15 @@ export function afterTestStart(): void {
19191919
TimerProgress.update();
19201920
}
19211921

1922+
export function onTestRestart(): void {
1923+
if (Config.compositionDisplay === "below") {
1924+
CompositionDisplay.update(" ");
1925+
CompositionDisplay.show();
1926+
} else {
1927+
CompositionDisplay.hide();
1928+
}
1929+
}
1930+
19221931
$(".pageTest #copyWordsListButton").on("click", async () => {
19231932
let words;
19241933
if (Config.mode === "zen") {
@@ -2043,4 +2052,12 @@ ConfigEvent.subscribe((key, value) => {
20432052
if (key === "showOutOfFocusWarning" && value === false) {
20442053
OutOfFocus.hide();
20452054
}
2055+
if (key === "compositionDisplay") {
2056+
if (value === "below") {
2057+
CompositionDisplay.update(" ");
2058+
CompositionDisplay.show();
2059+
} else {
2060+
CompositionDisplay.hide();
2061+
}
2062+
}
20462063
});

packages/schemas/src/configs.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ export type ConfidenceMode = z.infer<typeof ConfidenceModeSchema>;
5454
export const IndicateTyposSchema = z.enum(["off", "below", "replace", "both"]);
5555
export type IndicateTypos = z.infer<typeof IndicateTyposSchema>;
5656

57+
export const CompositionDisplaySchema = z.enum(["off", "below", "replace"]);
58+
export type CompositionDisplay = z.infer<typeof CompositionDisplaySchema>;
59+
5760
export const TimerStyleSchema = z.enum([
5861
"off",
5962
"bar",
@@ -408,6 +411,7 @@ export const ConfigSchema = z
408411
confidenceMode: ConfidenceModeSchema,
409412
quickEnd: z.boolean(),
410413
indicateTypos: IndicateTyposSchema,
414+
compositionDisplay: CompositionDisplaySchema,
411415
hideExtraLetters: z.boolean(),
412416
lazyMode: z.boolean(),
413417
layout: LayoutSchema,
@@ -544,6 +548,7 @@ export const ConfigGroupsLiteral = {
544548
confidenceMode: "input",
545549
quickEnd: "input",
546550
indicateTypos: "input",
551+
compositionDisplay: "input",
547552
hideExtraLetters: "input",
548553
lazyMode: "input",
549554
layout: "input",

0 commit comments

Comments
 (0)