[FIX] web_editor: avoid dialog error on email edition
Under certain unknown conditions, the range cannot be applied and triggered an error. In order to allow the user to keep editing, we need to prevent the dialog from showing, hence the use of `console.error`. If this error appears, the carret is moved to the beginning of the focused node. If this error appears, then bullet can generate an error (I managed to have the bug once or simulate it by manually breaking the dom and range) closes odoo/odoo#34284 Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
committed by
Nicolas Martinelli
parent
2349cba9c0
commit
82bf73fe30
@@ -47,7 +47,7 @@ var BulletPlugin = AbstractPlugin.extend({
|
||||
res = this._convertList(false, [], start, end, type);
|
||||
} else {
|
||||
var ul = this._createList(type);
|
||||
res = [].slice.call(ul.children);
|
||||
res = ul ? [].slice.call(ul.children) : [];
|
||||
}
|
||||
|
||||
var startLeaf = this.context.invoke('HelperPlugin.firstLeaf', start.node);
|
||||
|
||||
@@ -1047,6 +1047,7 @@ var HelperPlugin = AbstractPlugin.extend({
|
||||
var reAllNBSP = /\u00A0/g;
|
||||
var reMultipleSpace = /(\s){2,}/;
|
||||
|
||||
var textContent = range.sc.textContent;
|
||||
var startBlanks = range.sc.textContent.match(reStartBlanks)[0] || '';
|
||||
var endBlanks = range.sc.textContent.match(reEndBlanks)[0] || '';
|
||||
var trimmed = range.sc.textContent.replace(reStartBlanks, '').replace(reEndBlanks, '');
|
||||
@@ -1060,7 +1061,25 @@ var HelperPlugin = AbstractPlugin.extend({
|
||||
|
||||
this._removeInvisibleChar(range);
|
||||
|
||||
range.select();
|
||||
try {
|
||||
range.select();
|
||||
} catch (e) {
|
||||
/* Under certain unknown conditions, the range cannot be
|
||||
applied and triggered an error. In order to allow the user to
|
||||
keep editing, we need to prevent the dialog from showing, hence
|
||||
the use of `console.error`.
|
||||
If this error appears, the carret is moved to the beginning
|
||||
of the focused node.*/
|
||||
console.error(e);
|
||||
console.error('Informations for debugging', [
|
||||
['textContent', textContent],
|
||||
['trimmed', trimmed],
|
||||
['cleanContents', cleanContents],
|
||||
['start', range.sc.outerHTML || range.sc.textContent, range.so],
|
||||
['end', range.ec.outerHTML || range.ec.textContent, range.eo],
|
||||
['parent', range.sc.parentNode && range.sc.parentNode.outerHTML],
|
||||
]);
|
||||
}
|
||||
this.context.invoke('editor.saveRange');
|
||||
},
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user