[IMP] web_editor: apply custom font size as rem

This commit permits to apply custom font size as rem instead of px. The
users still use px to define and to read the font size but the editor
will convert it to rem.

task-1958098

Part-of: odoo/odoo#129791
Co-authored-by: qsm-odoo <qsm@odoo.com>
This commit is contained in:
Guillaume (gdi)
2023-10-19 19:08:11 +00:00
committed by qsm-odoo
co-authored by qsm-odoo
parent c32e7b27fe
commit 97b14eef9b
@@ -742,6 +742,12 @@ export class OdooEditor extends EventTarget {
}
});
const applyFontSizeREM = pxStrValue => {
const pxValue = parseFloat(pxStrValue);
const remValue = this.options.convertNumericToUnit(pxValue, "px", "rem");
this.execCommand("setFontSize", `${remValue}rem`);
};
// Handle the font size input.
if (fontSizeInput) {
const debouncedOnInputChange = (() => {
@@ -755,7 +761,7 @@ export class OdooEditor extends EventTarget {
if (!this.isSelectionInEditable()) {
this.historyResetLatestComputedSelection(true);
}
this.execCommand("setFontSize", `${fontSize}px`);
applyFontSizeREM(fontSize);
fontSizeInput.blur();
}
resolve();
@@ -779,7 +785,7 @@ export class OdooEditor extends EventTarget {
this.execCommand("setFontSize", undefined);
this.execCommand("setFontSizeClassName", fontSizeClassName);
} else {
this.execCommand("setFontSize", `${optionEl.dataset.value}px`);
applyFontSizeREM(optionEl.dataset.value);
}
};
fontSizeDropdown.querySelectorAll('.dropdown-item').forEach(item => {