[FIX] web_editor: avoid contenteditable reset when doing link isolation

Reproduction:

1. install website, drag a block with button
2. click at the beginning of the button text
3. type something, it will be outside of the button area

Reason:
The contenteditable is reset depending on the o_editable and
o_not_editable class in the _onPostSanitize function.

Fix: don’t do the resetting when we have the _fixLinkMutatedElements key
in OdooEditor as it indicates that the link isolation trick is executing

task-3514628

closes odoo/odoo#139030

X-original-commit: 1727317f258d184432b01b6295d01f688e298257
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
Co-authored-by: Nicolas Bayet <nby@odoo.com>
This commit is contained in:
Jinjiu Liu
2023-10-18 13:39:21 +00:00
co-authored by Nicolas Bayet
parent 00c2f50019
commit 9ed20a5260
2 changed files with 4 additions and 3 deletions
@@ -1923,14 +1923,14 @@ export class OdooEditor extends EventTarget {
setContenteditableLink(link) {
const editableChildren = link.querySelectorAll('[contenteditable=true]');
this._stopContenteditable();
this._fixLinkMutatedElements = {
link,
wasContenteditableTrue: [...editableChildren],
wasContenteditableFalse: [],
wasContenteditableNull: [],
};
this._stopContenteditable();
const contentEditableAttribute = link.getAttribute('contenteditable');
if (contentEditableAttribute === 'true') {
this._fixLinkMutatedElements.wasContenteditableTrue.push(link);
@@ -3201,7 +3201,8 @@ export class Wysiwyg extends Component {
* @param {Node} node
*/
_onPostSanitize(node) {
if (node?.querySelectorAll) {
// _fixLinkMutatedElements check to be removed after the new link edge soltion is merged.
if (node?.querySelectorAll && this.odooEditor && !this.odooEditor._fixLinkMutatedElements) {
for (const element of node.querySelectorAll('.o_editable, .o_not_editable')) {
const editable = element.classList.contains('o_editable');
if (element.isContentEditable !== editable) {