Bug 1845152 - [devtools] Make sure the input is focused before triggering keyboard event in setProperty. r=devtools-reviewers,ochameau a=test-only

Differential Revision: https://phabricator.services.mozilla.com/D233821
This commit is contained in:
Nicolas Chevobbe 2025-01-13 14:39:33 +00:00
parent 81d6efa641
commit cd9b1a656c

View file

@ -565,9 +565,7 @@ var focusEditableField = async function (
await onFocus;
info("Editable field gained focus, returning the input field now");
const onEdit = inplaceEditor(editable.ownerDocument.activeElement);
return onEdit;
return inplaceEditor(editable.ownerDocument.activeElement);
};
/**
@ -1083,7 +1081,7 @@ async function setProperty(
{ blurNewProperty = true, flushCount = 1 } = {}
) {
info("Set property to: " + value);
await focusEditableField(ruleView, textProp.editor.valueSpan);
const editor = await focusEditableField(ruleView, textProp.editor.valueSpan);
// Because of the manual flush approach used for tests, we might have an
// unknown number of debounced "preview" requests . Each preview should
@ -1104,6 +1102,11 @@ async function setProperty(
await onPopupOpened;
} else {
await wait(500);
// Since some time have passed since we made the input visible and focused it,
// we might have some previous async work that causes the input to be blurred
// (see intermittent Bug 1845152).
// Make sure the input is focused before triggering the keyboard event.
editor.input.focus();
EventUtils.sendString(value, ruleView.styleWindow);
}
@ -1138,6 +1141,11 @@ async function setProperty(
onPopupClosed = once(ruleView.popup, "popup-closed");
}
// Since some time have passed since we made the input visible and focused it,
// we might have some previous async work that causes the input to be blurred
// (see intermittent Bug 1845152).
// Make sure the input is focused before triggering the keyboard event.
editor.input.focus();
EventUtils.synthesizeKey(
blurNewProperty ? "VK_RETURN" : "VK_TAB",
{},