Merge pull request #15764 from calixteman/15753

[Annotation] Send correctly the updated values to the JS sandbox
This commit is contained in:
calixteman 2022-11-29 20:04:12 +01:00 committed by GitHub
commit f3206b351f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 5 deletions

View file

@ -1057,7 +1057,7 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
const elementData = {
userValue: textContent,
formattedValue: null,
valueOnFocus: "",
lastCommittedValue: null,
};
if (this.data.multiLine) {
@ -1114,10 +1114,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 => {
@ -1199,9 +1200,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", {
@ -1222,7 +1224,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,
@ -1242,6 +1247,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;