1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

[Annotation] Send correctly the updated values to the JS sandbox

This commit is contained in:
Calixte Denizet 2022-11-29 16:37:02 +01:00
parent ff9d21ff0e
commit 20fd9099f8
4 changed files with 65 additions and 5 deletions

View file

@ -1065,7 +1065,7 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
const elementData = {
userValue: textContent,
formattedValue: null,
valueOnFocus: "",
lastCommittedValue: null,
};
if (this.data.multiLine) {
@ -1122,10 +1122,11 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
if (this.enableScripting && this.hasJSActions) {
element.addEventListener("focus", event => {
const { target } = event;
if (elementData.userValue) {
event.target.value = elementData.userValue;
target.value = elementData.userValue;
}
elementData.valueOnFocus = event.target.value;
elementData.lastCommittedValue = target.value;
});
element.addEventListener("updatefromsandbox", jsEvent => {
@ -1207,9 +1208,10 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
return;
}
const { value } = event.target;
if (elementData.valueOnFocus === value) {
if (elementData.lastCommittedValue === value) {
return;
}
elementData.lastCommittedValue = value;
// Save the entered value
elementData.userValue = value;
this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
@ -1230,7 +1232,10 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
element.addEventListener("blur", event => {
const { value } = event.target;
elementData.userValue = value;
if (this._mouseState.isDown && elementData.valueOnFocus !== value) {
if (
this._mouseState.isDown &&
elementData.lastCommittedValue !== value
) {
// Focus out using the mouse: data are committed
this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
source: this,
@ -1250,6 +1255,7 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
if (this.data.actions?.Keystroke) {
element.addEventListener("beforeinput", event => {
elementData.lastCommittedValue = null;
const { data, target } = event;
const { value, selectionStart, selectionEnd } = target;