[FIX] web_editor: stop showing text tools on empty oe_structure

Do not switch to text tools if the cursor is in an empty oe_structure
(to encourage using snippets there and actually avoid breaking tours
which suppose the snippet list is visible).

Part of https://github.com/odoo/odoo/pull/64088
Related to task-2352339

This commit has been merged twice as it was lost during JW revert.

closes odoo/odoo#64104

X-original-commit: 455f4ec1c5d60d1868f181075ce97a24ee6bc62e
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
qsm-odoo
2021-01-05 17:16:18 +00:00
parent 0283ce986c
commit 73093edc18
@@ -2546,8 +2546,16 @@ var SnippetsMenu = Widget.extend({
if (!this._textToolsSwitchingEnabled) {
return;
}
if (!$.summernote.core.range.create()) {
// Sometimes not enough...
const range = $.summernote.core.range.create();
if (!range) {
return;
}
if (range.sc === range.ec && range.sc.nodeType === Node.ELEMENT_NODE
&& range.sc.classList.contains('oe_structure')
&& range.sc.children.length === 0) {
// Do not switch to text tools if the cursor is in an empty
// oe_structure (to encourage using snippets there and actually
// avoid breaking tours which suppose the snippet list is visible).
return;
}
this.textEditorPanelEl.classList.add('d-block');