summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js
diff options
context:
space:
mode:
authorGorash <chm@odoo.com>2019-06-17 13:52:21 +0000
committerNicolas Martinelli <nim@odoo.com>2019-06-20 13:25:37 +0000
commit82bf73fe3049978d5fa0b6984e129c5aa2870d95 (patch)
tree39d3fc0df9e2e9eaa1e5d5237a615d9ea80954bd /addons/web_editor/static/src/js
parent2349cba9c02ba46469fcd5e4a54659985da4fa21 (diff)
[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>
Diffstat (limited to 'addons/web_editor/static/src/js')
-rw-r--r--addons/web_editor/static/src/js/wysiwyg/plugin/bullet.js2
-rw-r--r--addons/web_editor/static/src/js/wysiwyg/plugin/helper.js21
2 files changed, 21 insertions, 2 deletions
diff --git a/addons/web_editor/static/src/js/wysiwyg/plugin/bullet.js b/addons/web_editor/static/src/js/wysiwyg/plugin/bullet.js
index 6a516dd2ad5..1d5c2d47a33 100644
--- a/addons/web_editor/static/src/js/wysiwyg/plugin/bullet.js
+++ b/addons/web_editor/static/src/js/wysiwyg/plugin/bullet.js
@@ -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);
diff --git a/addons/web_editor/static/src/js/wysiwyg/plugin/helper.js b/addons/web_editor/static/src/js/wysiwyg/plugin/helper.js
index 521afe6137a..a025d6a0082 100644
--- a/addons/web_editor/static/src/js/wysiwyg/plugin/helper.js
+++ b/addons/web_editor/static/src/js/wysiwyg/plugin/helper.js
@@ -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');
},
/**