mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
[Editor] Corrrectly get the words from the alt-text when reporting the telemetry (bug 1929311)
This commit is contained in:
parent
f8d11a3a3a
commit
e161826a44
3 changed files with 93 additions and 4 deletions
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue