fix: copy words command not working (fehmer) (#5400)

This commit is contained in:
Christian Fehmer 2024-05-20 11:46:34 +02:00 committed by GitHub
parent 85502eae53
commit 65dffce716
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 44 deletions

View file

@ -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...",
@ -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;
},

View file

@ -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.