[FIX] web_editor: fix inline html_field
Revert changes made in #101768. Wrong assumption were made in #101768 regarding inline conversion of html field. I though Inline HTML field always had two Field, one for the raw content and one for the inlined content. This is not correct. Some only have one (i.e. email templates). They override the raw version and save the inline version directly. In those case the inlining was not saved and was always reverted before saving. This error is corrected here. task-3222474 X-original-commit: 578600c506fab1461863decdaecaa414f6530eab Part-of: odoo/odoo#124020
This commit is contained in:
@@ -570,8 +570,6 @@ export class HtmlField extends Component {
|
||||
const html = this.wysiwyg.getValue();
|
||||
const $odooEditor = $editable.closest('.odoo-editor-editable');
|
||||
// Save correct nodes references.
|
||||
const originalContents = document.createDocumentFragment();
|
||||
originalContents.append(...$editable[0].childNodes);
|
||||
// Remove temporarily the class so that css editing will not be converted.
|
||||
$odooEditor.removeClass('odoo-editor-editable');
|
||||
$editable.html(html);
|
||||
@@ -579,7 +577,8 @@ export class HtmlField extends Component {
|
||||
await toInline($editable, this.cssRules, this.wysiwyg.$iframe);
|
||||
$odooEditor.addClass('odoo-editor-editable');
|
||||
|
||||
$editable[0].replaceChildren(...originalContents.childNodes);
|
||||
this.wysiwyg.setValue($editable.html());
|
||||
this.wysiwyg.odooEditor.sanitize(this.wysiwyg.odooEditor.editable);
|
||||
}
|
||||
async _getWysiwygClass() {
|
||||
return getWysiwygClass();
|
||||
|
||||
@@ -707,7 +707,7 @@ export class OdooEditor extends EventTarget {
|
||||
resetContent(value) {
|
||||
value = value || '<p><br></p>';
|
||||
this.editable.innerHTML = value;
|
||||
this.sanitize();
|
||||
this.sanitize(this.editable);
|
||||
this.historyStep(true);
|
||||
// The unbreakable protection mechanism detects an anomaly and attempts
|
||||
// to trigger a rollback when the content is reset using `innerHTML`.
|
||||
@@ -719,17 +719,22 @@ export class OdooEditor extends EventTarget {
|
||||
}
|
||||
}
|
||||
|
||||
sanitize() {
|
||||
sanitize(target) {
|
||||
this.observerFlush();
|
||||
|
||||
let commonAncestor, record;
|
||||
for (record of this._currentStep.mutations) {
|
||||
const node = this.idFind(record.parentId || record.id) || this.editable;
|
||||
commonAncestor = commonAncestor
|
||||
? commonParentGet(commonAncestor, node, this.editable)
|
||||
: node;
|
||||
let record;
|
||||
if (!target) {
|
||||
// If the target is not given,
|
||||
// find the closest common ancestor to all the nodes referenced
|
||||
// in the mutations from the last step.
|
||||
for (record of this._currentStep.mutations) {
|
||||
const node = this.idFind(record.parentId || record.id) || this.editable;
|
||||
target = target
|
||||
? commonParentGet(target, node, this.editable)
|
||||
: node;
|
||||
}
|
||||
}
|
||||
if (!commonAncestor) {
|
||||
if (!target) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -741,15 +746,16 @@ export class OdooEditor extends EventTarget {
|
||||
// <li class="oe-nested"><ul>...</ul></li>
|
||||
// </ol>: these two lists should be merged together so the common
|
||||
// ancestor should be the <ol> element).
|
||||
const nestedListAncestor = closestElement(commonAncestor, '.oe-nested');
|
||||
const nestedListAncestor = closestElement(target, '.oe-nested');
|
||||
if (nestedListAncestor && nestedListAncestor.parentElement) {
|
||||
commonAncestor = nestedListAncestor.parentElement;
|
||||
target = nestedListAncestor.parentElement;
|
||||
}
|
||||
|
||||
// sanitize and mark current position as sanitized
|
||||
sanitize(commonAncestor);
|
||||
this._pluginCall('sanitizeElement', [commonAncestor]);
|
||||
this.options.onPostSanitize(commonAncestor);
|
||||
sanitize(target);
|
||||
this._pluginCall('sanitizeElement',
|
||||
[target.parentElement]);
|
||||
this.options.onPostSanitize(target);
|
||||
}
|
||||
|
||||
addDomListener(element, eventName, callback) {
|
||||
|
||||
Reference in New Issue
Block a user