From b128d3a5a298eb656c272003c2b57546d25e3746 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Fri, 28 Jul 2023 12:15:50 +0200 Subject: [PATCH] [IMP] web_editor: add label to prepareUpdate This adds a label to the prepareUpdate function to be able to easily track which update is being restored when debugging. X-original-commit: 5bb8a5a9b5d54ebe93c473087981e3464cd61368 Part-of: odoo/odoo#138549 --- .../static/src/js/editor/odoo-editor/src/OdooEditor.js | 5 ++++- .../static/src/js/editor/odoo-editor/src/utils/utils.js | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js index 4202559c3f8..1ad2cd47eb1 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js @@ -2082,7 +2082,10 @@ export class OdooEditor extends EventTarget { splitTextNode(start, startOffset); startOffset = 0; } - const restoreUpdate = prepareUpdate(...boundariesOut(start).slice(0, 2), ...boundariesOut(end).slice(2, 4), { allowReenter: false }); + const restoreUpdate = prepareUpdate( + ...boundariesOut(start).slice(0, 2), + ...boundariesOut(end).slice(2, 4), + { allowReenter: false, label: 'deleteRange' }); // Let the DOM split and delete the range. const contents = range.extractContents(); diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js index 868347ea553..f9adfd3e6cb 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js @@ -2080,13 +2080,16 @@ const prepareUpdateLockedEditables = new Set(); * @param {Object} [options] * @param {boolean} [options.allowReenter = true] - if false, all calls to * prepareUpdate before this one gets restored will be ignored. + * @param {string} [options.label = ] * @returns {function} */ export function prepareUpdate(...args) { const closestRoot = args.length && ancestors(args[0]).find(ancestor => ancestor.oid === 'root'); const isPrepareUpdateLocked = closestRoot && prepareUpdateLockedEditables.has(closestRoot); + const hash = (Math.random() + 1).toString(36).substring(7); const options = { allowReenter: true, + label: hash, ...(args.length && args[args.length - 1] instanceof Object ? args.pop() : {}), }; if (isPrepareUpdateLocked) {