summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src
diff options
context:
space:
mode:
authorGorash <chm@odoo.com>2019-07-15 09:26:29 +0000
committerGorash <chm@odoo.com>2019-07-15 09:26:29 +0000
commit2c27d6c9257fbc28d4801a0b32a0b9921c509af5 (patch)
tree412a88f03e56695a6df647264f009d96185210f5 /addons/web_editor/static/src
parent522a0001e7717449538a8f05c003582fe88cfda4 (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) We suspect a wrong snippet custom javascript code. see: https://github.com/odoo/odoo/pull/34188 closes odoo/odoo#34871 Signed-off-by: VincentSchippefilt <VincentSchippefilt@users.noreply.github.com>
Diffstat (limited to 'addons/web_editor/static/src')
-rw-r--r--addons/web_editor/static/src/js/wysiwyg/plugin/helper.js14
-rw-r--r--addons/web_editor/static/src/js/wysiwyg_snippets/wysiwyg_snippets.js20
2 files changed, 29 insertions, 5 deletions
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 1738e6e7b48..d65c91aa682 100644
--- a/addons/web_editor/static/src/js/wysiwyg/plugin/helper.js
+++ b/addons/web_editor/static/src/js/wysiwyg/plugin/helper.js
@@ -1071,14 +1071,18 @@ var HelperPlugin = AbstractPlugin.extend({
If this error appears, the carret is moved to the beginning
of the focused node.*/
console.error(e);
- console.error('Informations for debugging', [
+ var log = [
['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],
- ]);
+ ];
+ if (range) {
+ log.push(
+ ['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]);
+ }
+ console.error('Informations for debugging', log);
}
this.context.invoke('editor.saveRange');
},
diff --git a/addons/web_editor/static/src/js/wysiwyg_snippets/wysiwyg_snippets.js b/addons/web_editor/static/src/js/wysiwyg_snippets/wysiwyg_snippets.js
index c4ee569ae88..a091a9eed90 100644
--- a/addons/web_editor/static/src/js/wysiwyg_snippets/wysiwyg_snippets.js
+++ b/addons/web_editor/static/src/js/wysiwyg_snippets/wysiwyg_snippets.js
@@ -253,6 +253,26 @@ $.fn.extend({
if (this.length) {
Wysiwyg.setRangeFromNode(this[0]);
var range = $.summernote.range.create();
+
+ try {
+ range.so;
+ } 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', [
+ ['elements', this],
+ ['outerHTML', this[0].outerHTML],
+ ['textContent', this[0].textContent],
+ ['html', this.html()],
+ ['previous selection', this.end().html()],
+ ]);
+ }
+
if (!range.sc.tagName && range.so === 0 && range.sc.textContent[range.so] === '\u200B') {
range.so += 1;
}