Skip to content

Commit

Permalink
fix: copy words command not working (fehmer) (#5400)
Browse files Browse the repository at this point in the history
  • Loading branch information
fehmer committed May 20, 2024
1 parent 85502ea commit 65dffce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 44 deletions.
47 changes: 19 additions & 28 deletions frontend/src/ts/commandline/lists/result-screen.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
import * as TestLogic from "../../test/test-logic";
import * as TestUI from "../../test/test-ui";
import * as PractiseWords from "../../test/practise-words";
import * as GetText from "../../utils/generate";
import * as Notifications from "../../elements/notifications";

const copyWords: MonkeyTypes.CommandsSubgroup = {
title: "Are you sure...",
list: [
{
id: "copyNo",
display: "Nevermind",
},
{
id: "copyYes",
display: "Yes, I am sure",
exec: (): void => {
const words = GetText.getWords();

navigator.clipboard.writeText(words).then(
() => {
Notifications.add("Copied to clipboard", 1);
},
() => {
Notifications.add("Failed to copy!", -1);
}
);
},
},
],
};
import * as TestInput from "../../test/test-input";
import * as TestWords from "../../test/test-words";
import Config from "../../config";

const practiceSubgroup: MonkeyTypes.CommandsSubgroup = {
title: "Practice words...",
Expand Down Expand Up @@ -130,7 +106,22 @@ const commands: MonkeyTypes.Command[] = [
id: "copyWordsToClipboard",
display: "Copy words to clipboard",
icon: "fa-copy",
subgroup: copyWords,
exec: (): void => {
const words = (
Config.mode === "zen"
? TestInput.input.history
: TestWords.words.list.slice(0, TestInput.input.history.length)
).join(" ");

navigator.clipboard.writeText(words).then(
() => {
Notifications.add("Copied to clipboard", 1);
},
() => {
Notifications.add("Failed to copy!", -1);
}
);
},
available: (): boolean => {
return TestUI.resultVisible;
},
Expand Down
16 changes: 0 additions & 16 deletions frontend/src/ts/utils/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,6 @@ export function getGibberish(): string {
return ret;
}

/**
* Retrieves the words from the HTML elements with IDs "words" and returns them as a string.
* @returns The words extracted from the HTML elements.
*/
export function getWords(): string {
const words = [...document.querySelectorAll("#words .word")]
.map((word) => {
return [...word.querySelectorAll("letter")]
.map((letter) => letter.textContent)
.join("");
})
.join(" ");

return words;
}

/**
* Generates a random ASCII string of printable characters.
* @returns The generated ASCII string.
Expand Down

0 comments on commit 65dffce

Please sign in to comment.