From e0b906d74db69fce1fec09aa5807fc3863816655 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Fri, 2 Nov 2018 16:54:50 +0000 Subject: [PATCH] [FIX] web_editor: firefox ctrl+a and un/format When we for example do ctrl+a in firefox, the selection is over the container and not the content. This is an issue when we apply a format, since the container could be removed. eg: we have selection over `
hello
`, on firefox the selected node is `pre`, on chromium it is `TextNode "hello"`. if we remove the style, `pre` is deleted so firefox selection is broken, whilst chrome has no issue since "hello" still exist. There was also an issue when the selection was over the blockquote, there was no error but the style could not be removed. opw-1903738 opw-1903735 closes #28369 --- addons/web_editor/static/src/js/editor/summernote.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/addons/web_editor/static/src/js/editor/summernote.js b/addons/web_editor/static/src/js/editor/summernote.js index 36729ff8ed3..b3a5d36009b 100644 --- a/addons/web_editor/static/src/js/editor/summernote.js +++ b/addons/web_editor/static/src/js/editor/summernote.js @@ -1891,6 +1891,15 @@ $.summernote.pluginEvents.formatBlock = function (event, editor, layoutInfo, sTa if (!r) { return; } + // select content since container (that firefox selects) may be removed + if (r.so === 0) { + r.sc = dom.firstChild(r.sc); + } + if (dom.nodeLength(r.ec) >= r.eo) { + r.ec = dom.lastChild(r.ec); + r.eo = dom.nodeLength(r.ec); + } + r = range.create(r.sc, r.so, r.ec, r.eo); r.reRange().select(); if (sTagName === "blockquote" || sTagName === "pre") {