[FIX] web_editor: fix select all in empty paragraph
The previous code with `parentsUntil` would not return any result in an empty paragraph because the only valid element would be the anchorNode itself but `parentsUntil` would only return parents and never the base node itself. It makes sense, but is not suitable for the case at hand. Before this commit: CTRL+A does nothing from inside an empty paragraph. After this commit: CTRL+A correctly triggers a select all from inside an empty paragraph. Task-3150956 closes odoo/odoo#121727 X-original-commit: 4bcba1d785afeaa8287adc48076f208d04fc72c3 Signed-off-by: David Monjoie (dmo) <dmo@odoo.com> Co-authored-by: dhba-odoo <dhba@odoo.com> Co-authored-by: David Monjoie <dmo@odoo.com>
This commit is contained in:
co-authored by
dhba-odoo
parent
feff1fc79f
commit
6dd38640ce
@@ -1840,21 +1840,16 @@ const Wysiwyg = Widget.extend({
|
||||
if (e && e.key === 'a' && (e.ctrlKey || e.metaKey)) {
|
||||
e.preventDefault();
|
||||
const selection = this.odooEditor.document.getSelection();
|
||||
const containerSelector = '#wrap>*, [contenteditable], .oe_structure>*';
|
||||
let $deepestParent =
|
||||
selection ?
|
||||
$(selection.anchorNode).parentsUntil(containerSelector).last() :
|
||||
$();
|
||||
|
||||
if ($deepestParent.is('html')) {
|
||||
// In case we didn't find a suitable container
|
||||
// we need to restrict the selection inside to the editable area.
|
||||
$deepestParent = this.$editable.find(containerSelector);
|
||||
}
|
||||
|
||||
if ($deepestParent.length) {
|
||||
const containerSelector = '#wrap>*, .oe_structure>*, [contenteditable]';
|
||||
const container =
|
||||
(selection &&
|
||||
closestElement(selection.anchorNode, containerSelector)) ||
|
||||
// In case a suitable container could not be found then the
|
||||
// selection is restricted inside the editable area.
|
||||
this.$editable.find(containerSelector);
|
||||
if (container) {
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents($deepestParent.parent()[0]);
|
||||
range.selectNodeContents(container);
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user