1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Merge pull request #19155 from calixteman/bug1929311

[Editor] Corrrectly get the words from the alt-text when reporting the telemetry (bug 1929311)
This commit is contained in:
calixteman 2024-12-03 19:27:15 +01:00 committed by GitHub
commit 9a4b7c2612
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 93 additions and 4 deletions

View file

@ -132,7 +132,7 @@ class FakeMLManager {
guess({ request: { data } }) {
return new Promise(resolve => {
setTimeout(() => {
resolve(data ? { output: "Fake alt text" } : { error: true });
resolve(data ? { output: "Fake alt text." } : { error: true });
}, 3000);
});
}

View file

@ -460,6 +460,15 @@ class NewAltTextManager {
this.#uiManager = null;
}
#extractWords(text) {
return new Set(
text
.toLowerCase()
.split(/[^\p{L}\p{N}]+/gu)
.filter(x => !!x)
);
}
#save() {
const altText = this.#textarea.value.trim();
this.#currentEditor.altTextData = {
@ -469,8 +478,8 @@ class NewAltTextManager {
this.#currentEditor.altTextData.guessedAltText = this.#guessedAltText;
if (this.#guessedAltText && this.#guessedAltText !== altText) {
const guessedWords = new Set(this.#guessedAltText.split(/\s+/));
const words = new Set(altText.split(/\s+/));
const guessedWords = this.#extractWords(this.#guessedAltText);
const words = this.#extractWords(altText);
this.#currentEditor._reportTelemetry({
action: "pdfjs.image.alt_text.user_edit",
data: {